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

Function TestSerializeUser

auth/auth_test.go:154–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

152}
153
154func TestSerializeUser(t *testing.T) {
155
156 ctx := base.TestCtx(t)
157 bucket := base.GetTestBucket(t)
158 defer bucket.Close(ctx)
159
160 dataStore := bucket.GetSingleDataStore()
161
162 auth := NewTestAuthenticator(t, dataStore, nil, DefaultAuthenticatorOptions(ctx))
163 user, _ := auth.NewUser("me", "letmein", ch.BaseSetOf(t, "me", "public"))
164 require.NoError(t, user.SetEmail("foo@example.com"))
165 encoded := base.MustJSONMarshal(t, user)
166 require.NotNil(t, encoded)
167 log.Printf("Marshaled User as: %s", encoded)
168
169 resu := &userImpl{auth: auth}
170 require.NoError(t, base.JSONUnmarshal(encoded, resu))
171 assert.Equal(t, user.Name(), resu.Name())
172 assert.Equal(t, user.Email(), resu.Email())
173 assert.Equal(t, user.ExplicitChannels(), resu.ExplicitChannels())
174 assert.True(t, resu.Authenticate("letmein"))
175 assert.False(t, resu.Authenticate("123456"))
176}
177
178func TestSerializeRole(t *testing.T) {
179

Callers

nothing calls this directly

Calls 15

SetEmailMethod · 0.95
EmailMethod · 0.95
EmailMethod · 0.95
AuthenticateMethod · 0.95
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
MustJSONMarshalFunction · 0.92
JSONUnmarshalFunction · 0.92
NewTestAuthenticatorFunction · 0.85
NewUserMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected