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

Function addUserAlice

db/functions/function_test.go:153–172  ·  view source on GitHub ↗

Adds a user "alice" to the database, with role "hero" and access to channels "wonderland" and "lookingglass".

(t *testing.T, db *db.Database)

Source from the content-addressed store, hash-verified

151// Adds a user "alice" to the database, with role "hero"
152// and access to channels "wonderland" and "lookingglass".
153func addUserAlice(t *testing.T, db *db.Database) auth.User {
154 authenticator := db.Authenticator(base.TestCtx(t))
155 hero, err := authenticator.NewRole("hero", base.SetOf("heroes"))
156 require.NoError(t, err)
157 require.NoError(t, authenticator.Save(hero))
158
159 villain, err := authenticator.NewRole("villain", base.SetOf("villains"))
160 require.NoError(t, err)
161 require.NoError(t, authenticator.Save(villain))
162
163 user, err := authenticator.NewUser("alice", "pass", base.SetOf("wonderland", "lookingglass", "city-London", "user-alice"))
164 require.NoError(t, err)
165 user.SetExplicitRoles(channels.TimedSet{"hero": channels.NewVbSimpleSequence(1)}, 1)
166 require.NoError(t, authenticator.Save(user), "Save")
167
168 // Have to call GetUser to get a user object that's properly configured:
169 user, err = authenticator.GetUser("alice")
170 require.NoError(t, err)
171 return user
172}
173
174// Unit test for JS user functions.
175func TestUserFunctions(t *testing.T) {

Callers 2

TestUserFunctionsFunction · 0.85
TestUserN1QLQueriesFunction · 0.85

Calls 9

SetExplicitRolesMethod · 0.95
TestCtxFunction · 0.92
SetOfFunction · 0.92
NewVbSimpleSequenceFunction · 0.92
NewRoleMethod · 0.80
SaveMethod · 0.80
NewUserMethod · 0.80
GetUserMethod · 0.80
AuthenticatorMethod · 0.45

Tested by

no test coverage detected