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

Function TestRevocationScenario9

auth/auth_test.go:2275–2328  ·  view source on GitHub ↗

Scenario 9 Initiate user and role Grant role channel and role, revoke role and role channel - Changes Request - Seq 60 - Doesn't have channel 1 access, no history Re-grant role, re-grant channel, re-revoke channel, re-revoke role - Changes Request - Seq 110 - Doesn't have channel 1 access,

(t *testing.T)

Source from the content-addressed store, hash-verified

2273// Re-grant role, re-grant channel, re-revoke channel, re-revoke role
2274// - Changes Request - Seq 110 - Doesn't have channel 1 access, no history
2275func TestRevocationScenario9(t *testing.T) {
2276 ctx := base.TestCtx(t)
2277 testBucket := base.GetTestBucket(t)
2278 defer testBucket.Close(ctx)
2279
2280 dataStore := testBucket.GetSingleDataStore()
2281
2282 testMockComputer := mockComputerV2{
2283 roles: map[string]ch.TimedSet{},
2284 channels: map[string]ch.TimedSet{},
2285 roleChannels: map[string]ch.TimedSet{},
2286 }
2287
2288 auth := NewTestAuthenticator(t, dataStore, &testMockComputer, DefaultAuthenticatorOptions(base.TestCtx(t)))
2289 initializeScenario(t, auth)
2290
2291 testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 5)
2292 testMockComputer.addRole(t, auth, "alice", "foo", 20)
2293
2294 testMockComputer.removeRole(t, auth, "alice", "foo", 45)
2295 testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 55)
2296
2297 // Get Principals / Rebuild Seq 60
2298 aliceUserPrincipal, fooPrincipal := getPrincipals(t, auth)
2299
2300 // Ensure user cannot see ch1 (via role)
2301 // Verify history
2302 requireCannotSeeChannels(t, aliceUserPrincipal, "ch1")
2303 assert.Len(t, aliceUserPrincipal.RoleHistory(), 0)
2304 assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0)
2305 assert.Len(t, fooPrincipal.ChannelHistory(), 0)
2306 revokedChannelsCombined, err := aliceUserPrincipal.revokedChannels(5, 0, 0)
2307 require.NoError(t, err)
2308 assert.Len(t, revokedChannelsCombined, 0)
2309
2310 testMockComputer.addRole(t, auth, "alice", "foo", 65)
2311 testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 75)
2312
2313 testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 85)
2314 testMockComputer.removeRole(t, auth, "alice", "foo", 95)
2315
2316 // Rebuild seq 110
2317 aliceUserPrincipal, fooPrincipal = getPrincipals(t, auth)
2318
2319 // Ensure user cannot see ch1 (via role)
2320 // Verify history
2321 requireCannotSeeChannels(t, aliceUserPrincipal, "ch1")
2322 assert.Len(t, aliceUserPrincipal.RoleHistory(), 0)
2323 assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0)
2324 assert.Len(t, fooPrincipal.ChannelHistory(), 0)
2325 revokedChannelsCombined, err = aliceUserPrincipal.revokedChannels(60, 0, 0)
2326 require.NoError(t, err)
2327 assert.Len(t, revokedChannelsCombined, 0)
2328}
2329
2330// Scenario 10
2331//

Callers

nothing calls this directly

Calls 15

addRoleChannelsMethod · 0.95
addRoleMethod · 0.95
removeRoleMethod · 0.95
removeRoleChannelMethod · 0.95
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
NewTestAuthenticatorFunction · 0.85
initializeScenarioFunction · 0.85
getPrincipalsFunction · 0.85
requireCannotSeeChannelsFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected