-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CORS policy in v2alpha1 * Revert to v1beta1 * Tests * Tests * Add test for multiple hosts * Update API * Revert "Update API" This reverts commit 94e4eb0. * review changes * Fix unit test * Add unit tests * Adapt the doc * Update docs/user/custom-resources/apirule/v2alpha1/04-10-apirule-custom-resource.md Co-authored-by: Natalia Sitko <[email protected]> --------- Co-authored-by: Tim Riffer <[email protected]> Co-authored-by: Natalia Sitko <[email protected]>
- Loading branch information
1 parent
9467685
commit 34e5a44
Showing
15 changed files
with
903 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 32 additions & 32 deletions
64
docs/user/custom-resources/apirule/v2alpha1/04-10-apirule-custom-resource.md
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package v2alpha1_test | ||
|
||
import ( | ||
gatewayv2alpha1 "github.com/kyma-project/api-gateway/apis/gateway/v2alpha1" | ||
"github.com/kyma-project/api-gateway/internal/builders" | ||
processors "github.com/kyma-project/api-gateway/internal/processing/processors/v2alpha1" | ||
istioapiv1beta1 "istio.io/api/networking/v1beta1" | ||
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
. "github.com/kyma-project/api-gateway/internal/processing/processing_test" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("CORS", func() { | ||
var client client.Client | ||
var processor processors.VirtualServiceProcessor | ||
BeforeEach(func() { | ||
client = GetFakeClient() | ||
}) | ||
|
||
DescribeTable("CORS", | ||
func(apiRule *gatewayv2alpha1.APIRule, verifiers []verifier, expectedActions ...string) { | ||
processor = processors.NewVirtualServiceProcessor(GetTestConfig(), apiRule) | ||
checkVirtualServices(client, processor, verifiers, expectedActions...) | ||
}, | ||
|
||
Entry("should set default empty values in VirtualService CORSPolicy when no CORS configuration is set in APIRule", | ||
newAPIRuleBuilderWithDummyDataWithNoAuthRule().Build(), | ||
[]verifier{ | ||
func(vs *networkingv1beta1.VirtualService) { | ||
Expect(vs.Spec.Http[0].CorsPolicy).To(BeNil()) | ||
|
||
Expect(vs.Spec.Http[0].Headers.Response.Remove).To(ConsistOf([]string{ | ||
builders.ExposeHeadersName, | ||
builders.MaxAgeName, | ||
builders.AllowHeadersName, | ||
builders.AllowCredentialsName, | ||
builders.AllowMethodsName, | ||
builders.AllowOriginName, | ||
})) | ||
}, | ||
}, "create"), | ||
|
||
Entry("should apply all CORSPolicy headers correctly", | ||
newAPIRuleBuilderWithDummyDataWithNoAuthRule().WithCORSPolicy( | ||
newCorsPolicyBuilder(). | ||
WithAllowOrigins([]map[string]string{{"exact": "example.com"}}). | ||
WithAllowMethods([]string{"GET", "POST"}). | ||
WithAllowHeaders([]string{"header1", "header2"}). | ||
WithExposeHeaders([]string{"header3", "header4"}). | ||
WithAllowCredentials(true). | ||
WithMaxAge(600). | ||
Build()). | ||
Build(), | ||
[]verifier{func(vs *networkingv1beta1.VirtualService) { | ||
Expect(vs.Spec.Http[0].CorsPolicy).NotTo(BeNil()) | ||
Expect(vs.Spec.Http[0].CorsPolicy.AllowOrigins).To(HaveLen(1)) | ||
Expect(vs.Spec.Http[0].CorsPolicy.AllowOrigins[0]).To(Equal(&istioapiv1beta1.StringMatch{MatchType: &istioapiv1beta1.StringMatch_Exact{Exact: "example.com"}})) | ||
Expect(vs.Spec.Http[0].CorsPolicy.AllowMethods).To(ConsistOf("GET", "POST")) | ||
Expect(vs.Spec.Http[0].CorsPolicy.AllowHeaders).To(ConsistOf("header1", "header2")) | ||
Expect(vs.Spec.Http[0].CorsPolicy.ExposeHeaders).To(ConsistOf("header3", "header4")) | ||
Expect(vs.Spec.Http[0].CorsPolicy.AllowCredentials.GetValue()).To(BeTrue()) | ||
Expect(vs.Spec.Http[0].CorsPolicy.MaxAge.Seconds).To(Equal(int64(600))) | ||
|
||
Expect(vs.Spec.Http[0].Headers.Response.Remove).To(ConsistOf([]string{ | ||
builders.ExposeHeadersName, | ||
builders.MaxAgeName, | ||
builders.AllowHeadersName, | ||
builders.AllowCredentialsName, | ||
builders.AllowMethodsName, | ||
builders.AllowOriginName, | ||
})) | ||
}}, "create"), | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package v2alpha1_test | ||
|
||
import ( | ||
gatewayv2alpha1 "github.com/kyma-project/api-gateway/apis/gateway/v2alpha1" | ||
processors "github.com/kyma-project/api-gateway/internal/processing/processors/v2alpha1" | ||
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
. "github.com/kyma-project/api-gateway/internal/processing/processing_test" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Hosts", func() { | ||
var client client.Client | ||
var processor processors.VirtualServiceProcessor | ||
BeforeEach(func() { | ||
client = GetFakeClient() | ||
}) | ||
|
||
DescribeTable("Hosts", | ||
func(apiRule *gatewayv2alpha1.APIRule, verifiers []verifier, expectedActions ...string) { | ||
processor = processors.NewVirtualServiceProcessor(GetTestConfig(), apiRule) | ||
checkVirtualServices(client, processor, verifiers, expectedActions...) | ||
}, | ||
|
||
Entry("should set the host correctly", | ||
newAPIRuleBuilder().WithGateway("example/example").WithHost("example.com").Build(), | ||
[]verifier{ | ||
func(vs *networkingv1beta1.VirtualService) { | ||
Expect(vs.Spec.Hosts).To(ConsistOf("example.com")) | ||
}, | ||
}, "create"), | ||
|
||
Entry("should set multiple hosts correctly", | ||
newAPIRuleBuilder().WithGateway("example/example").WithHosts("example.com", "goat.com").Build(), | ||
[]verifier{ | ||
func(vs *networkingv1beta1.VirtualService) { | ||
Expect(vs.Spec.Hosts).To(ConsistOf("example.com", "goat.com")) | ||
}, | ||
}, "create"), | ||
) | ||
}) |
51 changes: 51 additions & 0 deletions
51
internal/processing/processors/v2alpha1/http_matching_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package v2alpha1_test | ||
|
||
import ( | ||
gatewayv2alpha1 "github.com/kyma-project/api-gateway/apis/gateway/v2alpha1" | ||
processors "github.com/kyma-project/api-gateway/internal/processing/processors/v2alpha1" | ||
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1" | ||
"net/http" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
. "github.com/kyma-project/api-gateway/internal/processing/processing_test" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("HTTP matching", func() { | ||
var client client.Client | ||
var processor processors.VirtualServiceProcessor | ||
BeforeEach(func() { | ||
client = GetFakeClient() | ||
}) | ||
var _ = DescribeTable("Different methods on same path", | ||
func(apiRule *gatewayv2alpha1.APIRule, verifiers []verifier, expectedActions ...string) { | ||
processor = processors.NewVirtualServiceProcessor(GetTestConfig(), apiRule) | ||
checkVirtualServices(client, processor, verifiers, expectedActions...) | ||
}, | ||
Entry("from two rules with different methods on the same path should create two HTTP routes with different methods", | ||
newAPIRuleBuilderWithDummyData(). | ||
WithRules(newRuleBuilder().WithMethods(http.MethodGet).WithPath("/").NoAuth().Build(), | ||
newRuleBuilder().WithMethods(http.MethodPut).WithPath("/").WithJWTAuthn("example.com", "https://jwks.example.com", nil, nil).Build()).Build(), | ||
[]verifier{ | ||
func(vs *networkingv1beta1.VirtualService) { | ||
Expect(vs.Spec.Http).To(HaveLen(2)) | ||
|
||
Expect(vs.Spec.Http[0].Match[0].Method.GetRegex()).To(Equal("^(GET)$")) | ||
Expect(vs.Spec.Http[1].Match[0].Method.GetRegex()).To(Equal("^(PUT)$")) | ||
}, | ||
}, "create"), | ||
|
||
Entry("from one rule with two methods on the same path should create one HTTP route with regex matching both methods", | ||
newAPIRuleBuilderWithDummyData(). | ||
WithRules(newRuleBuilder().WithMethods(http.MethodGet, http.MethodPut).WithPath("/").NoAuth().Build()). | ||
Build(), | ||
[]verifier{ | ||
func(vs *networkingv1beta1.VirtualService) { | ||
Expect(vs.Spec.Http).To(HaveLen(1)) | ||
|
||
Expect(vs.Spec.Http[0].Match[0].Method.GetRegex()).To(Equal("^(GET|PUT)$")) | ||
}, | ||
}, "create"), | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.