Skip to content

Commit

Permalink
internal-endpoint-testing: introduce mandatoryheaders in cors config
Browse files Browse the repository at this point in the history
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
  • Loading branch information
NomadXD committed Jan 24, 2024
1 parent bec0b9b commit ab84ac1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions adapter/config/default_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var defaultConfig = &Config{
"testKey", "Internal-Key"},
AllowCredentials: false,
ExposeHeaders: []string{},
MandatoryHeaders: []string{"x-choreo-test-session-id"},
},
Upstream: envoyUpstream{
TLS: upstreamTLS{
Expand Down
1 change: 1 addition & 0 deletions adapter/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ type globalCors struct {
AllowHeaders []string
AllowCredentials bool
ExposeHeaders []string
MandatoryHeaders []string
}

// Envoy Upstream Related Configurations
Expand Down
10 changes: 8 additions & 2 deletions adapter/internal/oasparser/envoyconf/routes_with_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -1455,8 +1455,14 @@ func getCorsPolicy(corsConfig *model.CorsConfig) *cors_filter_v3.CorsPolicy {
return nil
}

// Append `x-choreo-test-session-id` used for internal endpoint testing to AccessControlAllowHeaders.
corsConfig.AccessControlAllowHeaders = append(corsConfig.AccessControlAllowHeaders, choreoTestSessionHeaderName)
conf, errReadConfig := config.ReadConfigs()
if errReadConfig != nil {
logger.LoggerOasparser.Error("Error loading configuration. ", errReadConfig)
return nil;
}
if len(conf.Envoy.Cors.MandatoryHeaders) > 0 {
corsConfig.AccessControlAllowHeaders = append(corsConfig.AccessControlAllowHeaders, conf.Envoy.Cors.MandatoryHeaders...)
}

stringMatcherArray := []*envoy_type_matcherv3.StringMatcher{}
for _, origin := range corsConfig.AccessControlAllowOrigins {
Expand Down

0 comments on commit ab84ac1

Please sign in to comment.