Test the userCtx role parameter with a list
(t *testing.T)
| 347 | |
| 348 | // Test the userCtx role parameter with a list |
| 349 | func 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 |
| 370 | func TestCheckAccess(t *testing.T) { |
nothing calls this directly
no test coverage detected