(t *testing.T)
| 182 | } |
| 183 | |
| 184 | func TestMFAPreValidate(t *testing.T) { |
| 185 | t.Parallel() |
| 186 | |
| 187 | app, _ := tests.NewTestApp() |
| 188 | defer app.Cleanup() |
| 189 | |
| 190 | mfasCol, err := app.FindCollectionByNameOrId(core.CollectionNameMFAs) |
| 191 | if err != nil { |
| 192 | t.Fatal(err) |
| 193 | } |
| 194 | |
| 195 | user, err := app.FindAuthRecordByEmail("users", "test@example.com") |
| 196 | if err != nil { |
| 197 | t.Fatal(err) |
| 198 | } |
| 199 | |
| 200 | t.Run("no proxy record", func(t *testing.T) { |
| 201 | mfa := &core.MFA{} |
| 202 | |
| 203 | if err := app.Validate(mfa); err == nil { |
| 204 | t.Fatal("Expected collection validation error") |
| 205 | } |
| 206 | }) |
| 207 | |
| 208 | t.Run("non-MFA collection", func(t *testing.T) { |
| 209 | mfa := &core.MFA{} |
| 210 | mfa.SetProxyRecord(core.NewRecord(core.NewBaseCollection("invalid"))) |
| 211 | mfa.SetRecordRef(user.Id) |
| 212 | mfa.SetCollectionRef(user.Collection().Id) |
| 213 | mfa.SetMethod("test123") |
| 214 | |
| 215 | if err := app.Validate(mfa); err == nil { |
| 216 | t.Fatal("Expected collection validation error") |
| 217 | } |
| 218 | }) |
| 219 | |
| 220 | t.Run("MFA collection", func(t *testing.T) { |
| 221 | mfa := &core.MFA{} |
| 222 | mfa.SetProxyRecord(core.NewRecord(mfasCol)) |
| 223 | mfa.SetRecordRef(user.Id) |
| 224 | mfa.SetCollectionRef(user.Collection().Id) |
| 225 | mfa.SetMethod("test123") |
| 226 | |
| 227 | if err := app.Validate(mfa); err != nil { |
| 228 | t.Fatalf("Expected nil validation error, got %v", err) |
| 229 | } |
| 230 | }) |
| 231 | } |
| 232 | |
| 233 | func TestMFAValidateHook(t *testing.T) { |
| 234 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…