Skip to content

Commit

Permalink
Test and lint fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
tcsc committed Oct 24, 2024
1 parent 0abcfee commit d3e981c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 76 deletions.
135 changes: 71 additions & 64 deletions lib/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ func TestCompletenessInit(t *testing.T) {
AutoUpdateService: p.autoUpdateService,
ProvisioningStates: p.provisioningStates,
MaxRetryPeriod: 200 * time.Millisecond,
IdentityCenter: p.identityCenter,
EventsC: p.eventsC,
}))
require.NoError(t, err)
Expand Down Expand Up @@ -938,6 +939,7 @@ func TestCompletenessReset(t *testing.T) {
StaticHostUsers: p.staticHostUsers,
AutoUpdateService: p.autoUpdateService,
ProvisioningStates: p.provisioningStates,
IdentityCenter: p.identityCenter,
MaxRetryPeriod: 200 * time.Millisecond,
EventsC: p.eventsC,
}))
Expand Down Expand Up @@ -1146,6 +1148,7 @@ func TestListResources_NodesTTLVariant(t *testing.T) {
StaticHostUsers: p.staticHostUsers,
AutoUpdateService: p.autoUpdateService,
ProvisioningStates: p.provisioningStates,
IdentityCenter: p.identityCenter,
MaxRetryPeriod: 200 * time.Millisecond,
EventsC: p.eventsC,
neverOK: true, // ensure reads are never healthy
Expand Down Expand Up @@ -1239,6 +1242,7 @@ func initStrategy(t *testing.T) {
StaticHostUsers: p.staticHostUsers,
AutoUpdateService: p.autoUpdateService,
ProvisioningStates: p.provisioningStates,
IdentityCenter: p.identityCenter,
MaxRetryPeriod: 200 * time.Millisecond,
EventsC: p.eventsC,
}))
Expand Down Expand Up @@ -3399,70 +3403,73 @@ func TestCacheWatchKindExistsInEvents(t *testing.T) {
}

