Scenario 11 Initiate user and role Grant role channel and role, revoke role and role channel, re-grant role, re-grant channel - Changes Request - Seq 80 - Has channel 1 access, no history Revoke channel, revoke role - Changes Request - Seq 110 - Doesn't have channel 1 access, adds role and
(t *testing.T)
| 2400 | // Revoke channel, revoke role |
| 2401 | // - Changes Request - Seq 110 - Doesn't have channel 1 access, adds role and channel history |
| 2402 | func TestRevocationScenario11(t *testing.T) { |
| 2403 | ctx := base.TestCtx(t) |
| 2404 | testBucket := base.GetTestBucket(t) |
| 2405 | defer testBucket.Close(ctx) |
| 2406 | |
| 2407 | dataStore := testBucket.GetSingleDataStore() |
| 2408 | |
| 2409 | testMockComputer := mockComputerV2{ |
| 2410 | roles: map[string]ch.TimedSet{}, |
| 2411 | channels: map[string]ch.TimedSet{}, |
| 2412 | roleChannels: map[string]ch.TimedSet{}, |
| 2413 | } |
| 2414 | |
| 2415 | auth := NewTestAuthenticator(t, dataStore, &testMockComputer, DefaultAuthenticatorOptions(base.TestCtx(t))) |
| 2416 | initializeScenario(t, auth) |
| 2417 | |
| 2418 | testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 5) |
| 2419 | testMockComputer.addRole(t, auth, "alice", "foo", 20) |
| 2420 | |
| 2421 | testMockComputer.removeRole(t, auth, "alice", "foo", 45) |
| 2422 | testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 55) |
| 2423 | |
| 2424 | testMockComputer.addRole(t, auth, "alice", "foo", 65) |
| 2425 | testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 75) |
| 2426 | |
| 2427 | // Get Principals / Rebuild Seq 80 |
| 2428 | aliceUserPrincipal, fooPrincipal := getPrincipals(t, auth) |
| 2429 | |
| 2430 | // Ensure user can see ch1 (via role) |
| 2431 | // Verify history |
| 2432 | requireCanSeeChannels(t, aliceUserPrincipal, "ch1") |
| 2433 | assert.Len(t, aliceUserPrincipal.RoleHistory(), 0) |
| 2434 | assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0) |
| 2435 | assert.Len(t, fooPrincipal.ChannelHistory(), 0) |
| 2436 | revokedChannelsCombined, err := aliceUserPrincipal.revokedChannels(5, 0, 0) |
| 2437 | require.NoError(t, err) |
| 2438 | assert.Len(t, revokedChannelsCombined, 0) |
| 2439 | |
| 2440 | testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 85) |
| 2441 | testMockComputer.removeRole(t, auth, "alice", "foo", 95) |
| 2442 | |
| 2443 | // Rebuild seq 110 |
| 2444 | aliceUserPrincipal, fooPrincipal = getPrincipals(t, auth) |
| 2445 | |
| 2446 | // Ensure user cannot see ch1 (via role) |
| 2447 | // Verify history |
| 2448 | requireCannotSeeChannels(t, aliceUserPrincipal, "ch1") |
| 2449 | |
| 2450 | userRoleHistory, ok := aliceUserPrincipal.RoleHistory()["foo"] |
| 2451 | require.True(t, ok) |
| 2452 | assert.Equal(t, GrantHistorySequencePair{StartSeq: 65, EndSeq: 95}, userRoleHistory.Entries[0]) |
| 2453 | |
| 2454 | channelHistory, ok := fooPrincipal.ChannelHistory()["ch1"] |
| 2455 | require.True(t, ok) |
| 2456 | assert.Equal(t, GrantHistorySequencePair{StartSeq: 75, EndSeq: 85}, channelHistory.Entries[0]) |
| 2457 | |
| 2458 | assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0) |
| 2459 |
nothing calls this directly
no test coverage detected