Skip to content

Commit

Permalink
oauth2: Resolves flaky MySQL tests on Circle-CI
Browse files Browse the repository at this point in the history
Closes #861
  • Loading branch information
arekkas authored and arekkas committed May 20, 2018
1 parent 127561c commit fcd9180
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

[[constraint]]
name = "github.com/ory/fosite"
version = "0.19.2"
version = "0.19.3"

[[constraint]]
name = "github.com/ory/graceful"
Expand Down
9 changes: 8 additions & 1 deletion consent/strategy_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ func (s *DefaultStrategy) verifyAuthentication(w http.ResponseWriter, r *http.Re
return nil, errors.WithStack(fosite.ErrServerError.WithDebug("The login request is marked as remember, but the subject from the login confirmation does not match the original subject from the cookie."))
}

authTime := session.AuthenticatedAt
if session.AuthenticatedAt.After(session.RequestedAt) {
// If we authenticated after the initial request hit the /oauth2/auth endpoint, we can update the
// auth time to now which will resolve issues with very short max_age times
authTime = time.Now().UTC()
}

if err := s.OpenIDConnectRequestValidator.ValidatePrompt(&fosite.AuthorizeRequest{
ResponseTypes: req.GetResponseTypes(),
RedirectURI: req.GetRedirectURI(),
Expand All @@ -306,7 +313,7 @@ func (s *DefaultStrategy) verifyAuthentication(w http.ResponseWriter, r *http.Re
Subject: session.Subject,
IssuedAt: time.Now().UTC(), // doesn't matter
ExpiresAt: time.Now().Add(time.Hour).UTC(), // doesn't matter
AuthTime: session.AuthenticatedAt,
AuthTime: authTime,
RequestedAt: session.RequestedAt,
},
Headers: &jwt.Headers{},
Expand Down
6 changes: 4 additions & 2 deletions oauth2/oauth2_auth_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,16 @@ func TestAuthCodeWithDefaultStrategy(t *testing.T) {
},
{
d: "should not cause issues if max_age is very low and consent takes a long time",
authURL: oauthConfig.AuthCodeURL("some-hardcoded-state") + "&max_age=1",
authURL: oauthConfig.AuthCodeURL("some-hardcoded-state") + "&max_age=3",
//cj: persistentCJ,
lph: func(t *testing.T) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
_, res, err := apiClient.GetLoginRequest(r.URL.Query().Get("login_challenge"))
require.NoError(t, err)
require.EqualValues(t, http.StatusOK, res.StatusCode)

time.Sleep(time.Second * 5)

v, res, err := apiClient.AcceptLoginRequest(r.URL.Query().Get("login_challenge"), swagger.AcceptLoginRequest{Subject: "user-a"})
require.NoError(t, err)
require.EqualValues(t, http.StatusOK, res.StatusCode)
Expand All @@ -472,7 +474,7 @@ func TestAuthCodeWithDefaultStrategy(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, http.StatusOK, res.StatusCode)

time.Sleep(time.Second * 2)
time.Sleep(time.Second * 5)

v, res, err := apiClient.AcceptConsentRequest(r.URL.Query().Get("consent_challenge"), swagger.AcceptConsentRequest{
GrantScope: []string{"hydra", "openid"},
Expand Down

0 comments on commit fcd9180

Please sign in to comment.