(t *testing.T)
| 150 | } |
| 151 | |
| 152 | func TestAuthOriginPreValidate(t *testing.T) { |
| 153 | t.Parallel() |
| 154 | |
| 155 | app, _ := tests.NewTestApp() |
| 156 | defer app.Cleanup() |
| 157 | |
| 158 | originsCol, err := app.FindCollectionByNameOrId(core.CollectionNameAuthOrigins) |
| 159 | if err != nil { |
| 160 | t.Fatal(err) |
| 161 | } |
| 162 | |
| 163 | user, err := app.FindAuthRecordByEmail("users", "test@example.com") |
| 164 | if err != nil { |
| 165 | t.Fatal(err) |
| 166 | } |
| 167 | |
| 168 | t.Run("no proxy record", func(t *testing.T) { |
| 169 | origin := &core.AuthOrigin{} |
| 170 | |
| 171 | if err := app.Validate(origin); err == nil { |
| 172 | t.Fatal("Expected collection validation error") |
| 173 | } |
| 174 | }) |
| 175 | |
| 176 | t.Run("non-AuthOrigin collection", func(t *testing.T) { |
| 177 | origin := &core.AuthOrigin{} |
| 178 | origin.SetProxyRecord(core.NewRecord(core.NewBaseCollection("invalid"))) |
| 179 | origin.SetRecordRef(user.Id) |
| 180 | origin.SetCollectionRef(user.Collection().Id) |
| 181 | origin.SetFingerprint("abc") |
| 182 | |
| 183 | if err := app.Validate(origin); err == nil { |
| 184 | t.Fatal("Expected collection validation error") |
| 185 | } |
| 186 | }) |
| 187 | |
| 188 | t.Run("AuthOrigin collection", func(t *testing.T) { |
| 189 | origin := &core.AuthOrigin{} |
| 190 | origin.SetProxyRecord(core.NewRecord(originsCol)) |
| 191 | origin.SetRecordRef(user.Id) |
| 192 | origin.SetCollectionRef(user.Collection().Id) |
| 193 | origin.SetFingerprint("abc") |
| 194 | |
| 195 | if err := app.Validate(origin); err != nil { |
| 196 | t.Fatalf("Expected nil validation error, got %v", err) |
| 197 | } |
| 198 | }) |
| 199 | } |
| 200 | |
| 201 | func TestAuthOriginValidateHook(t *testing.T) { |
| 202 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…