test(e2e): Add multi-scope grants test (#4446)
This commit is contained in:
1 parent
d5ae3d8dc6
commit
41d3dffa9b
12 files changed
+262
-21
No files matched your search
@@ -0,0 +1,142 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package base_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestCliApplyGrantsForMultipleScopes verifies if roles' grants can be applied for children and descendant scopes
|
||||
func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
|
||||
e2e.MaybeSkipTest(t)
|
||||
bc, err := boundary.LoadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
|
||||
// Create Org and Project
|
||||
orgId := boundary.CreateNewOrgCli(t, ctx)
|
||||
t.Cleanup(func() {
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
projectId := boundary.CreateNewProjectCli(t, ctx, orgId)
|
||||
|
||||
// Create Account
|
||||
acctName := "e2e-account"
|
||||
accountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
|
||||
t.Cleanup(func() {
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("accounts", "delete", "-id", accountId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
|
||||
// Create User and set Account to it
|
||||
userId := boundary.CreateNewUserCli(t, ctx, "global")
|
||||
t.Cleanup(func() {
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("users", "delete", "-id", userId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
boundary.SetAccountToUserCli(t, ctx, userId, accountId)
|
||||
|
||||
// Authenticate test user and try to:
|
||||
// - list Roles in global scope: expect error
|
||||
// - list Roles in org scope: expect error
|
||||
// - list Roles in proj scope: expect error
|
||||
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
|
||||
|
||||
_, err = boundary.CreateRoleCli(t, ctx, "global")
|
||||
require.Error(t, err)
|
||||
|
||||
_, err = boundary.CreateRoleCli(t, ctx, orgId)
|
||||
require.Error(t, err)
|
||||
|
||||
_, err = boundary.CreateRoleCli(t, ctx, projectId)
|
||||
require.Error(t, err)
|
||||
|
||||
// Create Role, and add grants and principal to it
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
roleId, err := boundary.CreateRoleCli(t, ctx, "global")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("roles", "delete", "-id", roleId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=role;actions=list")
|
||||
boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
|
||||
|
||||
// Authenticate User and try to:
|
||||
// - list Roles in global scope: expect success
|
||||
// - list Roles in org scope: expect error
|
||||
// - list Roles in proj scope: expect error
|
||||
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
|
||||
_, err = boundary.ListRolesCli(t, ctx, "global")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = boundary.ListRolesCli(t, ctx, orgId)
|
||||
require.Error(t, err)
|
||||
|
||||
_, err = boundary.ListRolesCli(t, ctx, projectId)
|
||||
require.Error(t, err)
|
||||
|
||||
// Set Grant Scopes to Role: this, children
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
err = boundary.SetGrantScopesToRoleCli(t, ctx, roleId,
|
||||
boundary.WithGrantScopeId("this"),
|
||||
boundary.WithGrantScopeId("children"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Authenticate User and try to:
|
||||
// - list Roles in global scope: expect success
|
||||
// - list Roles in org scope: expect success
|
||||
// - list Roles in proj scope: expect error
|
||||
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
|
||||
_, err = boundary.ListRolesCli(t, ctx, "global")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = boundary.ListRolesCli(t, ctx, orgId)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = boundary.ListRolesCli(t, ctx, projectId)
|
||||
require.Error(t, err)
|
||||
|
||||
// Set Grant Scopes to Role: this, descendants
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
err = boundary.SetGrantScopesToRoleCli(t, ctx, roleId,
|
||||
boundary.WithGrantScopeId("this"),
|
||||
boundary.WithGrantScopeId("descendants"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Authenticate User and try to:
|
||||
// - list Roles in global scope: expect success
|
||||
// - list Roles in org scope: expect success
|
||||
// - list Roles in proj scope: expect success
|
||||
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
|
||||
_, err = boundary.ListRolesCli(t, ctx, "global")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = boundary.ListRolesCli(t, ctx, orgId)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = boundary.ListRolesCli(t, ctx, projectId)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -98,7 +98,8 @@ func TestCliSessionCancelGroup(t *testing.T) {
|
||||
boundary.AddUserToGroup(t, ctx, newUserId, newGroupId)
|
||||
|
||||
// Create a role for a group
|
||||
newRoleId := boundary.CreateNewRoleCli(t, ctx, newProjectId)
|
||||
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
|
||||
require.NoError(t, err)
|
||||
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
|
||||
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newGroupId)
|
||||
|
||||
|
||||
@@ -93,7 +93,8 @@ func TestCliSessionCancelUser(t *testing.T) {
|
||||
|
||||
// Create a role for user
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
newRoleId := boundary.CreateNewRoleCli(t, ctx, newProjectId)
|
||||
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
|
||||
require.NoError(t, err)
|
||||
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
|
||||
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ func TestCliSessionEndWhenHostSetIsDeleted(t *testing.T) {
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
|
||||
newRoleId := boundary.CreateNewRoleCli(t, ctx, newProjectId)
|
||||
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
|
||||
require.NoError(t, err)
|
||||
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
|
||||
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ func TestCliSessionEndWhenHostIsDeleted(t *testing.T) {
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
|
||||
newRoleId := boundary.CreateNewRoleCli(t, ctx, newProjectId)
|
||||
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
|
||||
require.NoError(t, err)
|
||||
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
|
||||
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ func TestCliSessionEndWhenProjectIsDeleted(t *testing.T) {
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
|
||||
newRoleId := boundary.CreateNewRoleCli(t, ctx, newProjectId)
|
||||
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
|
||||
require.NoError(t, err)
|
||||
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
|
||||
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ func TestCliSessionEndWhenTargetIsDeleted(t *testing.T) {
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
|
||||
newRoleId := boundary.CreateNewRoleCli(t, ctx, newProjectId)
|
||||
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
|
||||
require.NoError(t, err)
|
||||
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
|
||||
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
|
||||
}
|
||||
})
|
||||
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
|
||||
newRoleId := boundary.CreateNewRoleCli(t, ctx, newProjectId)
|
||||
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
|
||||
require.NoError(t, err)
|
||||
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
|
||||
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
|
||||
|
||||
|
||||
Reference in new issue
Block a user