Skip to content

Commit

Permalink
rebase/lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCuse committed Oct 16, 2023
1 parent a55604c commit 2e4eebe
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/data/redis/blob_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *BlobStore) WriteNX(name string, blob []byte) (bool, error) {
}

func (s *BlobStore) Write(name string, blob []byte) (bool, error) {
res, err := s.Client.Set(name, blob, s.TTL).Result()
res, err := s.Client.Set(context.TODO(), name, blob, s.TTL).Result()
if res != "OK" {
return false, err
}
Expand Down
7 changes: 5 additions & 2 deletions app/services/credentials_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ func TestCredentialsVerifierWithTOTPSuccess(t *testing.T) {
username := "myname"
password := "mysecret"
dbEncryptionKey := []byte("DLz2TNDRdWWA5w8YNeCJ7uzcS4WDzQmB")
// nolint: gosec
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM"
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==")
bcrypted := []byte("$2a$04$lzQPXlov4RFLxps1uUGq4e4wmVjLYz3WrqQw4bSdfIiJRyo3/fk3C")

cfg := app.Config{BcryptCost: 4, DBEncryptionKey: dbEncryptionKey}
store := mock.NewAccountStore()
account, _ := store.Create(username, bcrypted)
store.SetTOTPSecret(account.ID, totpSecretEnc)
_, err := store.SetTOTPSecret(account.ID, totpSecretEnc)
require.NoError(t, err)

code, err := totp.GenerateCode(totpSecret, time.Now())
require.NoError(t, err)
Expand Down Expand Up @@ -92,7 +94,8 @@ func TestCredentialsVerifierWithTOTPFailure(t *testing.T) {
cfg := app.Config{BcryptCost: 4, DBEncryptionKey: dbEncryptionKey}
store := mock.NewAccountStore()
account, _ := store.Create(username, bcrypted)
store.SetTOTPSecret(account.ID, totpSecretEnc)
_, err := store.SetTOTPSecret(account.ID, totpSecretEnc)
require.NoError(t, err)

testCases := []struct {
code string
Expand Down
2 changes: 1 addition & 1 deletion app/services/password_changer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestPasswordChanger(t *testing.T) {
}

invoke := func(id int, currentPassword string, password string) error {
return services.PasswordChanger(accountStore, &ops.LogReporter{logrus.New()}, cfg, id, currentPassword, password)
return services.PasswordChanger(accountStore, &ops.LogReporter{FieldLogger: logrus.New()}, cfg, id, currentPassword, password)
}

factory := func(username string, password string) (*models.Account, error) {
Expand Down
9 changes: 6 additions & 3 deletions app/services/password_resetter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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==")

Expand All @@ -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)

Expand All @@ -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)

Expand Down
9 changes: 6 additions & 3 deletions app/services/passwordless_token_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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==")

Expand All @@ -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)

Expand All @@ -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)

Expand Down
9 changes: 6 additions & 3 deletions server/handlers/post_password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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==")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"}})
})
}
9 changes: 3 additions & 6 deletions server/handlers/post_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import (
"testing"
"time"

"golang.org/x/crypto/bcrypt"

"github.com/keratin/authn-server/app/services"
"github.com/keratin/authn-server/lib/route"
"github.com/keratin/authn-server/server/test"
"github.com/keratin/authn-server/app/services"
"github.com/keratin/authn-server/lib/route"
"github.com/keratin/authn-server/server/test"
Expand Down Expand Up @@ -97,6 +92,7 @@ func TestPostSessionFailure(t *testing.T) {
}

func TestPostSessionSuccessWithTOTP(t *testing.T) {
// nolint: gosec
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM"
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==")

Expand Down Expand Up @@ -128,6 +124,7 @@ func TestPostSessionSuccessWithTOTP(t *testing.T) {
}

func TestPostSessionSuccessWithSessionAndTOTP(t *testing.T) {
// nolint: gosec
totpSecret := "JKK5AG4NDAWSZSR4ZFKZBWZ7OJGLB2JM"
totpSecretEnc := []byte("cli6azfL5i7PAnh8U/w3Zbglsm3XcdaGODy+Ga5QqT02c9hotDAR1Y28--3UihzsJhw/+EU3R6--qUw9L8DwN5XPVfOStshKzA==")

Expand Down Expand Up @@ -188,7 +185,7 @@ func TestPostSessionFailureWithTOTP(t *testing.T) {
totpCode string
errors services.FieldErrors
}{
{"foo", "bar", "12345", services.FieldErrors{{"totp", "INVALID_OR_EXPIRED"}}},
{"foo", "bar", "12345", services.FieldErrors{{Field: "totp", Message: "INVALID_OR_EXPIRED"}}},
}

for _, tc := range testCases {
Expand Down
9 changes: 6 additions & 3 deletions server/handlers/post_session_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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==")

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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"}})
})
}
2 changes: 2 additions & 0 deletions server/handlers/post_totp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 2e4eebe

Please sign in to comment.