-
Notifications
You must be signed in to change notification settings - Fork 26
/
scenario_custom_cors.go
36 lines (30 loc) · 1.83 KB
/
scenario_custom_cors.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 ory
import (
"github.com/cucumber/godog"
"github.com/kyma-project/api-gateway/tests/integration/pkg/manifestprocessor"
)
func initCustomCors(ctx *godog.ScenarioContext, ts *testsuite) {
scenario := ts.createScenario("custom-cors.yaml", "ory-custom-cors")
ctx.Step(`CustomCORS: There is an httpbin service$`, scenario.thereIsAHttpbinService)
ctx.Step(`CustomCORS: The APIRule with following CORS setup is applied AllowOrigins:'(\[.*\])', AllowMethods:'(\[.*\])', AllowHeaders:'(\[.*\])', AllowCredentials:"([^"]*)", ExposeHeaders:'(\[.*\])', MaxAge:"([^"]*)"$`, scenario.applyApiRuleWithCustomCORS)
ctx.Step(`CustomCORS: Preflight calling the "([^"]*)" endpoint with header Origin:"([^"]*)" should result in status code (\d+) and response header "([^"]*)" with value "([^"]*)"$`, scenario.preflightEndpointCallResponseHeaders)
ctx.Step(`CustomCORS: Preflight calling the "([^"]*)" endpoint with header Origin:"([^"]*)" should result in status code (\d+) and no response header "([^"]*)"$`, scenario.preflightEndpointCallNoResponseHeader)
ctx.Step(`CustomCORS: Teardown httpbin service$`, scenario.teardownHttpbinService)
}
func (s *scenario) applyApiRuleWithCustomCORS(allowOrigins, allowMethods, allowHeaders, allowCredentials, exposeHeaders, maxAge string) error {
s.ManifestTemplate["AllowOrigins"] = allowOrigins
s.ManifestTemplate["AllowMethods"] = allowMethods
s.ManifestTemplate["AllowHeaders"] = allowHeaders
s.ManifestTemplate["AllowCredentials"] = allowCredentials
s.ManifestTemplate["ExposeHeaders"] = exposeHeaders
s.ManifestTemplate["MaxAge"] = maxAge
r, err := manifestprocessor.ParseFromFileWithTemplate(s.ApiResourceManifestPath, s.ApiResourceDirectory, s.ManifestTemplate)
if err != nil {
return err
}
_, err = s.resourceManager.CreateOrUpdateResources(s.k8sClient, r...)
if err != nil {
return err
}
return nil
}