2020-01-28 11:04:10 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUtils_CheckPassword(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
formPassword := "photoprism"
|
|
|
|
|
2020-04-13 18:08:21 +02:00
|
|
|
c.params.AdminPassword = "$2b$10$cRhWIleqJkbaFWhBMp54VOI25RvVubxOooCWzWgdrvl5COFxaBnAy"
|
2020-01-28 11:04:10 +01:00
|
|
|
check := c.CheckPassword(formPassword)
|
|
|
|
assert.True(t, check)
|
|
|
|
|
2020-04-13 18:08:21 +02:00
|
|
|
c.params.AdminPassword = "photoprism"
|
2020-01-28 11:04:10 +01:00
|
|
|
check = c.CheckPassword(formPassword)
|
|
|
|
assert.True(t, check)
|
|
|
|
|
2020-04-13 18:08:21 +02:00
|
|
|
c.params.AdminPassword = "$2b$10$yprZEQzm/Qy7AaePXtKfkem0kANBZgRwl8HbLE4JrjK6/8Pypgi1W"
|
2020-01-28 11:04:10 +01:00
|
|
|
check = c.CheckPassword(formPassword)
|
|
|
|
assert.False(t, check)
|
|
|
|
|
2020-04-13 18:08:21 +02:00
|
|
|
c.params.AdminPassword = "admin"
|
2020-01-28 11:04:10 +01:00
|
|
|
check = c.CheckPassword(formPassword)
|
|
|
|
assert.False(t, check)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUtils_isBcrypt(t *testing.T) {
|
|
|
|
p := "$2b$10$cRhWIleqJkbaFWhBMp54VOI25RvVubxOooCWzWgdrvl5COFxaBnAy"
|
|
|
|
assert.True(t, isBcrypt(p))
|
|
|
|
|
|
|
|
p = "$2b$10$cRhWIleqJkbaFWhBMp54VOI25RvVubxOooCWzWgdrvl5COFxaBnA"
|
|
|
|
assert.False(t, isBcrypt(p))
|
|
|
|
|
|
|
|
p = "admin"
|
|
|
|
assert.False(t, isBcrypt(p))
|
|
|
|
}
|