/
scenario_diff_svc_same_methods.go
36 lines (31 loc) · 2.03 KB
/
scenario_diff_svc_same_methods.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package istiojwt
import (
"fmt"
"github.com/cucumber/godog"
"github.com/kyma-project/api-gateway/tests/integration/pkg/manifestprocessor"
"strings"
)
func initDiffServiceSameMethods(ctx *godog.ScenarioContext, ts *testsuite) {
scenario := ts.createScenario("istio-jwt-diff-svc-same-methods.yaml", "istio-diff-service-same-methods")
ctx.Step(`DiffSvcSameMethods: There is a httpbin service$`, scenario.thereIsAHttpbinService)
ctx.Step(`DiffSvcSameMethods: There is a workload and service for httpbin and helloworld$`, scenario.thereAreTwoServices)
ctx.Step(`DiffSvcSameMethods: There is an endpoint secured with JWT on path "([^"]*)" for httpbin service with methods '(\[.*\])'$`, scenario.thereIsAJwtSecuredPathWithMethods)
ctx.Step(`DiffSvcSameMethods: There is an endpoint secured with JWT on path "([^"]*)" for helloworld service with methods '(\[.*\])'$`, scenario.thereIsAJwtSecuredPathWithMethods)
ctx.Step(`DiffSvcSameMethods: The APIRule is applied$`, scenario.theAPIRuleIsApplied)
ctx.Step(`DiffSvcSameMethods: Calling the "([^"]*)" endpoint with a valid "([^"]*)" token should result in status between (\d+) and (\d+)$`, scenario.callingTheEndpointWithValidTokenShouldResultInStatusBetween)
ctx.Step(`DiffSvcSameMethods: Calling the "([^"]*)" endpoint without token should result in status between (\d+) and (\d+)$`, scenario.callingTheEndpointWithoutTokenShouldResultInStatusBetween)
ctx.Step(`DiffSvcSameMethods: Teardown httpbin service$`, scenario.teardownHttpbinService)
}
func (s *scenario) thereAreTwoServices() error {
resources, err := manifestprocessor.ParseFromFileWithTemplate("testing-helloworld-app.yaml", s.ApiResourceDirectory, s.ManifestTemplate)
if err != nil {
return err
}
_, err = s.resourceManager.CreateResources(s.k8sClient, resources...)
return err
}
func (s *scenario) thereIsAJwtSecuredPathWithMethods(path string, methods string) {
pathName := strings.TrimPrefix(path, "/")
s.ManifestTemplate[fmt.Sprintf("%s%s", pathName, "Methods")] = methods
s.ManifestTemplate[fmt.Sprintf("%sJwtSecuredPath", pathName)] = path
}