(t *testing.T)
| 338 | } |
| 339 | |
| 340 | func TestRecordAuthResponseAuthAlertCheck(t *testing.T) { |
| 341 | const testFingerprint = "d0f88d6c87767262ba8e93d6acccd784" |
| 342 | |
| 343 | scenarios := []struct { |
| 344 | name string |
| 345 | devices []string // mock existing device fingerprints |
| 346 | expectDevices []string |
| 347 | enabled bool |
| 348 | expectEmail bool |
| 349 | }{ |
| 350 | { |
| 351 | name: "first login", |
| 352 | devices: nil, |
| 353 | expectDevices: []string{testFingerprint}, |
| 354 | enabled: true, |
| 355 | expectEmail: false, |
| 356 | }, |
| 357 | { |
| 358 | name: "existing device", |
| 359 | devices: []string{"1", testFingerprint}, |
| 360 | expectDevices: []string{"1", testFingerprint}, |
| 361 | enabled: true, |
| 362 | expectEmail: false, |
| 363 | }, |
| 364 | { |
| 365 | name: "new device (< 5)", |
| 366 | devices: []string{"1", "2"}, |
| 367 | expectDevices: []string{"1", "2", testFingerprint}, |
| 368 | enabled: true, |
| 369 | expectEmail: true, |
| 370 | }, |
| 371 | { |
| 372 | name: "new device (>= 5)", |
| 373 | devices: []string{"1", "2", "3", "4", "5"}, |
| 374 | expectDevices: []string{"2", "3", "4", "5", testFingerprint}, |
| 375 | enabled: true, |
| 376 | expectEmail: true, |
| 377 | }, |
| 378 | { |
| 379 | name: "with disabled auth alert collection flag", |
| 380 | devices: []string{"1", "2"}, |
| 381 | expectDevices: []string{"1", "2"}, |
| 382 | enabled: false, |
| 383 | expectEmail: false, |
| 384 | }, |
| 385 | } |
| 386 | |
| 387 | for _, s := range scenarios { |
| 388 | t.Run(s.name, func(t *testing.T) { |
| 389 | app, _ := tests.NewTestApp() |
| 390 | defer app.Cleanup() |
| 391 | |
| 392 | event := new(core.RequestEvent) |
| 393 | event.App = app |
| 394 | event.Request = httptest.NewRequest(http.MethodGet, "/", nil) |
| 395 | event.Response = httptest.NewRecorder() |
| 396 | |
| 397 | user, err := app.FindAuthRecordByEmail("users", "test@example.com") |
nothing calls this directly
no test coverage detected
searching dependent graphs…