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

Function TestRevocationScenario1

auth/auth_test.go:1534–1620  ·  view source on GitHub ↗

======================================================================================================= The below 'TestRevocationScenario' tests refer to scenarios in the following Google Sheet https://docs.google.com/spreadsheets/d/1pTLyJqrSdde-dAxDfMkKGXi0ttWF4GVCOBFJg7hRY0U/edit?usp=sharing =====

(t *testing.T)

Source from the content-addressed store, hash-verified

1532// Role revoke, role channel revoke
1533// - Changes Request - Seq 110 - Doesn't have channel access, history added for both role and channel
1534func TestRevocationScenario1(t *testing.T) {
1535 ctx := base.TestCtx(t)
1536 testBucket := base.GetTestBucket(t)
1537 defer testBucket.Close(ctx)
1538
1539 dataStore := testBucket.GetSingleDataStore()
1540
1541 testMockComputer := mockComputerV2{
1542 roles: map[string]ch.TimedSet{},
1543 channels: map[string]ch.TimedSet{},
1544 roleChannels: map[string]ch.TimedSet{},
1545 }
1546
1547 auth := NewTestAuthenticator(t, dataStore, &testMockComputer, DefaultAuthenticatorOptions(base.TestCtx(t)))
1548 initializeScenario(t, auth)
1549
1550 testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 5)
1551 testMockComputer.addRole(t, auth, "alice", "foo", 20)
1552
1553 // Get Principals / Rebuild Seq 25
1554 aliceUserPrincipal, fooPrincipal := getPrincipals(t, auth)
1555
1556 // Ensure user can see ch1 (via role)
1557 // Verify history
1558 assert.ElementsMatch(t, []string{"!", "ch1"}, fooPrincipal.Channels().AllKeys())
1559 requireCanSeeChannels(t, aliceUserPrincipal, "ch1")
1560 assert.Len(t, aliceUserPrincipal.RoleHistory(), 0)
1561 assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0)
1562 assert.Len(t, fooPrincipal.ChannelHistory(), 0)
1563 revokedChannelsCombined, err := aliceUserPrincipal.revokedChannels(5, 0, 0)
1564 require.NoError(t, err)
1565 assert.Len(t, revokedChannelsCombined, 0)
1566
1567 // Get Principals / Rebuild Seq 40
1568 aliceUserPrincipal, fooPrincipal = getPrincipals(t, auth)
1569
1570 // Ensure user can see ch1 (via role)
1571 // Verify history
1572 assert.ElementsMatch(t, []string{"!", "ch1"}, fooPrincipal.Channels().AllKeys())
1573 requireCanSeeChannels(t, aliceUserPrincipal, "ch1")
1574 assert.Len(t, aliceUserPrincipal.RoleHistory(), 0)
1575 assert.Len(t, aliceUserPrincipal.ChannelHistory(), 0)
1576 assert.Len(t, fooPrincipal.ChannelHistory(), 0)
1577 revokedChannelsCombined, err = aliceUserPrincipal.revokedChannels(25, 0, 0)
1578 require.NoError(t, err)
1579 assert.Len(t, revokedChannelsCombined, 0)
1580
1581 testMockComputer.removeRole(t, auth, "alice", "foo", 45)
1582 testMockComputer.removeRoleChannel(t, auth, "foo", "ch1", 55)
1583
1584 testMockComputer.addRole(t, auth, "alice", "foo", 65)
1585 testMockComputer.addRoleChannels(t, auth, "foo", "ch1", 75)
1586
1587 // Get Principals / Rebuild Seq 80
1588 aliceUserPrincipal, fooPrincipal = getPrincipals(t, auth)
1589
1590 // Ensure user can see ch1 (via role)
1591 // Verify history

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