Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STORY-648] feat: raise DB user passwords minimum length to 24 #1077

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### To be Released

* feat(database/users): raise minimum user password length to 24 ([PR#1077](https://github.com/Scalingo/cli/pull/1077))

### 1.33.0

* fix(one-off): remove async field from the run command ([PR#1060](https://github.com/Scalingo/cli/pull/1060))
Expand Down
2 changes: 1 addition & 1 deletion db/users/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func CreateUser(ctx context.Context, app, addonUUID, username string, readonly b
isPasswordGenerated := false
if password == "" {
isPasswordGenerated = true
password = gopassword.Generate(64)
password = gopassword.Generate()
confirmedPassword = password
}

Expand Down
6 changes: 3 additions & 3 deletions db/users/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ func isPasswordValid(password, confirmedPassword string) (string, bool) {
if password != confirmedPassword {
return "Password confirmation doesn't match", false
}
if len(password) < 8 || len(password) > 64 {
return "Password must contain between 8 and 64 characters", false
if len(password) < 24 || len(password) > 64 {
return "Password must contain between 24 and 64 characters", false
}
return "", true
}

func isUsernameValid(username string) (string, bool) {
if len(username) < 6 || len(username) > 32 {
return "name must contain between 6 and 32 characters", false
return "Name must contain between 6 and 32 characters", false
}
return "", true
}
105 changes: 105 additions & 0 deletions db/users/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package users

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_isPasswordValid(t *testing.T) {
testPasswords := map[string]struct {
password string
confirmation string
expectedValidity bool
expectedMessage string
}{
"empty": {
password: "",
confirmation: "",
expectedValidity: true,
expectedMessage: "",
},
"confirmation doesn't match": {
password: "abc",
confirmation: "aBc",
expectedValidity: false,
expectedMessage: "Password confirmation doesn't match",
},
"too short": {
password: "123456789a123456789b123",
confirmation: "123456789a123456789b123",
expectedValidity: false,
expectedMessage: "Password must contain between 24 and 64 characters",
},
"too long": {
password: "123456789a123456789b123456789c123456789d123456789e123456789f12345",
confirmation: "123456789a123456789b123456789c123456789d123456789e123456789f12345",
expectedValidity: false,
expectedMessage: "Password must contain between 24 and 64 characters",
},
"valid, short password": {
password: "123456789a123456789b1234",
confirmation: "123456789a123456789b1234",
expectedValidity: true,
expectedMessage: "",
},
"valid, log password ": {
password: "123456789a123456789b123456789c123456789d123456789e123456789f1234",
confirmation: "123456789a123456789b123456789c123456789d123456789e123456789f1234",
expectedValidity: true,
expectedMessage: "",
},
}

for name, testCase := range testPasswords {
t.Run(name, func(t *testing.T) {
message, isValid := isPasswordValid(testCase.password, testCase.confirmation)

assert.Equal(t, testCase.expectedValidity, isValid)
assert.Equal(t, testCase.expectedMessage, message)
})
}
}

func Test_isUsernameValid(t *testing.T) {
testPasswords := map[string]struct {
username string
expectedValidity bool
expectedMessage string
}{
"empty": {
username: "",
expectedValidity: false,
expectedMessage: "Name must contain between 6 and 32 characters",
},
"too short": {
username: "12345",
expectedValidity: false,
expectedMessage: "Name must contain between 6 and 32 characters",
},
"too long": {
username: "123456789a123456789b123456789c123",
expectedValidity: false,
expectedMessage: "Name must contain between 6 and 32 characters",
},
"valid, short username": {
username: "123456",
expectedValidity: true,
expectedMessage: "",
},
"valid, long username": {
username: "123456789a123456789b123456789c12",
expectedValidity: true,
expectedMessage: "",
},
}

for name, testCase := range testPasswords {
t.Run(name, func(t *testing.T) {
message, isValid := isUsernameValid(testCase.username)

assert.Equal(t, testCase.expectedValidity, isValid)
assert.Equal(t, testCase.expectedMessage, message)
})
}
}
Loading