Skip to content

Commit

Permalink
Bug fix: x-choreo-test-session-id is appended to CORS config repeated…
Browse files Browse the repository at this point in the history
…ly depending on the number of resources
  • Loading branch information
VirajSalaka committed Feb 2, 2024
1 parent 2195f51 commit 3b9cc7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ func TestGetCorsPolicy(t *testing.T) {
// Test configuration when all the fields are provided.
corsPolicy2 := getCorsPolicy(corsConfigModel2)
assert.NotNil(t, corsPolicy2, "Cors Policy should not be null.")
// To make sure that the allow headers in the config passed is not modified.
assert.Equal(t, 2, len(corsConfigModel2.AccessControlAllowHeaders), "Cors Config is modified which is not supposed to be modified.")
assert.NotEmpty(t, corsPolicy2.GetAllowOriginStringMatch(), "Cors Allowded Origins should not be null.")
assert.Equal(t, regexp.QuoteMeta("http://test.com"),
corsPolicy2.GetAllowOriginStringMatch()[0].GetSafeRegex().GetRegex(),
Expand Down
7 changes: 4 additions & 3 deletions adapter/internal/oasparser/envoyconf/routes_with_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -1454,10 +1454,11 @@ func getCorsPolicy(corsConfig *model.CorsConfig) *cors_filter_v3.CorsPolicy {
if corsConfig == nil || !corsConfig.Enabled {
return nil
}
var finalAccessControlAllowHeaders []string

conf, _ := config.ReadConfigs()
if len(conf.Envoy.Cors.MandatoryHeaders) > 0 {
corsConfig.AccessControlAllowHeaders = append(corsConfig.AccessControlAllowHeaders, conf.Envoy.Cors.MandatoryHeaders...)
finalAccessControlAllowHeaders = append(corsConfig.AccessControlAllowHeaders, conf.Envoy.Cors.MandatoryHeaders...)
}

stringMatcherArray := []*envoy_type_matcherv3.StringMatcher{}
Expand Down Expand Up @@ -1485,8 +1486,8 @@ func getCorsPolicy(corsConfig *model.CorsConfig) *cors_filter_v3.CorsPolicy {
if len(corsConfig.AccessControlAllowMethods) > 0 {
corsPolicy.AllowMethods = strings.Join(corsConfig.AccessControlAllowMethods, ", ")
}
if len(corsConfig.AccessControlAllowHeaders) > 0 {
corsPolicy.AllowHeaders = strings.Join(corsConfig.AccessControlAllowHeaders, ", ")
if len(finalAccessControlAllowHeaders) > 0 {
corsPolicy.AllowHeaders = strings.Join(finalAccessControlAllowHeaders, ", ")
}
if len(corsConfig.AccessControlExposeHeaders) > 0 {
corsPolicy.ExposeHeaders = strings.Join(corsConfig.AccessControlExposeHeaders, ", ")
Expand Down

0 comments on commit 3b9cc7a

Please sign in to comment.