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

Function TestRevocationScenario4

auth/auth_test.go:1852–1942  ·  view source on GitHub ↗

Scenario 4 Initiate user and role Grant role channel and role - Changes Request - Seq 25 - Has channel 1 access, no history Revoke role, revoke role channel, re-grant role - Changes Request - Seq 70 - Doesn't have channel access, history added for role channel Grant role - Changes Requ

(t *testing.T)

Source from the content-addressed store, hash-verified

1850// Role revoke, role channel revoke
1851// - Changes Request - Seq 110 - Doesn't have channel access, history added for both role and channel
1852func TestRevocationScenario4(t *testing.T) {
1853 ctx := base.TestCtx(t)
1854 testBucket := base.GetTestBucket(t)
1855 defer testBucket.Close(ctx)
1856
1857 dataStore := testBucket.GetSingleDataStore()
1858
1859 testMockComputer := mockComputerV2{
1860 roles: map[string]ch.TimedSet{},
1861 channels: map[string]ch.TimedSet{},
1862 roleChannels: map[string]ch.TimedSet{},
1863 }
1864
1865 auth := NewTestAuthenticator(t, dataStore, &testMockComputer, DefaultAuthenticatorOptions(base.TestCtx(t)))
1866 initializeScenario(t, auth)
1867
1868 testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 5)
1869 testMockComputer.addRole(t, auth, "alice", "foo", 20)
1870
1871 // Get Principals / Rebuild Seq 25
1872 aliceUserPrincipal, fooPrincipal := getPrincipals(t, auth)
1873
1874 // Ensure user can see ch1 (via role)
1875 // Verify history
1876 assert.ElementsMatch(t, []string{"!", "ch1"}, fooPrincipal.Channels().AllKeys())
1877 requireCanSeeChannels(t, aliceUserPrincipal, "ch1")
1878 assert.Len(t, aliceUserPrincipal.RoleHistory(), 0)
1879 assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0)
1880 assert.Len(t, fooPrincipal.ChannelHistory(), 0)
1881 revokedChannelsCombined, err := aliceUserPrincipal.revokedChannels(5, 0, 0)
1882 require.NoError(t, err)
1883 assert.Len(t, revokedChannelsCombined, 0)
1884
1885 testMockComputer.removeRole(t, auth, "alice", "foo", 45)
1886 testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 55)
1887
1888 testMockComputer.addRole(t, auth, "alice", "foo", 65)
1889
1890 // Get Principals / Rebuild Seq 70
1891 aliceUserPrincipal, fooPrincipal = getPrincipals(t, auth)
1892
1893 // Ensure user cannot see ch1 (via role)
1894 // Verify history
1895 requireCannotSeeChannels(t, aliceUserPrincipal, "ch1")
1896 channelHistory, ok := fooPrincipal.ChannelHistory()["ch1"]
1897 require.True(t, ok)
1898 assert.Equal(t, GrantHistorySequencePair{StartSeq: 5, EndSeq: 55}, channelHistory.Entries[0])
1899 assert.Len(t, aliceUserPrincipal.RoleHistory(), 0)
1900 assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0)
1901 revokedChannelsCombined, err = aliceUserPrincipal.revokedChannels(25, 0, 0)
1902 require.NoError(t, err)
1903 require.Contains(t, revokedChannelsCombined, "ch1")
1904 assert.Equal(t, uint64(55), revokedChannelsCombined["ch1"])
1905
1906 testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 75)
1907
1908 // Get Principals / Rebuild Seq 80
1909 aliceUserPrincipal, fooPrincipal = getPrincipals(t, auth)

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
requireCanSeeChannelsFunction · 0.85
requireCannotSeeChannelsFunction · 0.85

Tested by

no test coverage detected