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

Fix-cache-control #189

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"debug.allowBreakpointsEverywhere": true,
"files.autoGuessEncoding": true
}
7 changes: 7 additions & 0 deletions internal/auth/bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ func (ss *BearerSecurityScheme) GetHeaders() http.Header {
header.Set(AuthorizationHeader, fmt.Sprintf("%s %s", BearerPrefix, attackValue))
}

//add cache-control based on authorization
if ss.HasValidValue() {
header.Set("Cache-Control", "private, max-age=0")
} else {
header.Set("Cache-Control", "public, max-age=3600")
}

return header
}

Expand Down
6 changes: 5 additions & 1 deletion internal/auth/bearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestBearerSecurityScheme_GetHeaders(t *testing.T) {

assert.Equal(t, http.Header{
"Authorization": []string{"Bearer xyz789"},
"Cache-Control": []string{"private, max-age=0"},
}, headers)
}

Expand All @@ -85,6 +86,7 @@ func TestBearerSecurityScheme_GetHeaders_WhenNoAttackValue(t *testing.T) {

assert.Equal(t, http.Header{
"Authorization": []string{"Bearer abc123"},
"Cache-Control": []string{"private, max-age=0"},
}, headers)
}

Expand All @@ -94,7 +96,9 @@ func TestBearerSecurityScheme_GetHeaders_WhenNoAttackAndValidValue(t *testing.T)

headers := ss.GetHeaders()

assert.Equal(t, http.Header{}, headers)
assert.Equal(t, http.Header{
"Cache-Control": []string{"public, max-age=3600"},
}, headers)
}

func TestBearerSecurityScheme_GetCookies(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions internal/auth/jwt_bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ func (ss *JWTBearerSecurityScheme) GetHeaders() http.Header {
header.Set(AuthorizationHeader, fmt.Sprintf("%s %s", BearerPrefix, attackValue))
}

//add cache-control based on authorization
if ss.HasValidValue() {
header.Set("Cache-Control", "private, max-age=0")
} else {
header.Set("Cache-Control", "public, max-age=3600")
}

return header
}

Expand Down
6 changes: 5 additions & 1 deletion internal/auth/jwt_bearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestJWTBearerSecurityScheme_GetHeaders(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.Header{
"Authorization": []string{"Bearer xyz789"},
"Cache-Control": []string{"private, max-age=0"},
}, headers)
}

Expand All @@ -100,6 +101,7 @@ func TestJWTBearerSecurityScheme_GetHeaders_WhenNoAttackValue(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.Header{
"Authorization": []string{"Bearer " + jwt.FakeJWT},
"Cache-Control": []string{"private, max-age=0"},
}, headers)
}

Expand All @@ -110,7 +112,9 @@ func TestJWTBearerSecurityScheme_GetHeaders_WhenNoAttackAndValidValue(t *testing
headers := ss.GetHeaders()

assert.NoError(t, err)
assert.Equal(t, http.Header{}, headers)
assert.Equal(t, http.Header{
"Cache-Control": []string{"public, max-age=3600"},
}, headers)
}

func TestJWTBearerSecurityScheme_GetCookies(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions internal/auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ func (ss *OAuthSecurityScheme) GetHeaders() http.Header {
header.Set(AuthorizationHeader, fmt.Sprintf("%s %s", BearerPrefix, attackValue))
}

//add cache-control based on authorization
if ss.HasValidValue() {
header.Set("Cache-Control", "private, max-age=0")
} else {
header.Set("Cache-Control", "public, max-age=3600")
}

return header
}

Expand Down
6 changes: 5 additions & 1 deletion internal/auth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestNewOAuthSecurityScheme_GetHeaders(t *testing.T) {

assert.Equal(t, http.Header{
"Authorization": []string{"Bearer xyz789"},
"Cache-Control": []string{"private, max-age=0"},
}, headers)
}

Expand All @@ -104,6 +105,7 @@ func TestNewOAuthSecurityScheme_GetHeaders_WhenNoAttackValue(t *testing.T) {

assert.Equal(t, http.Header{
"Authorization": []string{"Bearer abc123"},
"Cache-Control": []string{"private, max-age=0"},
}, headers)
}

Expand All @@ -113,7 +115,9 @@ func TestNewOAuthSecurityScheme_GetHeaders_WhenNoAttackAndValidValue(t *testing.

headers := ss.GetHeaders()

assert.Equal(t, http.Header{}, headers)
assert.Equal(t, http.Header{
"Cache-Control": []string{"public, max-age=3600"},
}, headers)
}

func TestNewOAuthSecurityScheme_GetCookies(t *testing.T) {
Expand Down