Skip to content

Commit

Permalink
Allows browser extensions in cors (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
StewartThomson authored May 10, 2020
1 parent 7523ad0 commit 93b30c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion auth/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
// CorsConfig generates a config to use in gin cors middleware based on server configuration
func CorsConfig(conf *config.Configuration) cors.Config {
corsConf := cors.Config{
MaxAge: 12 * time.Hour,
MaxAge: 12 * time.Hour,
AllowBrowserExtensions: true,
}
if mode.IsDev() {
corsConf.AllowAllOrigins = true
Expand Down
23 changes: 13 additions & 10 deletions auth/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func TestCorsConfig(t *testing.T) {
actual.AllowOriginFunc = nil // func cannot be checked with equal

assert.Equal(t, cors.Config{
AllowAllOrigins: false,
AllowHeaders: []string{"content-type"},
AllowMethods: []string{"GET"},
MaxAge: 12 * time.Hour,
AllowAllOrigins: false,
AllowHeaders: []string{"content-type"},
AllowMethods: []string{"GET"},
MaxAge: 12 * time.Hour,
AllowBrowserExtensions: true,
}, actual)
assert.NotNil(t, allowF)
assert.True(t, allowF("http://test.com"))
Expand All @@ -42,9 +43,10 @@ func TestEmptyCorsConfigWithResponseHeaders(t *testing.T) {
actual.AllowOriginFunc = nil // func cannot be checked with equal

assert.Equal(t, cors.Config{
AllowAllOrigins: false,
AllowOrigins: []string{"https://example.com"},
MaxAge: 12 * time.Hour,
AllowAllOrigins: false,
AllowOrigins: []string{"https://example.com"},
MaxAge: 12 * time.Hour,
AllowBrowserExtensions: true,
}, actual)
}

Expand All @@ -60,8 +62,9 @@ func TestDevCorsConfig(t *testing.T) {
assert.Equal(t, cors.Config{
AllowHeaders: []string{"X-Gotify-Key", "Authorization", "Content-Type", "Upgrade", "Origin",
"Connection", "Accept-Encoding", "Accept-Language", "Host"},
AllowMethods: []string{"GET", "POST", "DELETE", "OPTIONS", "PUT"},
MaxAge: 12 * time.Hour,
AllowAllOrigins: true,
AllowMethods: []string{"GET", "POST", "DELETE", "OPTIONS", "PUT"},
MaxAge: 12 * time.Hour,
AllowAllOrigins: true,
AllowBrowserExtensions: true,
}, actual)
}

0 comments on commit 93b30c5

Please sign in to comment.