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

Function TestReloadUser

rest/blip_api_crud_test.go:1349–1415  ·  view source on GitHub ↗

Reproduce issue where ReloadUser was not being called, and so it was using a stale channel access grant for the user. Reproduces https://github.com/couchbase/sync_gateway/issues/2717

(t *testing.T)

Source from the content-addressed store, hash-verified

1347// using a stale channel access grant for the user.
1348// Reproduces https://github.com/couchbase/sync_gateway/issues/2717
1349func TestReloadUser(t *testing.T) {
1350
1351 base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP, base.KeySync, base.KeySyncMsg)
1352
1353 syncFn := `
1354 function(doc) {
1355 if (doc._id == "access1") {
1356 // if its an access grant doc, grant access
1357 access(doc.accessUser, doc.accessChannel);
1358 } else {
1359 // otherwise if its a normal access doc, require access then add to channels
1360 requireAccess("PBS");
1361 channel(doc.channels);
1362 }
1363 }
1364 `
1365
1366 // Setup
1367 rtConfig := RestTesterConfig{
1368 SyncFn: syncFn,
1369 }
1370 rt := NewRestTester(t, &rtConfig)
1371 defer rt.Close()
1372 const username = "user1"
1373 rt.CreateUser(username, nil)
1374 ctx := rt.Context()
1375 bt := NewBlipTesterFromSpecWithRT(rt, &BlipTesterSpec{
1376 connectingUsername: username,
1377 })
1378 defer bt.Close()
1379
1380 // Set up a ChangeWaiter for this test, to block until the user change notification happens
1381 dbc := rt.GetDatabase()
1382 user1, err := dbc.Authenticator(ctx).GetUser(username)
1383 require.NoError(t, err)
1384
1385 userDb, err := db.GetDatabase(dbc, user1)
1386 require.NoError(t, err)
1387
1388 userWaiter := userDb.NewUserWaiter()
1389
1390 // Put document that triggers access grant for user to channel PBS
1391 response := rt.SendAdminRequest("PUT", "/{{.keyspace}}/access1", `{"accessUser":"user1", "accessChannel":["PBS"]}`)
1392 RequireStatus(t, response, 201)
1393
1394 // Wait for notification
1395 require.True(t, db.WaitForUserWaiterChange(userWaiter))
1396
1397 // Add a doc in the PBS channel
1398 _, _, addRevResponse, err := bt.SendRev(
1399 "foo",
1400 "1-abc",
1401 []byte(`{"key": "val", "channels": ["PBS"]}`),
1402 blip.Properties{},
1403 )
1404 assert.NoError(t, err)
1405
1406 // Make assertions on response to make sure the change was accepted

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
CreateUserMethod · 0.95
ContextMethod · 0.95
GetDatabaseMethod · 0.95
SendAdminRequestMethod · 0.95
SetUpTestLoggingFunction · 0.92
GetDatabaseFunction · 0.92
WaitForUserWaiterChangeFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
GetUserMethod · 0.80

Tested by

no test coverage detected