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

Function TestDeletedRoleChanHistory

rest/user_api_test.go:1585–1636  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1583}
1584
1585func TestDeletedRoleChanHistory(t *testing.T) {
1586 tests := []struct {
1587 defaultCollection bool
1588 }{
1589 {defaultCollection: true},
1590 {defaultCollection: false},
1591 }
1592
1593 for _, test := range tests {
1594 t.Run(fmt.Sprintf("defaultCollection:%v", test.defaultCollection), func(t *testing.T) {
1595 ctx := base.TestCtx(t)
1596
1597 var rt *RestTester
1598 if test.defaultCollection {
1599 rt = NewRestTesterDefaultCollection(t, nil)
1600 } else {
1601 rt = NewRestTesterMultipleCollections(t, nil, 1)
1602 }
1603
1604 defer rt.Close()
1605
1606 ds := rt.GetSingleDataStore()
1607 const roleName = "role"
1608 response := rt.SendAdminRequest("PUT", "/db/_role/role", GetUserPayload(t, "role", "letmein", "", ds, []string{"channel"}, nil))
1609 RequireStatus(t, response, 201)
1610
1611 a := rt.ServerContext().Database(ctx, "db").Authenticator(ctx)
1612
1613 // Get role - ensure accessible
1614 role, err := a.GetRole(roleName)
1615 assert.NoError(t, err)
1616 assert.NotNil(t, role)
1617 channels := role.CollectionChannels(ds.ScopeName(), ds.CollectionName())
1618 assert.Len(t, channels, 2)
1619 assert.True(t, channels.Contains("channel"))
1620
1621 // Delete role
1622 err = a.DeleteRole(role, false, 2)
1623 assert.NoError(t, err)
1624
1625 // get deleted role and assert channel is in channel history
1626 role, err = a.GetRoleIncDeleted(roleName)
1627 assert.NoError(t, err)
1628 channelHistory := role.CollectionChannelHistory(ds.ScopeName(), ds.CollectionName())
1629 assert.Len(t, channelHistory, 2)
1630 _, ok := channelHistory["channel"]
1631 require.True(t, ok)
1632 assert.Truef(t, ok, "Channel history should contain 'channel'")
1633 })
1634 }
1635
1636}
1637
1638// TestDisabledUser ensures that a disabled (non-guest) user cannot authenticate to make requests.
1639func TestDisabledUser(t *testing.T) {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
GetSingleDataStoreMethod · 0.95
SendAdminRequestMethod · 0.95
ServerContextMethod · 0.95
TestCtxFunction · 0.92
GetUserPayloadFunction · 0.85
RequireStatusFunction · 0.85
GetRoleMethod · 0.80
GetRoleIncDeletedMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected