Scenario 3 Initiate user and role Grant role channel and role - Changes Request - Seq 25 - Has channel 1 access, no history Revoke role, revoke role channel - Changes Request - Seq 60 - Doesn't have channel access, history added for both role and channel Grant role channel and role - C
(t *testing.T)
| 1736 | // Role revoke, role channel revoke |
| 1737 | // - Changes Request - Seq 110 - Doesn't have channel access, history added for both role and channel |
| 1738 | func TestRevocationScenario3(t *testing.T) { |
| 1739 | ctx := base.TestCtx(t) |
| 1740 | testBucket := base.GetTestBucket(t) |
| 1741 | defer testBucket.Close(ctx) |
| 1742 | |
| 1743 | dataStore := testBucket.GetSingleDataStore() |
| 1744 | |
| 1745 | testMockComputer := mockComputerV2{ |
| 1746 | roles: map[string]ch.TimedSet{}, |
| 1747 | channels: map[string]ch.TimedSet{}, |
| 1748 | roleChannels: map[string]ch.TimedSet{}, |
| 1749 | } |
| 1750 | |
| 1751 | auth := NewTestAuthenticator(t, dataStore, &testMockComputer, DefaultAuthenticatorOptions(base.TestCtx(t))) |
| 1752 | initializeScenario(t, auth) |
| 1753 | |
| 1754 | testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 5) |
| 1755 | testMockComputer.addRole(t, auth, "alice", "foo", 20) |
| 1756 | |
| 1757 | // Get Principals / Rebuild Seq 25 |
| 1758 | aliceUserPrincipal, fooPrincipal := getPrincipals(t, auth) |
| 1759 | |
| 1760 | // Ensure user can see ch1 (via role) |
| 1761 | // Verify history |
| 1762 | assert.ElementsMatch(t, []string{"!", "ch1"}, fooPrincipal.Channels().AllKeys()) |
| 1763 | requireCanSeeChannels(t, aliceUserPrincipal, "ch1") |
| 1764 | assert.Len(t, aliceUserPrincipal.RoleHistory(), 0) |
| 1765 | assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0) |
| 1766 | assert.Len(t, fooPrincipal.ChannelHistory(), 0) |
| 1767 | revokedChannelsCombined, err := aliceUserPrincipal.revokedChannels(55, 0, 0) |
| 1768 | require.NoError(t, err) |
| 1769 | assert.Len(t, revokedChannelsCombined, 0) |
| 1770 | |
| 1771 | testMockComputer.removeRole(t, auth, "alice", "foo", 45) |
| 1772 | testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 55) |
| 1773 | |
| 1774 | // Rebuild seq 60 |
| 1775 | aliceUserPrincipal, fooPrincipal = getPrincipals(t, auth) |
| 1776 | |
| 1777 | // Ensure user cannot see ch1 (via role) |
| 1778 | // Verify history |
| 1779 | requireCannotSeeChannels(t, aliceUserPrincipal, "ch1") |
| 1780 | userRoleHistory, ok := aliceUserPrincipal.RoleHistory()["foo"] |
| 1781 | require.True(t, ok) |
| 1782 | assert.Equal(t, GrantHistorySequencePair{StartSeq: 20, EndSeq: 45}, userRoleHistory.Entries[0]) |
| 1783 | |
| 1784 | channelHistory, ok := fooPrincipal.ChannelHistory()["ch1"] |
| 1785 | require.True(t, ok) |
| 1786 | assert.Equal(t, GrantHistorySequencePair{StartSeq: 5, EndSeq: 55}, channelHistory.Entries[0]) |
| 1787 | |
| 1788 | assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0) |
| 1789 | |
| 1790 | revokedChannelsCombined, err = aliceUserPrincipal.revokedChannels(25, 0, 0) |
| 1791 | require.NoError(t, err) |
| 1792 | require.Contains(t, revokedChannelsCombined, "ch1") |
| 1793 | assert.Equal(t, uint64(45), revokedChannelsCombined["ch1"]) |
| 1794 | |
| 1795 | testMockComputer.addRole(t, auth, "alice", "foo", 65) |
nothing calls this directly
no test coverage detected