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

Function TestCheckUser

channels/channelmapper_test.go:286–304  ·  view source on GitHub ↗

Test the userCtx name parameter

(t *testing.T)

Source from the content-addressed store, hash-verified

284
285// Test the userCtx name parameter
286func TestCheckUser(t *testing.T) {
287 ctx := base.TestCtx(t)
288 mapper := NewChannelMapper(ctx, `function(doc, oldDoc) {
289 requireUser(doc.owner);
290 }`, 0)
291 var sally = map[string]interface{}{"name": "sally", "channels": []string{}}
292 res, err := mapper.MapToChannelsAndAccess(ctx, parse(t, `{"owner": "sally"}`), `{}`, emptyMetaMap(), sally)
293 assert.NoError(t, err, "MapToChannelsAndAccess failed")
294 assert.Equal(t, nil, res.Rejection)
295
296 var linus = map[string]interface{}{"name": "linus", "channels": []string{}}
297 res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"owner": "sally"}`), `{}`, emptyMetaMap(), linus)
298 assert.NoError(t, err, "MapToChannelsAndAccess failed")
299 assert.Equal(t, base.HTTPErrorf(403, base.SyncFnErrorWrongUser), res.Rejection)
300
301 res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"owner": "sally"}`), `{}`, emptyMetaMap(), nil)
302 assert.NoError(t, err, "MapToChannelsAndAccess failed")
303 assert.Equal(t, nil, res.Rejection)
304}
305
306// Test the userCtx name parameter with a list
307func TestCheckUserArray(t *testing.T) {

Callers

nothing calls this directly

Calls 7

TestCtxFunction · 0.92
HTTPErrorfFunction · 0.92
NewChannelMapperFunction · 0.85
parseFunction · 0.85
emptyMetaMapFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected