diff options
Diffstat (limited to 'internal/authentication/file_user_provider_test.go')
| -rw-r--r-- | internal/authentication/file_user_provider_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/authentication/file_user_provider_test.go b/internal/authentication/file_user_provider_test.go index 2c9dbe1ff..7ce16def4 100644 --- a/internal/authentication/file_user_provider_test.go +++ b/internal/authentication/file_user_provider_test.go @@ -7,7 +7,9 @@ import ( "strings" "testing" + "aletheia.icu/broccoli/fs" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/authelia/authelia/internal/configuration/schema" ) @@ -32,6 +34,41 @@ func WithDatabase(content []byte, f func(path string)) { } } +func TestShouldErrorNoUserDBInEmbeddedFS(t *testing.T) { + oldCfg := cfg + cfg = fs.New(false, []byte("\x1b~\x00\x80\x8d\x94n\xc2|\x84J\xf7\xbfn\xfd\xf7w;.\x8d m\xb2&\xd1Z\xec\xb2\x05\xb9\xc00\x8a\xf7(\x80^78\t(\f\f\xc3p\xc2\xc1\x06[a\xa2\xb3\xa4P\xe5\xa14\xfb\x19\xb2cp\xf6\x90-Z\xb2\x11\xe0l\xa1\x80\\\x95Vh\t\xc5\x06\x16\xfa\x8c\xc0\"!\xa5\xcf\xf7$\x9a\xb2\a`\xc6\x18\xc8~\xce8\r\x16Z\x9d\xc3\xe3\xff\x00")) + errors := checkDatabase("./nonexistent.yml") + cfg = oldCfg + + require.Len(t, errors, 3) + + require.EqualError(t, errors[0], "Unable to find database file: ./nonexistent.yml") + require.EqualError(t, errors[1], "Generating database file: ./nonexistent.yml") + require.EqualError(t, errors[2], "Unable to open users_database.template.yml: file does not exist") +} + +func TestShouldErrorPermissionsOnLocalFS(t *testing.T) { + _ = os.Mkdir("/tmp/noperms/", 0000) + errors := checkDatabase("/tmp/noperms/users_database.yml") + + require.Len(t, errors, 3) + + require.EqualError(t, errors[0], "Unable to find database file: /tmp/noperms/users_database.yml") + require.EqualError(t, errors[1], "Generating database file: /tmp/noperms/users_database.yml") + require.EqualError(t, errors[2], "Unable to generate /tmp/noperms/users_database.yml: open /tmp/noperms/users_database.yml: permission denied") +} + +func TestShouldErrorAndGenerateUserDB(t *testing.T) { + errors := checkDatabase("./nonexistent.yml") + _ = os.Remove("./nonexistent.yml") + + require.Len(t, errors, 3) + + require.EqualError(t, errors[0], "Unable to find database file: ./nonexistent.yml") + require.EqualError(t, errors[1], "Generating database file: ./nonexistent.yml") + require.EqualError(t, errors[2], "Generated database at: ./nonexistent.yml") +} + func TestShouldCheckUserArgon2idPasswordIsCorrect(t *testing.T) { WithDatabase(UserDatabaseContent, func(path string) { config := DefaultFileAuthenticationBackendConfiguration |
