MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / GetPrincipalForTest

Method GetPrincipalForTest

db/util_testing.go:481–508  ·  view source on GitHub ↗

Test-only version of GetPrincipal that doesn't trigger channel/role recalculation

(tb testing.TB, name string, isUser bool)

Source from the content-addressed store, hash-verified

479
480// Test-only version of GetPrincipal that doesn't trigger channel/role recalculation
481func (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.
511func (db *DatabaseContext) FlushRevisionCacheForTest() {

Calls 14

AuthenticatorMethod · 0.95
TestCtxFunction · 0.92
PtrFunction · 0.92
GetUserMethod · 0.80
GetRoleMethod · 0.80
AsSetMethod · 0.80
AllKeysMethod · 0.80
EmailMethod · 0.65
DisabledMethod · 0.65
ExplicitRolesMethod · 0.65

Tested by 4

TestUpdatePrincipalFunction · 0.64