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: do not store refresh token, if empty. #349

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: do not store refresh token, if empty.
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
  • Loading branch information
jkroepke committed Nov 12, 2024
commit ca56ed339e13cb702347a72b648f2a280d0a9af5
44 changes: 21 additions & 23 deletions internal/oauth2/refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,42 +146,40 @@ func TestRefreshReAuth(t *testing.T) {
return nil, err
}

if refreshToken != "" {
res := httptest.NewRecorder()
if !strings.Contains(string(requestBody), refreshToken) {
res.WriteHeader(http.StatusUnauthorized)
} else {
res.WriteHeader(http.StatusOK)
}
if refreshToken == "" {
req.Body = io.NopCloser(bytes.NewReader(requestBody))
res, err := rt.RoundTrip(req)

res.WriteHeader(http.StatusUnauthorized)
if _, err := res.WriteString(`{}`); err != nil {
var tokenResponse oidc.AccessTokenResponse
if err := json.NewDecoder(res.Body).Decode(&tokenResponse); err != nil {
return nil, err
}

return res.Result(), nil
}
refreshToken = tokenResponse.RefreshToken

req.Body = io.NopCloser(bytes.NewReader(requestBody))
var buf bytes.Buffer

res, err := rt.RoundTrip(req)
if err := json.NewEncoder(&buf).Encode(tokenResponse); err != nil {
return nil, err
}

var tokenResponse oidc.AccessTokenResponse
if err := json.NewDecoder(res.Body).Decode(&tokenResponse); err != nil {
return nil, err
}
res.Body = io.NopCloser(&buf)

refreshToken = tokenResponse.RefreshToken
return res, err
}

var buf bytes.Buffer
res := httptest.NewRecorder()
if !strings.Contains(string(requestBody), refreshToken) {
res.WriteHeader(http.StatusUnauthorized)
} else {
res.WriteHeader(http.StatusOK)
}

if err := json.NewEncoder(&buf).Encode(tokenResponse); err != nil {
if _, err := res.WriteString(`{}`); err != nil {
return nil, err
}

res.Body = io.NopCloser(&buf)

return res, err
return res.Result(), nil
}),
},
} {
Expand Down
Loading