All checks were successful
Publish / Test, build, and push image (push) Successful in 3m38s
34 lines
817 B
Go
34 lines
817 B
Go
package store
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func TestMigrateUpdatesAdminCredentials(t *testing.T) {
|
|
st, err := Open(filepath.Join(t.TempDir(), "app.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = st.Close() })
|
|
if err := st.Migrate("admin", "old-password"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := st.Migrate("owner", "new-password"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
user, err := st.AdminByUsername(t.Context(), "owner")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := bcrypt.CompareHashAndPassword(user.PasswordHash, []byte("new-password")); err != nil {
|
|
t.Fatalf("expected updated password hash: %v", err)
|
|
}
|
|
if _, err := st.AdminByUsername(t.Context(), "admin"); !IsNotFound(err) {
|
|
t.Fatalf("expected old username to be removed, got %v", err)
|
|
}
|
|
}
|