chore(e2e): Make function for role creation conventional

Return role id and error and handle the error where the function is called.
pull/4446/head
Stan Ryzhov 2 years ago
parent 2c75f0e3d7
commit 4c83dad9d6

@ -28,28 +28,6 @@ func CreateNewRoleApi(t testing.TB, ctx context.Context, client *api.Client, sco
return newRoleId
}
// CreateNewRoleCli creates a new role using the cli.
// Returns the id of the new role.
func CreateNewRoleCli(t testing.TB, ctx context.Context, scopeId string) string {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"roles", "create",
"-scope-id", scopeId,
"-name", "e2e Role",
"-description", "e2e",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newRoleResult roles.RoleCreateResult
err := json.Unmarshal(output.Stdout, &newRoleResult)
require.NoError(t, err)
newRoleId := newRoleResult.Item.Id
t.Logf("Created Role: %s", newRoleId)
return newRoleId
}
// CreateRoleCli creates a new role using the Boundary CLI.
// Returns the id of the new role or error
func CreateRoleCli(t testing.TB, ctx context.Context, scopeId string) (string, error) {

@ -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)

@ -155,7 +155,8 @@ func TestCliLdap(t *testing.T) {
require.Contains(t, managedGroupReadResult.Item.MemberIds, newAccountId)
// Add managed group as a principal to a role with permissions to read auth methods
newRoleId := boundary.CreateNewRoleCli(t, ctx, newOrgId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newOrgId)
require.NoError(t, err)
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, managedGroupId)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=auth-method;actions=read")

@ -171,7 +171,8 @@ func TestHttpRateLimit(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=*;actions=*")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
@ -306,7 +307,8 @@ func TestCliRateLimit(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=*;actions=*")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)

@ -241,7 +241,8 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newGroupId := boundary.CreateNewGroupCli(t, ctx, "global")
boundary.AddUserToGroup(t, ctx, newUserId, newGroupId)
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)
@ -277,7 +278,7 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T
)
require.NoError(t, output.Err, string(output.Stderr))
var tokenCreateResult vault.CreateTokenResponse
err := json.Unmarshal(output.Stdout, &tokenCreateResult)
err = json.Unmarshal(output.Stdout, &tokenCreateResult)
require.NoError(t, err)
credStoreToken := tokenCreateResult.Auth.Client_Token
t.Log("Created Vault Cred Store Token")

Loading…
Cancel
Save