-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove unnecessary comments & check for pkce prefix in verify
- Loading branch information
1 parent
ac75297
commit 2e3f9d4
Showing
3 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/gofrs/uuid" | ||
mail "github.com/supabase/auth/internal/mailer" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
@@ -748,6 +749,60 @@ func (ts *VerifyTestSuite) TestVerifyPKCEOTP() { | |
|
||
} | ||
|
||
func (ts *VerifyTestSuite) TestVerifyPostPKCE() { | ||
var buffer bytes.Buffer | ||
require.NoError(ts.T(), json.NewEncoder(&buffer).Encode(map[string]interface{}{ | ||
"email": "[email protected]", | ||
"password": "test-password", | ||
"code_challenge": "codechallengecodechallengcodechallengcodechallengcodechallenge", | ||
"code_challenge_method": "plain", | ||
})) | ||
req := httptest.NewRequest(http.MethodPost, "http://localhost/signup", &buffer) | ||
req.Header.Set("Content-Type", "application/json") | ||
|
||
w := httptest.NewRecorder() | ||
ts.API.handler.ServeHTTP(w, req) | ||
require.Equal(ts.T(), http.StatusOK, w.Code) | ||
|
||
var data map[string]interface{} | ||
require.NoError(ts.T(), json.NewDecoder(w.Body).Decode(&data)) | ||
userId, err := uuid.FromString(data["id"].(string)) | ||
require.NoError(ts.T(), err) | ||
u, err := models.FindUserByID(ts.API.db, userId) | ||
require.NoError(ts.T(), err) | ||
require.NotEmpty(ts.T(), u.OneTimeTokens) | ||
|
||
// update the token hash to a known value for subsequent verification | ||
ott := u.OneTimeTokens[0] | ||
ott.TokenHash = addFlowPrefixToToken(crypto.GenerateTokenHash("[email protected]", "123456"), models.PKCEFlow) | ||
require.NoError(ts.T(), ts.API.db.Update(&ott)) | ||
|
||
require.NoError(ts.T(), json.NewEncoder(&buffer).Encode(map[string]interface{}{ | ||
"email": "[email protected]", | ||
"token": "123456", | ||
"type": "email", | ||
})) | ||
req = httptest.NewRequest(http.MethodPost, "http://localhost/verify", &buffer) | ||
req.Header.Set("Content-Type", "application/json") | ||
|
||
w = httptest.NewRecorder() | ||
ts.API.handler.ServeHTTP(w, req) | ||
require.Equal(ts.T(), http.StatusOK, w.Code) | ||
|
||
// check that the response contains an access and refresh token | ||
require.NoError(ts.T(), json.NewDecoder(w.Body).Decode(&data)) | ||
require.Contains(ts.T(), data, "access_token") | ||
require.Contains(ts.T(), data, "refresh_token") | ||
|
||
// check that the user in the db is confirmed | ||
u, err = models.FindUserByID(ts.API.db, userId) | ||
require.NoError(ts.T(), err) | ||
require.True(ts.T(), u.IsConfirmed()) | ||
|
||
// // one time tokens should be cleared after successful verification | ||
require.Empty(ts.T(), u.OneTimeTokens) | ||
} | ||
|
||
func (ts *VerifyTestSuite) TestVerifyBannedUser() { | ||
u, err := models.FindUserByEmailAndAudience(ts.API.db, "[email protected]", ts.Config.JWT.Aud) | ||
require.NoError(ts.T(), err) | ||
|