-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
802 additions
and
695 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Submodule e
updated
from 6f3574 to 6b755f
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 |
---|---|---|
|
@@ -64,7 +64,8 @@ func TestGenerateAndUpsertRecoveryCodes(t *testing.T) { | |
user := "[email protected]" | ||
rc, err := srv.Auth().generateAndUpsertRecoveryCodes(ctx, user) | ||
require.NoError(t, err) | ||
require.Len(t, rc, numOfRecoveryCodes) | ||
require.Len(t, rc.Codes, numOfRecoveryCodes) | ||
require.NotEmpty(t, rc.Created) | ||
|
||
// Test codes are not marked used. | ||
recovery, err := srv.Auth().GetRecoveryCodes(ctx, user, true /* withSecrets */) | ||
|
@@ -74,7 +75,7 @@ func TestGenerateAndUpsertRecoveryCodes(t *testing.T) { | |
} | ||
|
||
// Test each codes are of correct format and used. | ||
for _, code := range rc { | ||
for _, code := range rc.Codes { | ||
s := strings.Split(code, "-") | ||
|
||
// 9 b/c 1 for prefix, 8 for words. | ||
|
@@ -94,15 +95,15 @@ func TestGenerateAndUpsertRecoveryCodes(t *testing.T) { | |
} | ||
|
||
// Test with a used code returns error. | ||
err = srv.Auth().verifyRecoveryCode(ctx, user, []byte(rc[0])) | ||
err = srv.Auth().verifyRecoveryCode(ctx, user, []byte(rc.Codes[0])) | ||
require.True(t, trace.IsAccessDenied(err)) | ||
|
||
// Test with invalid recovery code returns error. | ||
err = srv.Auth().verifyRecoveryCode(ctx, user, []byte("invalidcode")) | ||
require.True(t, trace.IsAccessDenied(err)) | ||
|
||
// Test with non-existing user returns error. | ||
err = srv.Auth().verifyRecoveryCode(ctx, "doesnotexist", []byte(rc[0])) | ||
err = srv.Auth().verifyRecoveryCode(ctx, "doesnotexist", []byte(rc.Codes[0])) | ||
require.True(t, trace.IsAccessDenied(err)) | ||
} | ||
|
||
|
@@ -116,21 +117,21 @@ func TestRecoveryCodeEventsEmitted(t *testing.T) { | |
user := "[email protected]" | ||
|
||
// Test generated recovery codes event. | ||
tc, err := srv.Auth().generateAndUpsertRecoveryCodes(ctx, user) | ||
rc, err := srv.Auth().generateAndUpsertRecoveryCodes(ctx, user) | ||
require.NoError(t, err) | ||
event := mockEmitter.LastEvent() | ||
require.Equal(t, events.RecoveryCodeGeneratedEvent, event.GetType()) | ||
require.Equal(t, events.RecoveryCodesGenerateCode, event.GetCode()) | ||
|
||
// Test used recovery code event. | ||
err = srv.Auth().verifyRecoveryCode(ctx, user, []byte(tc[0])) | ||
err = srv.Auth().verifyRecoveryCode(ctx, user, []byte(rc.Codes[0])) | ||
require.NoError(t, err) | ||
event = mockEmitter.LastEvent() | ||
require.Equal(t, events.RecoveryCodeUsedEvent, event.GetType()) | ||
require.Equal(t, events.RecoveryCodeUseSuccessCode, event.GetCode()) | ||
|
||
// Re-using the same token emits failed event. | ||
err = srv.Auth().verifyRecoveryCode(ctx, user, []byte(tc[0])) | ||
err = srv.Auth().verifyRecoveryCode(ctx, user, []byte(rc.Codes[0])) | ||
require.Error(t, err) | ||
event = mockEmitter.LastEvent() | ||
require.Equal(t, events.RecoveryCodeUsedEvent, event.GetType()) | ||
|
@@ -1275,7 +1276,8 @@ func TestCreateAccountRecoveryCodes(t *testing.T) { | |
|
||
default: | ||
require.NoError(t, err) | ||
require.Len(t, res.GetRecoveryCodes(), numOfRecoveryCodes) | ||
require.Len(t, res.GetCodes(), numOfRecoveryCodes) | ||
require.NotEmpty(t, res.GetCreated()) | ||
|
||
// Check token is deleted after success. | ||
_, err = srv.Auth().Identity.GetUserToken(ctx, req.TokenID) | ||
|
@@ -1318,8 +1320,8 @@ func TestGetAccountRecoveryCodes(t *testing.T) { | |
|
||
rc, err := clt.GetAccountRecoveryCodes(ctx, &proto.GetAccountRecoveryCodesRequest{}) | ||
require.NoError(t, err) | ||
require.Empty(t, rc.Spec.Codes) | ||
require.NotEmpty(t, rc.Spec.Created) | ||
require.Empty(t, rc.Codes) | ||
require.NotEmpty(t, rc.Created) | ||
} | ||
|
||
func triggerLoginLock(t *testing.T, srv *Server, username string) { | ||
|
@@ -1416,7 +1418,7 @@ func createUserWithSecondFactors(srv *TestTLSServer) (*userAuthCreds, error) { | |
return &userAuthCreds{ | ||
username: username, | ||
password: password, | ||
recoveryCodes: res.GetRecoveryCodes(), | ||
recoveryCodes: res.GetRecovery().GetCodes(), | ||
totpDev: totpDev, | ||
webDev: webDev, | ||
}, nil | ||
|
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
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 |
---|---|---|
|
@@ -1535,9 +1535,10 @@ func (s *WebSuite) TestChangePasswordAndAddTOTPDeviceWithToken(c *C) { | |
c.Assert(err, IsNil) | ||
|
||
// Test that no recovery codes are returned b/c cloud feature isn't enabled. | ||
var recoveryCodes []string | ||
c.Assert(json.Unmarshal(re.Bytes(), &recoveryCodes), IsNil) | ||
c.Assert(recoveryCodes, HasLen, 0) | ||
var response ui.RecoveryCodes | ||
c.Assert(json.Unmarshal(re.Bytes(), &response), IsNil) | ||
c.Assert(response.Codes, IsNil) | ||
c.Assert(response.Created, IsNil) | ||
} | ||
|
||
func (s *WebSuite) TestChangePasswordAndAddU2FDeviceWithToken(c *C) { | ||
|
@@ -1592,9 +1593,10 @@ func (s *WebSuite) TestChangePasswordAndAddU2FDeviceWithToken(c *C) { | |
c.Assert(err, IsNil) | ||
|
||
// Test that no recovery codes are returned b/c cloud is not turned on. | ||
var recoveryCodes []string | ||
c.Assert(json.Unmarshal(re.Bytes(), &recoveryCodes), IsNil) | ||
c.Assert(recoveryCodes, HasLen, 0) | ||
var response ui.RecoveryCodes | ||
c.Assert(json.Unmarshal(re.Bytes(), &response), IsNil) | ||
c.Assert(response.Codes, IsNil) | ||
c.Assert(response.Created, IsNil) | ||
} | ||
|
||
// TestEmptyMotD ensures that responses returned by both /webapi/ping and | ||
|
@@ -2802,7 +2804,7 @@ func TestChangeUserAuthentication_recoveryCodesReturnedForCloud(t *testing.T) { | |
}}, | ||
}) | ||
require.NoError(t, err) | ||
require.Empty(t, re.RecoveryCodes) | ||
require.Nil(t, re.Recovery) | ||
|
||
// Create a user that is valid for recovery. | ||
teleUser, err = types.NewUser("[email protected]") | ||
|
@@ -2831,7 +2833,8 @@ func TestChangeUserAuthentication_recoveryCodesReturnedForCloud(t *testing.T) { | |
}}, | ||
}) | ||
require.NoError(t, err) | ||
require.Len(t, re.RecoveryCodes, 3) | ||
require.Len(t, re.Recovery.Codes, 3) | ||
require.NotEmpty(t, re.Recovery.Created) | ||
} | ||
|
||
type authProviderMock struct { | ||
|
Oops, something went wrong.