Skip to content

Commit

Permalink
test(e2e): Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
stasryzhov committed Feb 27, 2024
1 parent 71639df commit 729235f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion testing/internal/e2e/boundary/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func AddPrincipalToRoleCli(t testing.TB, ctx context.Context, roleId string, pri
),
)
require.NoError(t, output.Err, string(output.Stderr))
t.Logf("Principle %s added to role: %s", principal, roleId)
t.Logf("Principal %s added to role: %s", principal, roleId)
}

// SetGrantScopesToRoleCli uses Boundary CLI to override grant scopes for the role with the provided ones.
Expand Down
74 changes: 36 additions & 38 deletions testing/internal/e2e/tests/base/role_multi_scope_grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,36 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
boundary.AuthenticateAdminCli(t, ctx)

// Create Org and Project
newOrgId := boundary.CreateNewOrgCli(t, ctx)
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", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId := boundary.CreateNewProjectCli(t, ctx, orgId)

// Create Account
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
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", newAccountId),
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})

// Create User and set Account to it
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
userId := boundary.CreateNewUserCli(t, ctx, "global")
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)

// Create Role and add admin grants to it
newRoleId, 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", newRoleId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=*;actions=*")
boundary.SetAccountToUserCli(t, ctx, userId, accountId)

// Authenticate test user and try to:
// - create role in global scope: expect error
Expand All @@ -74,40 +62,50 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
_, err = boundary.CreateRoleCli(t, ctx, "global")
require.Error(t, err)

_, err = boundary.CreateRoleCli(t, ctx, newOrgId)
_, err = boundary.CreateRoleCli(t, ctx, orgId)
require.Error(t, err)

_, err = boundary.CreateRoleCli(t, ctx, newProjectId)
_, err = boundary.CreateRoleCli(t, ctx, projectId)
require.Error(t, err)

// Add User as a principle to the admin Role
// Create Role and add admin grants, and principal to it
boundary.AuthenticateAdminCli(t, ctx)
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
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=*;actions=*")
boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)

// Authenticate User and try to:
// - create Role in global scope: expect success
// - create Role in org scope: expect error
// - create Role in proj scope: expect error
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
newGlobalRoleId2, err := boundary.CreateRoleCli(t, ctx, "global")
globalRoleId2, 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", newGlobalRoleId2),
e2e.WithArgs("roles", "delete", "-id", globalRoleId2),
)
require.NoError(t, output.Err, string(output.Stderr))
})

_, err = boundary.CreateRoleCli(t, ctx, newOrgId)
_, err = boundary.CreateRoleCli(t, ctx, orgId)
require.Error(t, err)

_, err = boundary.CreateRoleCli(t, ctx, newProjectId)
_, err = boundary.CreateRoleCli(t, ctx, projectId)
require.Error(t, err)

// Set Grant Scopes to Role: this, children
boundary.AuthenticateAdminCli(t, ctx)
err = boundary.SetGrantScopesToRoleCli(t, ctx, newRoleId,
err = boundary.SetGrantScopesToRoleCli(t, ctx, roleId,
boundary.WithGrantScopeId("this"),
boundary.WithGrantScopeId("children"),
)
Expand All @@ -118,25 +116,25 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
// - create Role in org scope: expect success
// - create Role in proj scope: expect error
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
newGlobalRoleId3, err := boundary.CreateRoleCli(t, ctx, "global")
globalRoleId3, 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", newGlobalRoleId3),
e2e.WithArgs("roles", "delete", "-id", globalRoleId3),
)
require.NoError(t, output.Err, string(output.Stderr))
})

_, err = boundary.CreateRoleCli(t, ctx, newOrgId)
_, err = boundary.CreateRoleCli(t, ctx, orgId)
require.NoError(t, err)

_, err = boundary.CreateRoleCli(t, ctx, newProjectId)
_, err = boundary.CreateRoleCli(t, ctx, projectId)
require.Error(t, err)

// Set Grant Scopes to Role: this, descendants
boundary.AuthenticateAdminCli(t, ctx)
err = boundary.SetGrantScopesToRoleCli(t, ctx, newRoleId,
err = boundary.SetGrantScopesToRoleCli(t, ctx, roleId,
boundary.WithGrantScopeId("this"),
boundary.WithGrantScopeId("descendants"),
)
Expand All @@ -147,19 +145,19 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
// - create Role in org scope: expect success
// - create Role in proj scope: expect success
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
newGlobalRoleId4, err := boundary.CreateRoleCli(t, ctx, "global")
globalRoleId4, 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", newGlobalRoleId4),
e2e.WithArgs("roles", "delete", "-id", globalRoleId4),
)
require.NoError(t, output.Err, string(output.Stderr))
})

_, err = boundary.CreateRoleCli(t, ctx, newOrgId)
_, err = boundary.CreateRoleCli(t, ctx, orgId)
require.NoError(t, err)

_, err = boundary.CreateRoleCli(t, ctx, newProjectId)
_, err = boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
}

0 comments on commit 729235f

Please sign in to comment.