-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
40 additions
and
44 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
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 |
---|---|---|
|
@@ -116,9 +116,6 @@ func TestPasswordResetter(t *testing.T) { | |
} | ||
|
||
func TestPasswordResetterWithTOTP(t *testing.T) { | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==") | ||
|
||
accountStore := mock.NewAccountStore() | ||
cfg := &app.Config{ | ||
AuthNURL: &url.URL{Scheme: "http", Host: "authn.example.com"}, | ||
|
@@ -137,14 +134,15 @@ func TestPasswordResetterWithTOTP(t *testing.T) { | |
} | ||
|
||
invoke := func(token string, password string, totpCode string) error { | ||
_, err := services.PasswordResetter(accountStore, &ops.LogReporter{logrus.New()}, cfg, token, password, totpCode) | ||
_, err := services.PasswordResetter(accountStore, &ops.LogReporter{FieldLogger: logrus.New()}, cfg, token, password, totpCode) | ||
return err | ||
} | ||
|
||
t.Run("sets new password", func(t *testing.T) { | ||
expired, err := accountStore.Create("[email protected]", []byte("old")) | ||
require.NoError(t, err) | ||
accountStore.SetTOTPSecret(expired.ID, totpSecretEnc) | ||
_, err = accountStore.SetTOTPSecret(expired.ID, totpSecretEnc) | ||
Check failure on line 144 in app/services/password_resetter_test.go GitHub Actions / Test
|
||
require.NoError(t, err) | ||
_, err = accountStore.RequireNewPassword(expired.ID) | ||
require.NoError(t, err) | ||
|
||
|
@@ -163,7 +161,8 @@ func TestPasswordResetterWithTOTP(t *testing.T) { | |
t.Run("without totp code", func(t *testing.T) { | ||
expired, err := accountStore.Create("[email protected]", []byte("old")) | ||
require.NoError(t, err) | ||
accountStore.SetTOTPSecret(expired.ID, totpSecretEnc) | ||
_, err = accountStore.SetTOTPSecret(expired.ID, totpSecretEnc) | ||
Check failure on line 164 in app/services/password_resetter_test.go GitHub Actions / Test
|
||
require.NoError(t, err) | ||
_, err = accountStore.RequireNewPassword(expired.ID) | ||
require.NoError(t, err) | ||
|
||
|
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 |
---|---|---|
|
@@ -101,9 +101,6 @@ func TestPasswordlessTokenVerifier(t *testing.T) { | |
} | ||
|
||
func TestPasswordlessTokenVerifierWithTOTP(t *testing.T) { | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==") | ||
|
||
accountStore := mock.NewAccountStore() | ||
cfg := &app.Config{ | ||
AuthNURL: &url.URL{Scheme: "http", Host: "authn.example.com"}, | ||
|
@@ -122,14 +119,17 @@ func TestPasswordlessTokenVerifierWithTOTP(t *testing.T) { | |
} | ||
|
||
invoke := func(token string, totpCode string) error { | ||
_, err := services.PasswordlessTokenVerifier(accountStore, &ops.LogReporter{logrus.New()}, cfg, token, totpCode) | ||
_, err := services.PasswordlessTokenVerifier(accountStore, &ops.LogReporter{FieldLogger: logrus.New()}, cfg, token, totpCode) | ||
return err | ||
} | ||
|
||
t.Run("with good code", func(t *testing.T) { | ||
account, err := accountStore.Create("[email protected]", []byte("old")) | ||
accountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
set, err := accountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
Check failure on line 129 in app/services/passwordless_token_verifier_test.go GitHub Actions / Test
|
||
require.NoError(t, err) | ||
require.True(t, set) | ||
|
||
token := newToken(account.ID) | ||
|
||
code, err := totp.GenerateCode(totpSecret, time.Now()) | ||
Check failure on line 135 in app/services/passwordless_token_verifier_test.go GitHub Actions / Test
|
||
|
@@ -141,8 +141,11 @@ func TestPasswordlessTokenVerifierWithTOTP(t *testing.T) { | |
|
||
t.Run("with bad code", func(t *testing.T) { | ||
account, err := accountStore.Create("[email protected]", []byte("old")) | ||
accountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
set, err := accountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
Check failure on line 145 in app/services/passwordless_token_verifier_test.go GitHub Actions / Test
|
||
require.NoError(t, err) | ||
require.True(t, set) | ||
|
||
token := newToken(account.ID) | ||
|
||
err = invoke(token, "12345") | ||
|
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 |
---|---|---|
|
@@ -248,9 +248,6 @@ func TestPostPassword(t *testing.T) { | |
} | ||
|
||
func TestPostPasswordWithTOTP(t *testing.T) { | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==") | ||
|
||
app := test.App() | ||
server := test.Server(app) | ||
defer server.Close() | ||
|
@@ -278,8 +275,10 @@ func TestPostPasswordWithTOTP(t *testing.T) { | |
t.Run("valid totp code", func(t *testing.T) { | ||
// given an account | ||
account, err := factory("[email protected]", "oldpwd") | ||
app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
set, err := app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
require.True(t, set) | ||
|
||
// given a reset token | ||
token, err := resets.New(app.Config, account.ID, account.PasswordChangedAt) | ||
|
@@ -306,8 +305,10 @@ func TestPostPasswordWithTOTP(t *testing.T) { | |
t.Run("invalid totp code", func(t *testing.T) { | ||
// given an account | ||
account, err := factory("[email protected]", "oldpwd") | ||
app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
set, err := app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
require.True(t, set) | ||
|
||
// given a reset token | ||
token, err := resets.New(app.Config, account.ID, account.PasswordChangedAt) | ||
|
@@ -324,6 +325,6 @@ func TestPostPasswordWithTOTP(t *testing.T) { | |
require.NoError(t, err) | ||
|
||
assert.Equal(t, http.StatusUnprocessableEntity, res.StatusCode) | ||
test.AssertErrors(t, res, services.FieldErrors{{"totp", "INVALID_OR_EXPIRED"}}) | ||
test.AssertErrors(t, res, services.FieldErrors{{Field: "totp", Message: "INVALID_OR_EXPIRED"}}) | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -112,9 +112,6 @@ func TestPostSessionToken(t *testing.T) { | |
} | ||
|
||
func TestPostSessionTokenWithTOTP(t *testing.T) { | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==") | ||
|
||
app := test.App() | ||
server := test.Server(app) | ||
defer server.Close() | ||
|
@@ -143,7 +140,9 @@ func TestPostSessionTokenWithTOTP(t *testing.T) { | |
// given an account | ||
account, err := factory("[email protected]", "oldpwd") | ||
require.NoError(t, err) | ||
app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
set, err := app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
require.True(t, set) | ||
|
||
// given a passwordless token | ||
token, err := passwordless.New(app.Config, account.ID) | ||
|
@@ -170,7 +169,9 @@ func TestPostSessionTokenWithTOTP(t *testing.T) { | |
// given an account | ||
account, err := factory("[email protected]", "oldpwd") | ||
require.NoError(t, err) | ||
app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
set, err := app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
require.True(t, set) | ||
|
||
// given a passwordless token | ||
token, err := passwordless.New(app.Config, account.ID) | ||
|
@@ -186,6 +187,6 @@ func TestPostSessionTokenWithTOTP(t *testing.T) { | |
require.NoError(t, err) | ||
|
||
assert.Equal(t, http.StatusUnprocessableEntity, res.StatusCode) | ||
test.AssertErrors(t, res, services.FieldErrors{{"totp", "INVALID_OR_EXPIRED"}}) | ||
test.AssertErrors(t, res, services.FieldErrors{{Field: "totp", Message: "INVALID_OR_EXPIRED"}}) | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -19,7 +19,6 @@ func TestPostTOTPSuccess(t *testing.T) { | |
server := test.Server(app) | ||
defer server.Close() | ||
|
||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
account, _ := app.AccountStore.Create("[email protected]", []byte("password")) | ||
existingSession := test.CreateSession(app.RefreshTokenStore, app.Config, account.ID) | ||
err := app.TOTPCache.CacheTOTPSecret(account.ID, []byte(totpSecret)) | ||
|
@@ -45,7 +44,6 @@ func TestPostTOTPFailure(t *testing.T) { | |
server := test.Server(app) | ||
defer server.Close() | ||
|
||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
account, _ := app.AccountStore.Create("[email protected]", []byte("password")) | ||
existingSession := test.CreateSession(app.RefreshTokenStore, app.Config, account.ID) | ||
err := app.TOTPCache.CacheTOTPSecret(account.ID, []byte(totpSecret)) | ||
|