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

Function TestRevocationScenario7

auth/auth_test.go:2125–2201  ·  view source on GitHub ↗

Scenario 7 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, re-grant channel, re-revoke channel, re-revoke role - Changes Request - Seq 100 - Doesn't have channel 1 access, hist

(t *testing.T)

Source from the content-addressed store, hash-verified

2123// No Change
2124// - Changes Request - Seq 110 - Doesn't have channel access, history retained
2125func TestRevocationScenario7(t *testing.T) {
2126 ctx := base.TestCtx(t)
2127 testBucket := base.GetTestBucket(t)
2128 defer testBucket.Close(ctx)
2129
2130 dataStore := testBucket.GetSingleDataStore()
2131
2132 testMockComputer := mockComputerV2{
2133 roles: map[string]ch.TimedSet{},
2134 channels: map[string]ch.TimedSet{},
2135 roleChannels: map[string]ch.TimedSet{},
2136 }
2137
2138 auth := NewTestAuthenticator(t, dataStore, &testMockComputer, DefaultAuthenticatorOptions(base.TestCtx(t)))
2139 initializeScenario(t, auth)
2140
2141 testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 5)
2142 testMockComputer.addRole(t, auth, "alice", "foo", 20)
2143
2144 // Get Principals / Rebuild Seq 25
2145 aliceUserPrincipal, fooPrincipal := getPrincipals(t, auth)
2146
2147 // Ensure user can see ch1 (via role)
2148 // Verify history
2149 assert.ElementsMatch(t, []string{"!", "ch1"}, fooPrincipal.Channels().AllKeys())
2150 requireCanSeeChannels(t, aliceUserPrincipal, "ch1")
2151 assert.Len(t, aliceUserPrincipal.RoleHistory(), 0)
2152 assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0)
2153 assert.Len(t, fooPrincipal.ChannelHistory(), 0)
2154 revokedChannelsCombined, err := aliceUserPrincipal.revokedChannels(5, 0, 0)
2155 require.NoError(t, err)
2156 assert.Len(t, revokedChannelsCombined, 0)
2157
2158 testMockComputer.removeRole(t, auth, "alice", "foo", 45)
2159 testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 55)
2160
2161 testMockComputer.addRole(t, auth, "alice", "foo", 65)
2162 testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 75)
2163
2164 testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 85)
2165 testMockComputer.removeRole(t, auth, "alice", "foo", 95)
2166
2167 // Get Principals / Rebuild Seq 100
2168 aliceUserPrincipal, fooPrincipal = getPrincipals(t, auth)
2169
2170 // Ensure user cannot see ch1 (via role)
2171 // Verify history
2172 requireCannotSeeChannels(t, aliceUserPrincipal, "ch1")
2173 userRoleHistory, ok := aliceUserPrincipal.RoleHistory()["foo"]
2174 require.True(t, ok)
2175 assert.Equal(t, GrantHistorySequencePair{StartSeq: 20, EndSeq: 45}, userRoleHistory.Entries[0])
2176
2177 channelHistory, ok := fooPrincipal.ChannelHistory()["ch1"]
2178 require.True(t, ok)
2179 assert.Equal(t, GrantHistorySequencePair{StartSeq: 5, EndSeq: 55}, channelHistory.Entries[0])
2180
2181 assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0)
2182

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