events := map[string]types.Resource{
types.KindCertAuthority: &types.CertAuthorityV2{},
types.KindClusterName: &types.ClusterNameV2{},
types.KindClusterAuditConfig: types.DefaultClusterAuditConfig(),
types.KindClusterNetworkingConfig: types.DefaultClusterNetworkingConfig(),
types.KindClusterAuthPreference: types.DefaultAuthPreference(),
types.KindSessionRecordingConfig: types.DefaultSessionRecordingConfig(),
types.KindUIConfig: &types.UIConfigV1{},
types.KindStaticTokens: &types.StaticTokensV2{},
types.KindToken: &types.ProvisionTokenV2{},
types.KindUser: &types.UserV2{},
types.KindRole: &types.RoleV6{Version: types.V4},
types.KindNamespace: &types.Namespace{},
types.KindNode: &types.ServerV2{},
types.KindProxy: &types.ServerV2{},
types.KindAuthServer: &types.ServerV2{},
types.KindReverseTunnel: &types.ReverseTunnelV2{},
types.KindTunnelConnection: &types.TunnelConnectionV2{},
types.KindAccessRequest: &types.AccessRequestV3{},
types.KindAppServer: &types.AppServerV3{},
types.KindApp: &types.AppV3{},
types.KindWebSession: &types.WebSessionV2{SubKind: types.KindWebSession},
types.KindAppSession: &types.WebSessionV2{SubKind: types.KindAppSession},
types.KindSnowflakeSession: &types.WebSessionV2{SubKind: types.KindSnowflakeSession},
types.KindSAMLIdPSession: &types.WebSessionV2{SubKind: types.KindSAMLIdPServiceProvider},
types.KindWebToken: &types.WebTokenV3{},
types.KindRemoteCluster: &types.RemoteClusterV3{},
types.KindKubeServer: &types.KubernetesServerV3{},
types.KindDatabaseService: &types.DatabaseServiceV1{},
types.KindDatabaseServer: &types.DatabaseServerV3{},
types.KindDatabase: &types.DatabaseV3{},
types.KindNetworkRestrictions: &types.NetworkRestrictionsV4{},
types.KindLock: &types.LockV2{},
types.KindWindowsDesktopService: &types.WindowsDesktopServiceV3{},
types.KindWindowsDesktop: &types.WindowsDesktopV3{},
types.KindDynamicWindowsDesktop: &types.DynamicWindowsDesktopV1{},
types.KindInstaller: &types.InstallerV1{},
types.KindKubernetesCluster: &types.KubernetesClusterV3{},
types.KindSAMLIdPServiceProvider: &types.SAMLIdPServiceProviderV1{},
types.KindUserGroup: &types.UserGroupV1{},
types.KindOktaImportRule: &types.OktaImportRuleV1{},
types.KindOktaAssignment: &types.OktaAssignmentV1{},
types.KindIntegration: &types.IntegrationV1{},
types.KindDiscoveryConfig: newDiscoveryConfig(t, "discovery-config"),
types.KindHeadlessAuthentication: &types.HeadlessAuthentication{},
types.KindUserLoginState: newUserLoginState(t, "user-login-state"),
types.KindAuditQuery: newAuditQuery(t, "audit-query"),
types.KindSecurityReport: newSecurityReport(t, "security-report"),
types.KindSecurityReportState: newSecurityReport(t, "security-report-state"),
types.KindAccessList: newAccessList(t, "access-list", clock),
types.KindAccessListMember: newAccessListMember(t, "access-list", "member"),
types.KindAccessListReview: newAccessListReview(t, "access-list", "review"),
types.KindKubeWaitingContainer: newKubeWaitingContainer(t),
types.KindNotification: types.Resource153ToLegacy(newUserNotification(t, "test")),
types.KindGlobalNotification: types.Resource153ToLegacy(newGlobalNotification(t, "test")),
types.KindAccessMonitoringRule: types.Resource153ToLegacy(newAccessMonitoringRule(t)),
types.KindCrownJewel: types.Resource153ToLegacy(newCrownJewel(t, "test")),
types.KindDatabaseObject: types.Resource153ToLegacy(newDatabaseObject(t, "test")),
types.KindAccessGraphSettings: types.Resource153ToLegacy(newAccessGraphSettings(t)),
types.KindSPIFFEFederation: types.Resource153ToLegacy(newSPIFFEFederation("test")),
types.KindStaticHostUser: types.Resource153ToLegacy(newStaticHostUser(t, "test")),
types.KindAutoUpdateConfig: types.Resource153ToLegacy(newAutoUpdateConfig(t)),
types.KindAutoUpdateVersion: types.Resource153ToLegacy(newAutoUpdateVersion(t)),
types.KindUserTask: types.Resource153ToLegacy(newUserTasks(t)),
types.KindProvisioningPrincipalState: types.Resource153ToLegacy(newProvisioningPrincipalState("[email protected]")),
types.KindCertAuthority: &types.CertAuthorityV2{},
types.KindClusterName: &types.ClusterNameV2{},
types.KindClusterAuditConfig: types.DefaultClusterAuditConfig(),
types.KindClusterNetworkingConfig: types.DefaultClusterNetworkingConfig(),
types.KindClusterAuthPreference: types.DefaultAuthPreference(),
types.KindSessionRecordingConfig: types.DefaultSessionRecordingConfig(),
types.KindUIConfig: &types.UIConfigV1{},
types.KindStaticTokens: &types.StaticTokensV2{},
types.KindToken: &types.ProvisionTokenV2{},
types.KindUser: &types.UserV2{},
types.KindRole: &types.RoleV6{Version: types.V4},
types.KindNamespace: &types.Namespace{},
types.KindNode: &types.ServerV2{},
types.KindProxy: &types.ServerV2{},
types.KindAuthServer: &types.ServerV2{},
types.KindReverseTunnel: &types.ReverseTunnelV2{},
types.KindTunnelConnection: &types.TunnelConnectionV2{},
types.KindAccessRequest: &types.AccessRequestV3{},
types.KindAppServer: &types.AppServerV3{},
types.KindApp: &types.AppV3{},
types.KindWebSession: &types.WebSessionV2{SubKind: types.KindWebSession},
types.KindAppSession: &types.WebSessionV2{SubKind: types.KindAppSession},
types.KindSnowflakeSession: &types.WebSessionV2{SubKind: types.KindSnowflakeSession},
types.KindSAMLIdPSession: &types.WebSessionV2{SubKind: types.KindSAMLIdPServiceProvider},
types.KindWebToken: &types.WebTokenV3{},
types.KindRemoteCluster: &types.RemoteClusterV3{},
types.KindKubeServer: &types.KubernetesServerV3{},
types.KindDatabaseService: &types.DatabaseServiceV1{},
types.KindDatabaseServer: &types.DatabaseServerV3{},
types.KindDatabase: &types.DatabaseV3{},
types.KindNetworkRestrictions: &types.NetworkRestrictionsV4{},
types.KindLock: &types.LockV2{},
types.KindWindowsDesktopService: &types.WindowsDesktopServiceV3{},
types.KindWindowsDesktop: &types.WindowsDesktopV3{},
types.KindDynamicWindowsDesktop: &types.DynamicWindowsDesktopV1{},
types.KindInstaller: &types.InstallerV1{},
types.KindKubernetesCluster: &types.KubernetesClusterV3{},
types.KindSAMLIdPServiceProvider: &types.SAMLIdPServiceProviderV1{},
types.KindUserGroup: &types.UserGroupV1{},
types.KindOktaImportRule: &types.OktaImportRuleV1{},
types.KindOktaAssignment: &types.OktaAssignmentV1{},
types.KindIntegration: &types.IntegrationV1{},
types.KindDiscoveryConfig: newDiscoveryConfig(t, "discovery-config"),
types.KindHeadlessAuthentication: &types.HeadlessAuthentication{},
types.KindUserLoginState: newUserLoginState(t, "user-login-state"),
types.KindAuditQuery: newAuditQuery(t, "audit-query"),
types.KindSecurityReport: newSecurityReport(t, "security-report"),
types.KindSecurityReportState: newSecurityReport(t, "security-report-state"),
types.KindAccessList: newAccessList(t, "access-list", clock),
types.KindAccessListMember: newAccessListMember(t, "access-list", "member"),
types.KindAccessListReview: newAccessListReview(t, "access-list", "review"),
types.KindKubeWaitingContainer: newKubeWaitingContainer(t),
types.KindNotification: types.Resource153ToLegacy(newUserNotification(t, "test")),
types.KindGlobalNotification: types.Resource153ToLegacy(newGlobalNotification(t, "test")),
types.KindAccessMonitoringRule: types.Resource153ToLegacy(newAccessMonitoringRule(t)),
types.KindCrownJewel: types.Resource153ToLegacy(newCrownJewel(t, "test")),
types.KindDatabaseObject: types.Resource153ToLegacy(newDatabaseObject(t, "test")),
types.KindAccessGraphSettings: types.Resource153ToLegacy(newAccessGraphSettings(t)),
types.KindSPIFFEFederation: types.Resource153ToLegacy(newSPIFFEFederation("test")),
types.KindStaticHostUser: types.Resource153ToLegacy(newStaticHostUser(t, "test")),
types.KindAutoUpdateConfig: types.Resource153ToLegacy(newAutoUpdateConfig(t)),
types.KindAutoUpdateVersion: types.Resource153ToLegacy(newAutoUpdateVersion(t)),
types.KindUserTask: types.Resource153ToLegacy(newUserTasks(t)),
types.KindProvisioningPrincipalState: types.Resource153ToLegacy(newProvisioningPrincipalState("[email protected]")),
types.KindIdentityCenterAccount: types.Resource153ToLegacy(newIdentityCenterAccount("some_account")),
types.KindIdentityCenterAccountAssignment: types.Resource153ToLegacy(newIdentityCenterAccountAssignment("some_account_assignment")),
types.KindIdentityCenterPrincipalAssignment: types.Resource153ToLegacy(newIdentityCenterPrincipalAssignment("some_principal_assignment")),
}

