-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1077 from Scalingo/feat/database-dashboard/659/st…
…rengthen_passwords [STORY-648] feat: raise DB user passwords minimum length to 24
- Loading branch information
Showing
4 changed files
with
111 additions
and
4 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 |
---|---|---|
@@ -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) | ||
}) | ||
} | ||
} |