Skip to content

Commit

Permalink
Change Content-Type to plain text for logout and reset endpoints
Browse files Browse the repository at this point in the history
No text is returned so the response is not a valid JSON.
  • Loading branch information
paskal committed Sep 19, 2024
1 parent b6f1a79 commit 1c0fb40
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func TestLogout(t *testing.T) {
resp, err = client.Get("http://127.0.0.1:8089/auth/logout")
require.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "application/json; charset=utf-8", resp.Header.Get("Content-Type"))
assert.Equal(t, "text/plain; charset=utf-8", resp.Header.Get("Content-Type"))
defer resp.Body.Close()

resp, err = client.Get("http://127.0.0.1:8089/private")
Expand Down
2 changes: 1 addition & 1 deletion provider/apple_pubkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type appleKeySet struct {

// get return Apple public key with specific KeyID (kid)
func (aks *appleKeySet) get(kid string) (keys *applePublicKey, err error) {
if aks.keys == nil || len(aks.keys) == 0 {
if len(aks.keys) == 0 {
return nil, fmt.Errorf("failed to get key in appleKeySet, key set is nil or empty")
}

Expand Down
3 changes: 3 additions & 0 deletions provider/apple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"log"
"math"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -660,6 +661,8 @@ ODIRe1AuTyHceAbewn8b462yEWKARdpd9AjQW5SIVPfdsz5B6GlYQ5LdYKtznTuy

// convert exponent
eBuff := make([]byte, 4)
require.Less(t, publicKey.E, math.MaxUint32)
//nolint:gosec // checked by a line above
binary.LittleEndian.PutUint32(eBuff, uint32(publicKey.E))
e := base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(eBuff)

Expand Down
2 changes: 1 addition & 1 deletion token/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (j *Service) Reset(w http.ResponseWriter) {
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &xsrfCookie)

w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
}

// checkAuds verifies if claims.Audience in the list of allowed by audReader
Expand Down
2 changes: 1 addition & 1 deletion v2/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func TestLogout(t *testing.T) {
resp, err = client.Get("http://127.0.0.1:8089/auth/logout")
require.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "application/json; charset=utf-8", resp.Header.Get("Content-Type"))
assert.Equal(t, "text/plain; charset=utf-8", resp.Header.Get("Content-Type"))
defer resp.Body.Close()

resp, err = client.Get("http://127.0.0.1:8089/private")
Expand Down
2 changes: 1 addition & 1 deletion v2/provider/apple_pubkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type appleKeySet struct {

// get return Apple public key with specific KeyID (kid)
func (aks *appleKeySet) get(kid string) (keys *applePublicKey, err error) {
if aks.keys == nil || len(aks.keys) == 0 {
if len(aks.keys) == 0 {
return nil, fmt.Errorf("failed to get key in appleKeySet, key set is nil or empty")
}

Expand Down
3 changes: 3 additions & 0 deletions v2/provider/apple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"log"
"math"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -660,6 +661,8 @@ ODIRe1AuTyHceAbewn8b462yEWKARdpd9AjQW5SIVPfdsz5B6GlYQ5LdYKtznTuy

// convert exponent
eBuff := make([]byte, 4)
require.Less(t, publicKey.E, math.MaxUint32)
//nolint:gosec // checked by a line above
binary.LittleEndian.PutUint32(eBuff, uint32(publicKey.E))
e := base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(eBuff)

Expand Down
2 changes: 1 addition & 1 deletion v2/token/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (j *Service) Reset(w http.ResponseWriter) {
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &xsrfCookie)

w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
}

// checkAuds verifies if claims.Audience in the list of allowed by audReader
Expand Down

0 comments on commit 1c0fb40

Please sign in to comment.