Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: x-choreo-test-session-id is appended to CORS config repeatedly #3489

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading