MCPcopy
hub / github.com/pocketbase/pocketbase / TestExternalAuthPreValidate

Function TestExternalAuthPreValidate

core/external_auth_model_test.go:175–224  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

173}
174
175func TestExternalAuthPreValidate(t *testing.T) {
176 t.Parallel()
177
178 app, _ := tests.NewTestApp()
179 defer app.Cleanup()
180
181 externalAuthsCol, err := app.FindCollectionByNameOrId(core.CollectionNameExternalAuths)
182 if err != nil {
183 t.Fatal(err)
184 }
185
186 user, err := app.FindAuthRecordByEmail("users", "test@example.com")
187 if err != nil {
188 t.Fatal(err)
189 }
190
191 t.Run("no proxy record", func(t *testing.T) {
192 externalAuth := &core.ExternalAuth{}
193
194 if err := app.Validate(externalAuth); err == nil {
195 t.Fatal("Expected collection validation error")
196 }
197 })
198
199 t.Run("non-ExternalAuth collection", func(t *testing.T) {
200 externalAuth := &core.ExternalAuth{}
201 externalAuth.SetProxyRecord(core.NewRecord(core.NewBaseCollection("invalid")))
202 externalAuth.SetRecordRef(user.Id)
203 externalAuth.SetCollectionRef(user.Collection().Id)
204 externalAuth.SetProvider("gitlab")
205 externalAuth.SetProviderId("test123")
206
207 if err := app.Validate(externalAuth); err == nil {
208 t.Fatal("Expected collection validation error")
209 }
210 })
211
212 t.Run("ExternalAuth collection", func(t *testing.T) {
213 externalAuth := &core.ExternalAuth{}
214 externalAuth.SetProxyRecord(core.NewRecord(externalAuthsCol))
215 externalAuth.SetRecordRef(user.Id)
216 externalAuth.SetCollectionRef(user.Collection().Id)
217 externalAuth.SetProvider("gitlab")
218 externalAuth.SetProviderId("test123")
219
220 if err := app.Validate(externalAuth); err != nil {
221 t.Fatalf("Expected nil validation error, got %v", err)
222 }
223 })
224}
225
226func TestExternalAuthValidateHook(t *testing.T) {
227 t.Parallel()

Callers

nothing calls this directly

Calls 14

CleanupMethod · 0.95
SetProxyRecordMethod · 0.95
SetRecordRefMethod · 0.95
SetCollectionRefMethod · 0.95
SetProviderMethod · 0.95
SetProviderIdMethod · 0.95
NewTestAppFunction · 0.92
NewRecordFunction · 0.92
NewBaseCollectionFunction · 0.92
CollectionMethod · 0.80
FindAuthRecordByEmailMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…