-
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
36 additions
and
22 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,6 +116,7 @@ func TestPasswordResetter(t *testing.T) { | |
} | ||
|
||
func TestPasswordResetterWithTOTP(t *testing.T) { | ||
// nolint: gosec | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==") | ||
|
||
|
@@ -137,14 +138,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) | ||
require.NoError(t, err) | ||
_, err = accountStore.RequireNewPassword(expired.ID) | ||
require.NoError(t, err) | ||
|
||
|
@@ -163,7 +165,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) | ||
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,6 +101,7 @@ func TestPasswordlessTokenVerifier(t *testing.T) { | |
} | ||
|
||
func TestPasswordlessTokenVerifierWithTOTP(t *testing.T) { | ||
// nolint: gosec | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==") | ||
|
||
|
@@ -122,13 +123,14 @@ 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) | ||
_, err = accountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
token := newToken(account.ID) | ||
|
||
|
@@ -141,7 +143,8 @@ 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) | ||
_, err = accountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
token := newToken(account.ID) | ||
|
||
|
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,6 +248,7 @@ func TestPostPassword(t *testing.T) { | |
} | ||
|
||
func TestPostPasswordWithTOTP(t *testing.T) { | ||
// nolint: gosec | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==") | ||
|
||
|
@@ -278,7 +279,8 @@ 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) | ||
_, err = app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
|
||
// given a reset token | ||
|
@@ -306,7 +308,8 @@ 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) | ||
_, err = app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
|
||
// given a reset token | ||
|
@@ -324,6 +327,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,6 +112,7 @@ func TestPostSessionToken(t *testing.T) { | |
} | ||
|
||
func TestPostSessionTokenWithTOTP(t *testing.T) { | ||
// nolint: gosec | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==") | ||
|
||
|
@@ -143,7 +144,8 @@ func TestPostSessionTokenWithTOTP(t *testing.T) { | |
// given an account | ||
account, err := factory("[email protected]", "oldpwd") | ||
require.NoError(t, err) | ||
app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
_, err = app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
|
||
// given a passwordless token | ||
token, err := passwordless.New(app.Config, account.ID) | ||
|
@@ -170,7 +172,8 @@ func TestPostSessionTokenWithTOTP(t *testing.T) { | |
// given an account | ||
account, err := factory("[email protected]", "oldpwd") | ||
require.NoError(t, err) | ||
app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
_, err = app.AccountStore.SetTOTPSecret(account.ID, totpSecretEnc) | ||
require.NoError(t, err) | ||
|
||
// given a passwordless token | ||
token, err := passwordless.New(app.Config, account.ID) | ||
|
@@ -186,6 +189,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,6 +19,7 @@ func TestPostTOTPSuccess(t *testing.T) { | |
server := test.Server(app) | ||
defer server.Close() | ||
|
||
// nolint: gosec | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
account, _ := app.AccountStore.Create("[email protected]", []byte("password")) | ||
existingSession := test.CreateSession(app.RefreshTokenStore, app.Config, account.ID) | ||
|
@@ -45,6 +46,7 @@ func TestPostTOTPFailure(t *testing.T) { | |
server := test.Server(app) | ||
defer server.Close() | ||
|
||
// nolint: gosec | ||
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM" | ||
account, _ := app.AccountStore.Create("[email protected]", []byte("password")) | ||
existingSession := test.CreateSession(app.RefreshTokenStore, app.Config, account.ID) | ||
|