forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip validating minimum password length for existing user logins (gra…
…vitational#36579) The minimum password length was being checked against all password checks, both for validating existing passwords and new passwords. This meant that if the minimum password length was increased, any existing passwords that were under the minimum length would be rejected. Follow-up to gravitational#36389. Ref gravitational#1936. Ref gravitational#7687.
- Loading branch information
Showing
3 changed files
with
71 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import ( | |
"github.com/jonboulle/clockwork" | ||
"github.com/pquerna/otp/totp" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/crypto/bcrypt" | ||
|
||
"github.com/gravitational/teleport" | ||
"github.com/gravitational/teleport/api/client/proto" | ||
|
@@ -46,6 +47,7 @@ import ( | |
"github.com/gravitational/teleport/lib/events/eventstest" | ||
"github.com/gravitational/teleport/lib/services" | ||
"github.com/gravitational/teleport/lib/services/suite" | ||
"github.com/gravitational/teleport/lib/utils" | ||
) | ||
|
||
type passwordSuite struct { | ||
|
@@ -126,6 +128,38 @@ func TestUserNotFound(t *testing.T) { | |
require.True(t, trace.IsBadParameter(err)) | ||
} | ||
|
||
func TestPasswordLengthChange(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
srv := newTestTLSServer(t) | ||
authServer := srv.Auth() | ||
|
||
ap, err := types.NewAuthPreference(types.AuthPreferenceSpecV2{ | ||
Type: constants.Local, | ||
SecondFactor: constants.SecondFactorOff, | ||
}) | ||
require.NoError(t, err) | ||
|
||
err = authServer.SetAuthPreference(ctx, ap) | ||
require.NoError(t, err) | ||
|
||
username := fmt.Sprintf("llama%[email protected]", rand.Int()) | ||
password := []byte("a") | ||
_, _, err = CreateUserAndRole(authServer, username, []string{username}, nil) | ||
require.NoError(t, err) | ||
|
||
hash, err := utils.BcryptFromPassword(password, bcrypt.DefaultCost) | ||
require.NoError(t, err) | ||
|
||
// Set an initial password that is shorter than minimum length | ||
err = authServer.UpsertPasswordHash(username, hash) | ||
require.NoError(t, err) | ||
|
||
// Ensure that a shorter password still works for auth | ||
err = authServer.checkPasswordWOToken(username, password) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestChangePassword(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
|
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