From a0e6f153da08da5c69f06b654e6a67fc0857cb8e Mon Sep 17 00:00:00 2001 From: Pubudu Gunatilaka Date: Thu, 21 Mar 2024 19:28:02 +0530 Subject: [PATCH] Add integration test to verify old CR versions of the API --- .../resources/tests/verify-old-apis.yaml | 80 +++++++++++++++++++ .../integration/tests/verify-old-apis.go | 68 ++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 test/integration/integration/tests/resources/tests/verify-old-apis.yaml create mode 100644 test/integration/integration/tests/verify-old-apis.go diff --git a/test/integration/integration/tests/resources/tests/verify-old-apis.yaml b/test/integration/integration/tests/resources/tests/verify-old-apis.yaml new file mode 100644 index 000000000..0fa9a363d --- /dev/null +++ b/test/integration/integration/tests/resources/tests/verify-old-apis.yaml @@ -0,0 +1,80 @@ +# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +apiVersion: dp.wso2.com/v1alpha1 +kind: API +metadata: + name: verify-old-apis + namespace: gateway-integration-test-infra +spec: + apiName: Backend with no basepath + apiType: REST + apiVersion: v1 + basePath: /verify-old-apis/v1 + #definitionFileRef: definition-file + production: + - httpRouteRefs: + - prod-httproute-1 + organization: wso2-org +--- +apiVersion: gateway.networking.k8s.io/v1beta1 +kind: HTTPRoute +metadata: + name: prod-httproute-1 + namespace: gateway-integration-test-infra +spec: + parentRefs: + - group: gateway.networking.k8s.io + kind: Gateway + name: wso2-apk-default + namespace: apk-integration-test + sectionName: httpslistener + hostnames: + - prod-api.test.gw.wso2.com + rules: + - matches: + - path: + type: PathPrefix + value: / + method: GET + backendRefs: + - group: dp.wso2.com + kind: Backend + name: infra-backend-v1 +--- +apiVersion: dp.wso2.com/v1alpha1 +kind: Authentication +metadata: + name: disable-sand-api-security + namespace: gateway-integration-test-infra +spec: + override: + disabled: true + targetRef: + group: gateway.networking.k8s.io + kind: API + namespace: gateway-integration-test-infra + name: prod-and-sand-apis +--- +apiVersion: dp.wso2.com/v1alpha1 +kind: Backend +metadata: + name: infra-backend-v1 + namespace: gateway-integration-test-infra +spec: + services: + - host: infra-backend-v1.gateway-integration-test-infra + port: 8080 diff --git a/test/integration/integration/tests/verify-old-apis.go b/test/integration/integration/tests/verify-old-apis.go new file mode 100644 index 000000000..6575db68c --- /dev/null +++ b/test/integration/integration/tests/verify-old-apis.go @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package tests + +import ( + "testing" + + "github.com/wso2/apk/test/integration/integration/utils/http" + "github.com/wso2/apk/test/integration/integration/utils/suite" +) + +func init() { + IntegrationTests = append(IntegrationTests, VerifyOldAPIs) +} + +// VerifyOldAPIs test +var VerifyOldAPIs = suite.IntegrationTest{ + ShortName: "VerifyOldAPIs", + Description: "Verify Old APIs with different CR versions", + Manifests: []string{"tests/verify-old-apis.yaml"}, + Test: func(t *testing.T, suite *suite.IntegrationTestSuite) { + ns := "gateway-integration-test-infra" + gwAddr1 := "prod-api.test.gw.wso2.com:9095" + token := http.GetTestToken(t) + + testCases1 := []http.ExpectedResponse{ + // invoke prod api using prod domain name, invokes prod backend + { + Request: http.Request{ + Host: "prod-api.test.gw.wso2.com", + Path: "/verify-old-apis/v1", + }, + ExpectedRequest: &http.ExpectedRequest{ + Request: http.Request{ + Path: "/", + }, + }, + Backend: "infra-backend-v1", + Namespace: ns, + }, + } + + for i := range testCases1 { + tc := testCases1[i] + tc.Request.Headers = http.AddBearerTokenToHeader(token, tc.Request.Headers) + t.Run(tc.GetTestCaseName(i), func(t *testing.T) { + t.Parallel() + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr1, tc) + }) + } + + }, +}