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

Function TestCheckAccessArray

channels/channelmapper_test.go:391–409  ·  view source on GitHub ↗

Test the userCtx.channels parameter with a list

(t *testing.T)

Source from the content-addressed store, hash-verified

389
390// Test the userCtx.channels parameter with a list
391func TestCheckAccessArray(t *testing.T) {
392 ctx := base.TestCtx(t)
393 mapper := NewChannelMapper(ctx, `function(doc, oldDoc) {
394 requireAccess(doc.channels)
395 }`, 0)
396 var sally = map[string]interface{}{"name": "sally", "roles": []string{"girl", "5yo"}, "channels": []string{"party", "school"}}
397 res, err := mapper.MapToChannelsAndAccess(ctx, parse(t, `{"channels": ["swim","party"]}`), `{}`, emptyMetaMap(), sally)
398 assert.NoError(t, err, "MapToChannelsAndAccess failed")
399 assert.Equal(t, nil, res.Rejection)
400
401 var linus = map[string]interface{}{"name": "linus", "roles": []string{"boy", "musician"}, "channels": []string{"party", "school"}}
402 res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"channels": ["work"]}`), `{}`, emptyMetaMap(), linus)
403 assert.NoError(t, err, "MapToChannelsAndAccess failed")
404 assert.Equal(t, base.HTTPErrorf(403, base.SyncFnErrorMissingChannelAccess), res.Rejection)
405
406 res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"channels": ["magic"]}`), `{}`, emptyMetaMap(), nil)
407 assert.NoError(t, err, "MapToChannelsAndAccess failed")
408 assert.Equal(t, nil, res.Rejection)
409}
410
411// Test changing the function
412func TestSetFunction(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