MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordAuthResponseAuthAlertCheck

Function TestRecordAuthResponseAuthAlertCheck

apis/record_helpers_test.go:340–465  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

338}
339
340func 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")

Callers

nothing calls this directly

Calls 15

CleanupMethod · 0.95
SetCollectionRefMethod · 0.95
SetRecordRefMethod · 0.95
SetFingerprintMethod · 0.95
FingerprintMethod · 0.95
NewTestAppFunction · 0.92
PointerFunction · 0.92
NowDateTimeFunction · 0.92
NewAuthOriginFunction · 0.92
RecordAuthResponseFunction · 0.92
CollectionMethod · 0.80
SetRawMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…