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

Function TestCheckRoleArray

channels/channelmapper_test.go:349–367  ·  view source on GitHub ↗

Test the userCtx role parameter with a list

(t *testing.T)

Source from the content-addressed store, hash-verified

347
348// Test the userCtx role parameter with a list
349func TestCheckRoleArray(t *testing.T) {
350 ctx := base.TestCtx(t)
351 mapper := NewChannelMapper(ctx, `function(doc, oldDoc) {
352 requireRole(doc.roles);
353 }`, 0)
354 var sally = map[string]interface{}{"name": "sally", "roles": map[string]int{"girl": 1, "5yo": 1}}
355 res, err := mapper.MapToChannelsAndAccess(ctx, parse(t, `{"roles": ["kid","girl"]}`), `{}`, emptyMetaMap(), sally)
356 assert.NoError(t, err, "MapToChannelsAndAccess failed")
357 assert.Equal(t, nil, res.Rejection)
358
359 var linus = map[string]interface{}{"name": "linus", "roles": map[string]int{"boy": 1, "musician": 1}}
360 res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"roles": ["girl"]}`), `{}`, emptyMetaMap(), linus)
361 assert.NoError(t, err, "MapToChannelsAndAccess failed")
362 assert.Equal(t, base.HTTPErrorf(403, base.SyncFnErrorMissingRole), res.Rejection)
363
364 res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"roles": ["girl"]}`), `{}`, emptyMetaMap(), nil)
365 assert.NoError(t, err, "MapToChannelsAndAccess failed")
366 assert.Equal(t, nil, res.Rejection)
367}
368
369// Test the userCtx.channels parameter
370func TestCheckAccess(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