Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(groups): add grants tests for groups API #5403

Open
wants to merge 49 commits into
base: llb-normalized-grants
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9deb35a
first test with all the required setup
bosorawis Dec 17, 2024
b62c58c
v1 of test
bosorawis Dec 18, 2024
2847974
add primitive func and more test
bosorawis Dec 19, 2024
1fb540f
refactor read tests into a single top level
bosorawis Dec 20, 2024
62a3112
move token generation to a function
bosorawis Dec 20, 2024
bda6a33
add test for creates
bosorawis Dec 21, 2024
1bc4bb9
add delete tests
bosorawis Dec 24, 2024
99552af
add update test
bosorawis Dec 27, 2024
5137e63
only check for version and update_time
bosorawis Dec 27, 2024
df1eea1
move setup resource into testcase to support grants with specific ID
bosorawis Dec 27, 2024
a11f366
add member tests
bosorawis Jan 3, 2025
f38198e
add group-member test example with multiple actions
bosorawis Jan 3, 2025
8f24be7
remove duplicate group membership tests
bosorawis Jan 3, 2025
515013f
ran make gen
bosorawis Jan 3, 2025
567190e
fix missing parentID bug
bosorawis Jan 4, 2025
def3900
fix typo
bosorawis Jan 4, 2025
a32b74d
fix test names and add test cases
bosorawis Jan 6, 2025
401a9eb
switch from google/uuid to hashicorp/go-uuid
bosorawis Jan 6, 2025
4dc5344
add comment to groupmember tests
bosorawis Jan 6, 2025
8b5e8d3
small comment change
bosorawis Jan 7, 2025
a457a9c
pull shared test utility code from PR #5418
bosorawis Jan 8, 2025
05f9a59
refactor role grants out of authtoken package
bosorawis Jan 29, 2025
fb7bda7
unexport utility function
bosorawis Jan 29, 2025
224f2be
Remove dead code
bosorawis Jan 29, 2025
5eddf3f
lint and make gen
bosorawis Jan 29, 2025
4670161
fix role cration logic
bosorawis Jan 30, 2025
11b9664
fix password TestAccountFunc implementation
bosorawis Feb 12, 2025
6428eb9
implement TestAccountFunc for LDAP
bosorawis Feb 12, 2025
e992244
implement TestAccountFunc for OIDC
bosorawis Feb 12, 2025
9acb2f4
implement TestUserFunc for managed groups
bosorawis Feb 12, 2025
7291ccb
use managed groups in grants test
bosorawis Feb 12, 2025
4c13c6a
undo removal of authtoken.TestAuthTokenWithRoles for future refactor
bosorawis Feb 12, 2025
9592fdb
switch from list to map based test case for create tests
bosorawis Feb 12, 2025
743bb0b
undo merge mistakes
bosorawis Feb 12, 2025
ed41a7d
fix merge mistakes
bosorawis Feb 12, 2025
ce38dac
lint
bosorawis Feb 12, 2025
1029cbb
add setup examples
bosorawis Feb 13, 2025
f03226b
add output fields tests for getgroup
bosorawis Feb 14, 2025
e861253
reimplement with reflect
bosorawis Feb 14, 2025
ce83c89
add test for CreateGroup
bosorawis Feb 14, 2025
1357b20
add all single resource action tests
bosorawis Feb 15, 2025
42077fa
add list test
bosorawis Feb 15, 2025
6a0a5cc
rename function argument
bosorawis Feb 19, 2025
8079ad7
move AssertOutputFields to handlers package
bosorawis Feb 19, 2025
264055a
fix lint
bosorawis Feb 19, 2025
59426ba
make gen
bosorawis Feb 19, 2025
748a968
use proto.Message instead of custom interface
bosorawis Feb 19, 2025
5677673
switch to hashicorp/go-uuid
bosorawis Feb 19, 2025
d9e4f14
fix typo
bosorawis Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/auth/ldap/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/kms"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -175,6 +176,21 @@ func TestAccount(t testing.TB, conn *db.DB, am *AuthMethod, loginName string, op
return a
}

