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

Function TestCheckUserArray

channels/channelmapper_test.go:307–325  ·  view source on GitHub ↗

Test the userCtx name parameter with a list

(t *testing.T)

Source from the content-addressed store, hash-verified

305
306// Test the userCtx name parameter with a list
307func TestCheckUserArray(t *testing.T) {
308 ctx := base.TestCtx(t)
309 mapper := NewChannelMapper(ctx, `function(doc, oldDoc) {
310 requireUser(doc.owners);
311 }`, 0)
312 var sally = map[string]interface{}{"name": "sally", "channels": []string{}}
313 res, err := mapper.MapToChannelsAndAccess(ctx, parse(t, `{"owners": ["sally", "joe"]}`), `{}`, emptyMetaMap(), sally)
314 assert.NoError(t, err, "MapToChannelsAndAccess failed")
315 assert.Equal(t, nil, res.Rejection)
316
317 var linus = map[string]interface{}{"name": "linus", "channels": []string{}}
318 res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"owners": ["sally", "joe"]}`), `{}`, emptyMetaMap(), linus)
319 assert.NoError(t, err, "MapToChannelsAndAccess failed")
320 assert.Equal(t, base.HTTPErrorf(403, base.SyncFnErrorWrongUser), res.Rejection)
321
322 res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"owners": ["sally"]}`), `{}`, emptyMetaMap(), nil)
323 assert.NoError(t, err, "MapToChannelsAndAccess failed")
324 assert.Equal(t, nil, res.Rejection)
325}
326
327// Test the userCtx role parameter
328func TestCheckRole(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