MCPcopy
hub / github.com/pocketbase/pocketbase / TestMFAPreValidate

Function TestMFAPreValidate

core/mfa_model_test.go:184–231  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func 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
233func TestMFAValidateHook(t *testing.T) {
234 t.Parallel()

Callers

nothing calls this directly

Calls 13

CleanupMethod · 0.95
SetProxyRecordMethod · 0.95
SetRecordRefMethod · 0.95
SetCollectionRefMethod · 0.95
SetMethodMethod · 0.95
NewTestAppFunction · 0.92
NewRecordFunction · 0.92
NewBaseCollectionFunction · 0.92
CollectionMethod · 0.80
FindAuthRecordByEmailMethod · 0.65
ValidateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…