Test-only version of GetPrincipal that doesn't trigger channel/role recalculation
(tb testing.TB, name string, isUser bool)
| 479 | |
| 480 | // Test-only version of GetPrincipal that doesn't trigger channel/role recalculation |
| 481 | func (dbc *DatabaseContext) GetPrincipalForTest(tb testing.TB, name string, isUser bool) (info *auth.PrincipalConfig, err error) { |
| 482 | ctx := base.TestCtx(tb) |
| 483 | var princ auth.Principal |
| 484 | if isUser { |
| 485 | princ, err = dbc.Authenticator(ctx).GetUser(name) |
| 486 | } else { |
| 487 | princ, err = dbc.Authenticator(ctx).GetRole(name) |
| 488 | } |
| 489 | if princ == nil { |
| 490 | return |
| 491 | } |
| 492 | info = new(auth.PrincipalConfig) |
| 493 | info.Name = &name |
| 494 | info.ExplicitChannels = princ.CollectionExplicitChannels(base.DefaultScope, base.DefaultCollection).AsSet() |
| 495 | if user, ok := princ.(auth.User); ok { |
| 496 | channels, err := user.InheritedCollectionChannels(base.DefaultScope, base.DefaultCollection) |
| 497 | require.NoError(tb, err) |
| 498 | info.Channels = channels.AsSet() |
| 499 | email := user.Email() |
| 500 | info.Email = &email |
| 501 | info.Disabled = base.Ptr(user.Disabled()) |
| 502 | info.ExplicitRoleNames = user.ExplicitRoles().AsSet() |
| 503 | info.RoleNames = user.RoleNames().AllKeys() |
| 504 | } else { |
| 505 | info.Channels = princ.Channels().AsSet() |
| 506 | } |
| 507 | return |
| 508 | } |
| 509 | |
| 510 | // FlushRevisionCacheForTest creates a new revision cache. This is currently at the database level. Only use this in test code. |
| 511 | func (db *DatabaseContext) FlushRevisionCacheForTest() { |