// TestAccountFunc returns a function that creates an LDAP auth method, a managed group, and an account in that method which
// is also a member of the created ManagedGroup. The function returns the public ID of the managed group and the account.
func TestAccountFunc(t *testing.T, conn *db.DB, kmsCache *kms.Kms, scopeID string) func() (managedGroupID string, accountID string) {
return func() (string, string) {
t.Helper()
ctx := context.Background()
databaseWrapper, err := kmsCache.GetWrapper(context.Background(), scopeID, kms.KeyPurposeDatabase)
require.NoError(t, err)
am := TestAuthMethod(t, conn, databaseWrapper, scopeID, []string{"ldap://testldap"})
managedGroup := TestManagedGroup(t, conn, am, []string{"test-group"})
acct := TestAccount(t, conn, am, "testacct", WithMemberOfGroups(ctx, "test-group"))
return managedGroup.PublicId, acct.PublicId
}
}

// TestManagedGroup creates a test ldap managed group.
func TestManagedGroup(t testing.TB, conn *db.DB, am *AuthMethod, grpNames []string, opt ...Option) *ManagedGroup {
t.Helper()
Expand Down
19 changes: 19 additions & 0 deletions internal/auth/oidc/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@ func TestAccount(t testing.TB, conn *db.DB, am *AuthMethod, subject string, opt
return a
}

// TestAccountFunc returns a function that creates an OIDC auth method, an account on that auth method, and an OIDC managed group
// which has a filter that matches the account's subject. The function returns the managed group's public ID and the account's public ID.
func TestAccountFunc(t *testing.T, conn *db.DB, kmsCache *kms.Kms, scopeID string) func() (managedGroupID string, accountID string) {
return func() (string, string) {
t.Helper()
databaseWrapper, err := kmsCache.GetWrapper(context.Background(), scopeID, kms.KeyPurposeDatabase)
require.NoError(t, err)
testAuthMethod := TestAuthMethod(t, conn, databaseWrapper, scopeID, ActivePublicState,
"alice-rp", "fido",
WithIssuer(TestConvertToUrls(t, "https://alice.com")[0]),
WithSigningAlgs(Alg(oidc.RS256)),
WithApiUrl(TestConvertToUrls(t, "https://alice.com/callback")[0]))
account := TestAccount(t, conn, testAuthMethod, "testacct")
managedGroup := TestManagedGroup(t, conn, testAuthMethod, `"/token/sub" matches ".*"`)
TestManagedGroupMember(t, conn, managedGroup.PublicId, account.PublicId)
return managedGroup.PublicId, account.PublicId
}
}

// TestManagedGroup creates a test oidc managed group.
func TestManagedGroup(t testing.TB, conn *db.DB, am *AuthMethod, filter string, opt ...Option) *ManagedGroup {
t.Helper()
Expand Down
15 changes: 15 additions & 0 deletions internal/auth/password/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/go-uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -71,6 +73,19 @@ func TestMultipleAccounts(t testing.TB, conn *db.DB, authMethodId string, count
return auts
}

// TestAccountFunc returns a function that creates auth method and an account in that auth method
// which returns the created account ID in a slice
// This is used to normalize account creation across multiple auth method types
func TestAccountFunc(t testing.TB, conn *db.DB) func() string {
return func() string {
authMethod := TestAuthMethod(t, conn, globals.GlobalPrefix)
loginName, err := uuid.GenerateUUID()
require.NoError(t, err)
acct := TestAccount(t, conn, authMethod.GetPublicId(), loginName)
return acct.PublicId
}
}

// TestAccount creates a password account to the provided DB with the provided
// auth method id and loginName. The auth method must have been created
// previously. See password.NewAccount(...) for a list of supported options.
Expand Down
Loading
Loading