diff options
| author | Clement Michaud <clement.michaud34@gmail.com> | 2019-12-27 18:09:57 +0100 |
|---|---|---|
| committer | Clément Michaud <clement.michaud34@gmail.com> | 2019-12-28 09:08:54 +0100 |
| commit | 716e01752139bd36df2797ca952c820544b476aa (patch) | |
| tree | 6b52d3c4a3c2b6d6b69e05d2dc3be5a5e5960743 /internal/authentication/file_user_provider_test.go | |
| parent | 1ee442e86f76ed368f96fcdcbded9bd724bab579 (diff) | |
Add early checks for user hashes.
Diffstat (limited to 'internal/authentication/file_user_provider_test.go')
| -rw-r--r-- | internal/authentication/file_user_provider_test.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/internal/authentication/file_user_provider_test.go b/internal/authentication/file_user_provider_test.go index bb07fc4bf..2e3d03a25 100644 --- a/internal/authentication/file_user_provider_test.go +++ b/internal/authentication/file_user_provider_test.go @@ -84,7 +84,7 @@ func TestShouldUpdatePassword(t *testing.T) { func TestShouldRaiseWhenLoadingMalformedDatabaseForFirstTime(t *testing.T) { WithDatabase(MalformedUserDatabaseContent, func(path string) { - assert.Panics(t, func() { + assert.PanicsWithValue(t, "Unable to parse database: yaml: line 4: mapping values are not allowed in this context", func() { NewFileUserProvider(path) }) }) @@ -92,7 +92,15 @@ func TestShouldRaiseWhenLoadingMalformedDatabaseForFirstTime(t *testing.T) { func TestShouldRaiseWhenLoadingDatabaseWithBadSchemaForFirstTime(t *testing.T) { WithDatabase(BadSchemaUserDatabaseContent, func(path string) { - assert.Panics(t, func() { + assert.PanicsWithValue(t, "Invalid schema of database: Users: non zero value required", func() { + NewFileUserProvider(path) + }) + }) +} + +func TestShouldRaiseWhenLoadingDatabaseWithBadHashesForTheFirstTime(t *testing.T) { + WithDatabase(BadHashContent, func(path string) { + assert.PanicsWithValue(t, "Unable to parse hash of user john: Cannot match pattern 'rounds=<int>' to find the number of rounds", func() { NewFileUserProvider(path) }) }) @@ -165,3 +173,16 @@ users: password: "$6$rounds=500000$jgiCMRyGXzoqpxS3$w2pJeZnnH8bwW3zzvoMWtTRfQYsHbWbD/hquuQ5vUeIyl9gdwBIt6RWk2S6afBA0DPakbeWgD/4SZPiS0hYtU/" email: james.dean@authelia.com `) + +var BadHashContent = []byte(` +users: + john: + password: "$6$rounds00000$jgiCMRyGXzoqpxS3$w2pJeZnnH8bwW3zzvoMWtTRfQYsHbWbD/hquuQ5vUeIyl9gdwBIt6RWk2S6afBA0DPakbeWgD/4SZPiS0hYtU/" + email: john.doe@authelia.com + groups: + - admins + - dev + james: + password: "$6$rounds=500000$jgiCMRyGXzoqpxS3$w2pJeZnnH8bwW3zzvoMWtTRfQYsHbWbD/hquuQ5vUeIyl9gdwBIt6RWk2S6afBA0DPakbeWgD/4SZPiS0hYtU/" + email: james.dean@authelia.com +`) |