for name, cfg := range cases {
Expand Down
18 changes: 15 additions & 3 deletions lib/cache/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,11 @@ func setupCollections(c *Cache, watches []types.WatchKind) (*cacheCollections, e
if c.IdentityCenter == nil {
return nil, trace.BadParameter("missing upstream IdentityCenter collection")
}
collections.identityCenterAccounts = &genericCollection[services.IdentityCenterAccount, identityCenterAccountGetter, identityCenterAccountExecutor]{
collections.identityCenterAccounts = &genericCollection[
services.IdentityCenterAccount,
identityCenterAccountGetter,
identityCenterAccountExecutor,
]{
cache: c,
watch: watch,
}
Expand All @@ -746,7 +750,11 @@ func setupCollections(c *Cache, watches []types.WatchKind) (*cacheCollections, e
if c.IdentityCenter == nil {
return nil, trace.BadParameter("missing parameter IdentityCenter")
}
collections.identityCenterPrincipalAssignments = &genericCollection[*identitycenterv1.PrincipalAssignment, identityCenterPrincipalAssignmentGetter, identityCenterPrincipalAssignmentExecutor]{
collections.identityCenterPrincipalAssignments = &genericCollection[
*identitycenterv1.PrincipalAssignment,
identityCenterPrincipalAssignmentGetter,
identityCenterPrincipalAssignmentExecutor,
]{
cache: c,
watch: watch,
}
Expand All @@ -756,7 +764,11 @@ func setupCollections(c *Cache, watches []types.WatchKind) (*cacheCollections, e
if c.IdentityCenter == nil {
return nil, trace.BadParameter("missing parameter IdentityCenter")
}
collections.identityCenterAccountAssignments = &genericCollection[services.IdentityCenterAccountAssignment, identityCenterAccountAssignmentGetter, identityCenterAccountAssignmentExecutor]{
collections.identityCenterAccountAssignments = &genericCollection[
services.IdentityCenterAccountAssignment,
identityCenterAccountAssignmentGetter,
identityCenterAccountAssignmentExecutor,
]{
cache: c,
watch: watch,
}
Expand Down
23 changes: 14 additions & 9 deletions lib/cache/identitycenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ func (identityCenterAccountExecutor) getAll(ctx context.Context, cache *Cache, l
var pageToken pagination.PageRequestToken
var resources []services.IdentityCenterAccount
for {
if cache == nil {
panic("Cache is nil")
}

if cache.ProvisioningStates == nil {
panic("Cache ProvisioningStates is nil")
}

resourcesPage, nextPage, err := cache.IdentityCenter.ListIdentityCenterAccounts(ctx, 0, &pageToken)
if err != nil {
return nil, trace.Wrap(err)
Expand Down Expand Up @@ -86,7 +78,10 @@ func (identityCenterAccountExecutor) isSingleton() bool {
return false
}

var _ executor[services.IdentityCenterAccount, identityCenterAccountGetter] = identityCenterAccountExecutor{}
var _ executor[
services.IdentityCenterAccount,
identityCenterAccountGetter,
] = identityCenterAccountExecutor{}

type identityCenterPrincipalAssignmentGetter interface {
GetPrincipalAssignment(context.Context, services.PrincipalAssignmentID) (*identitycenterv1.PrincipalAssignment, error)
Expand All @@ -95,6 +90,11 @@ type identityCenterPrincipalAssignmentGetter interface {

type identityCenterPrincipalAssignmentExecutor struct{}

var _ executor[
*identitycenterv1.PrincipalAssignment,
identityCenterPrincipalAssignmentGetter,
] = identityCenterPrincipalAssignmentExecutor{}

func (identityCenterPrincipalAssignmentExecutor) getAll(ctx context.Context, cache *Cache, loadSecrets bool) ([]*identitycenterv1.PrincipalAssignment, error) {
var pageToken pagination.PageRequestToken
var resources []*identitycenterv1.PrincipalAssignment
Expand Down Expand Up @@ -189,3 +189,8 @@ func (identityCenterAccountAssignmentExecutor) getReader(cache *Cache, cacheOK b
func (identityCenterAccountAssignmentExecutor) isSingleton() bool {
return false
}

var _ executor[
services.IdentityCenterAccountAssignment,
identityCenterAccountAssignmentGetter,
] = identityCenterAccountAssignmentExecutor{}

0 comments on commit d3e981c

Please sign in to comment.