2026-04-06 15:48:37 +05:30
|
|
|
// Copyright IBM Corp. 2020, 2026
|
2023-03-15 11:40:40 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
package auth
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"sort"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-10-12 10:33:41 -07:00
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db/timestamp"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/kms"
|
2023-03-15 11:40:40 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
2025-06-20 15:31:57 -04:00
|
|
|
type (
|
|
|
|
|
TestAuthMethodWithAccountFunc func(t *testing.T, conn *db.DB) (AuthMethod, Account)
|
|
|
|
|
TestAuthMethodWithAccountInManagedGroup func(t *testing.T, conn *db.DB, kmsCache *kms.Kms, scopeId string) (AuthMethod, Account, ManagedGroup)
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-15 11:40:40 -04:00
|
|
|
// ManagedGroupMemberAccount represents an entry from
|
|
|
|
|
// auth_managed_group_member_account. These are used to determine the account
|
|
|
|
|
// ids where are a member of managed groups. See: oidc and ldap managed groups
|
|
|
|
|
// as well as iam role grants.
|
|
|
|
|
type ManagedGroupMemberAccount struct {
|
|
|
|
|
CreateTime *timestamp.Timestamp
|
|
|
|
|
MemberId string
|
|
|
|
|
ManagedGroupId string
|
|
|
|
|
tableName string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetTableName sets the table name.
|
|
|
|
|
func (a *ManagedGroupMemberAccount) SetTableName(n string) {
|
|
|
|
|
a.tableName = n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TableName returns the table name.
|
|
|
|
|
func (a *ManagedGroupMemberAccount) TableName() string {
|
|
|
|
|
if a.tableName != "" {
|
|
|
|
|
return a.tableName
|
|
|
|
|
}
|
|
|
|
|
return "auth_managed_group_member_account"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestSortManagedGroupMemberAccounts simply sorts them by public id to make
|
|
|
|
|
// comparisons a bit easier.
|
|
|
|
|
func TestSortManagedGroupMemberAccounts(t testing.TB, m []*ManagedGroupMemberAccount) {
|
|
|
|
|
sort.Slice(m, func(a, b int) bool {
|
|
|
|
|
return m[a].MemberId < m[b].MemberId
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestManagedGroupMemberAccounts retrieves the accounts with membership in the
|
|
|
|
|
// specified managed group.
|
|
|
|
|
func TestManagedGroupMemberAccounts(t *testing.T, conn *db.DB, managedGroupId string) []*ManagedGroupMemberAccount {
|
|
|
|
|
var mgmAccts []*ManagedGroupMemberAccount
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
rw := db.New(conn)
|
|
|
|
|
err := rw.SearchWhere(ctx, &mgmAccts, "managed_group_id = ?", []any{managedGroupId})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
TestSortManagedGroupMemberAccounts(t, mgmAccts)
|
|
|
|
|
return mgmAccts
|
|
|
|
|
}
|