[#6607] allowed manually changing the password from the create/update hooks
This commit is contained in:
@@ -887,6 +887,119 @@ func TestRecordUpsertSubmitSuccess(t *testing.T) {
|
||||
testFilesCount(t, testApp, record, 2) // the file + attrs
|
||||
}
|
||||
|
||||
func TestRecordUpsertPasswordsSync(t *testing.T) {
|
||||
testApp, _ := tests.NewTestApp()
|
||||
defer testApp.Cleanup()
|
||||
|
||||
users, err := testApp.FindCollectionByNameOrId("users")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Run("new user without password", func(t *testing.T) {
|
||||
record := core.NewRecord(users)
|
||||
|
||||
form := forms.NewRecordUpsert(testApp, record)
|
||||
|
||||
err := form.Submit()
|
||||
|
||||
tests.TestValidationErrors(t, err, []string{"password", "passwordConfirm"})
|
||||
})
|
||||
|
||||
t.Run("new user with manual password", func(t *testing.T) {
|
||||
record := core.NewRecord(users)
|
||||
|
||||
form := forms.NewRecordUpsert(testApp, record)
|
||||
|
||||
record.SetPassword("1234567890")
|
||||
|
||||
err := form.Submit()
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no errors, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("new user with random password", func(t *testing.T) {
|
||||
record := core.NewRecord(users)
|
||||
|
||||
form := forms.NewRecordUpsert(testApp, record)
|
||||
|
||||
record.SetRandomPassword()
|
||||
|
||||
err := form.Submit()
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no errors, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update user with no password change", func(t *testing.T) {
|
||||
record, err := testApp.FindAuthRecordByEmail(users, "test@example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
oldHash := record.GetString("password:hash")
|
||||
|
||||
form := forms.NewRecordUpsert(testApp, record)
|
||||
|
||||
err = form.Submit()
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no errors, got %v", err)
|
||||
}
|
||||
|
||||
newHash := record.GetString("password:hash")
|
||||
if newHash == "" || newHash != oldHash {
|
||||
t.Fatal("Expected no password change")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update user with manual password change", func(t *testing.T) {
|
||||
record, err := testApp.FindAuthRecordByEmail(users, "test@example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
oldHash := record.GetString("password:hash")
|
||||
|
||||
form := forms.NewRecordUpsert(testApp, record)
|
||||
|
||||
record.SetPassword("1234567890")
|
||||
|
||||
err = form.Submit()
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no errors, got %v", err)
|
||||
}
|
||||
|
||||
newHash := record.GetString("password:hash")
|
||||
if newHash == "" || newHash == oldHash {
|
||||
t.Fatal("Expected password change")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update user with random password change", func(t *testing.T) {
|
||||
record, err := testApp.FindAuthRecordByEmail(users, "test@example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
oldHash := record.GetString("password:hash")
|
||||
|
||||
form := forms.NewRecordUpsert(testApp, record)
|
||||
|
||||
record.SetRandomPassword()
|
||||
|
||||
err = form.Submit()
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no errors, got %v", err)
|
||||
}
|
||||
|
||||
newHash := record.GetString("password:hash")
|
||||
if newHash == "" || newHash == oldHash {
|
||||
t.Fatal("Expected password change")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
func testFilesCount(t *testing.T, app core.App, record *core.Record, count int) {
|
||||
|
||||
Reference in New Issue
Block a user