(t *testing.T)
| 173 | } |
| 174 | |
| 175 | func 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 | |
| 226 | func TestExternalAuthValidateHook(t *testing.T) { |
| 227 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…