Skip to content

Commit

Permalink
refact(e2e): Add err to CreateAccountCli
Browse files Browse the repository at this point in the history
  • Loading branch information
moduli committed Apr 1, 2024
1 parent 3929fe5 commit d73b748
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 51 deletions.
29 changes: 19 additions & 10 deletions testing/internal/e2e/boundary/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ func CreateAccountApi(t testing.TB, ctx context.Context, client *api.Client, aut
return accountId, password, nil
}

// CreateNewAccountCli creates a new account using the cli.
// CreateAccountCli creates a new account using the cli.
// Returns the id of the new account as well as the password that was generated
func CreateNewAccountCli(t testing.TB, ctx context.Context, authMethodId string, loginName string) (string, string) {
func CreateAccountCli(t testing.TB, ctx context.Context, authMethodId string, loginName string) (string, string, error) {
name, err := base62.Random(16)
if err != nil {
return "", "", err
}

password, err := base62.Random(16)
require.NoError(t, err)
output := e2e.RunCommand(ctx, "boundary",
Expand All @@ -52,19 +57,23 @@ func CreateNewAccountCli(t testing.TB, ctx context.Context, authMethodId string,
"-auth-method-id", authMethodId,
"-login-name", loginName,
"-password", "env://E2E_TEST_ACCOUNT_PASSWORD",
"-name", "e2e Account "+loginName,
"-name", fmt.Sprintf("e2e Account %s", name),
"-description", "e2e",
"-format", "json",
),
e2e.WithEnv("E2E_TEST_ACCOUNT_PASSWORD", password),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return "", "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}

var newAccountResult accounts.AccountCreateResult
err = json.Unmarshal(output.Stdout, &newAccountResult)
require.NoError(t, err)
var createAccountResult accounts.AccountCreateResult
err = json.Unmarshal(output.Stdout, &createAccountResult)
if err != nil {
return "", "", err
}

newAccountId := newAccountResult.Item.Id
t.Logf("Created Account: %s", newAccountId)
return newAccountId, password
accountId := createAccountResult.Item.Id
t.Logf("Created Account: %s", accountId)
return accountId, password, nil
}
14 changes: 8 additions & 6 deletions testing/internal/e2e/tests/base/auth_method_password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func TestCliAuthMethodPassword(t *testing.T) {

// Create account in auth method
testAccountName := "test-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, newAuthMethodId, testAccountName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, newAuthMethodId, testAccountName)
require.NoError(t, err)

// Set new auth method as primary auth method for the new org
output = e2e.RunCommand(ctx, "boundary",
Expand Down Expand Up @@ -105,7 +106,7 @@ func TestCliAuthMethodPassword(t *testing.T) {
var usersListResult users.UserListResult
err = json.Unmarshal(output.Stdout, &usersListResult)
require.NoError(t, err)
require.Equal(t, newAccountId, usersListResult.Items[0].PrimaryAccountId)
require.Equal(t, accountId, usersListResult.Items[0].PrimaryAccountId)

userId := usersListResult.Items[0].Id
output = e2e.RunCommand(ctx, "boundary",
Expand All @@ -119,15 +120,16 @@ func TestCliAuthMethodPassword(t *testing.T) {
var usersReadResult users.UserReadResult
err = json.Unmarshal(output.Stdout, &usersReadResult)
require.NoError(t, err)
require.Equal(t, newAccountId, usersReadResult.Item.PrimaryAccountId)
require.Contains(t, usersReadResult.Item.AccountIds, newAccountId)
require.Equal(t, accountId, usersReadResult.Item.PrimaryAccountId)
require.Contains(t, usersReadResult.Item.AccountIds, accountId)

// Create a new account and manually attach it to a new user
newUserId, err := boundary.CreateUserCli(t, ctx, orgId)
require.NoError(t, err)
testAccountName = "test-account2"
newAccountId, acctPassword = boundary.CreateNewAccountCli(t, ctx, newAuthMethodId, testAccountName)
err = boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
accountId, acctPassword, err = boundary.CreateAccountCli(t, ctx, newAuthMethodId, testAccountName)
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, newUserId, accountId)
require.NoError(t, err)

// Log in with the new account
Expand Down
7 changes: 4 additions & 3 deletions testing/internal/e2e/tests/base/auth_token_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ func TestUserIsLoggedOutWhenAuthTokenIsDeletedCli(t *testing.T) {

ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, testAccountName)
accountid, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, testAccountName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -45,7 +46,7 @@ func TestUserIsLoggedOutWhenAuthTokenIsDeletedCli(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountid)
require.NoError(t, err)

// Authenticate user and assign a name to its auth token
Expand Down
6 changes: 4 additions & 2 deletions testing/internal/e2e/tests/base/paginate_auth_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func TestCliPaginateAuthTokens(t *testing.T) {
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("auth-methods", "delete", "-id", amId))
require.NoError(t, output.Err, string(output.Stderr))
})
accId, password := boundary.CreateNewAccountCli(t, ctx, amId, "testuser")
accId, password, err := boundary.CreateAccountCli(t, ctx, amId, "testuser")
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, userId, accId)
require.NoError(t, err)

Expand Down Expand Up @@ -161,7 +162,8 @@ func TestApiPaginateAuthTokens(t *testing.T) {
_, err := amClient.Delete(ctx, amId)
require.NoError(t, err)
})
accId, password := boundary.CreateNewAccountCli(t, ctx, amId, "testuser")
accId, password, err := boundary.CreateAccountCli(t, ctx, amId, "testuser")
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, userId, accId)
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {

// Create Account
acctName := "e2e-account"
accountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary",
Expand Down
7 changes: 4 additions & 3 deletions testing/internal/e2e/tests/base/session_cancel_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ func TestCliSessionCancelGroup(t *testing.T) {
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -74,7 +75,7 @@ func TestCliSessionCancelGroup(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)

// Try to connect to the target as a user without permissions
Expand Down
7 changes: 4 additions & 3 deletions testing/internal/e2e/tests/base/session_cancel_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ func TestCliSessionCancelUser(t *testing.T) {
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -73,7 +74,7 @@ func TestCliSessionCancelUser(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)

// Try to connect to the target as a user without permissions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ func TestCliSessionEndWhenHostSetIsDeleted(t *testing.T) {
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -66,7 +67,7 @@ func TestCliSessionEndWhenHostSetIsDeleted(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ func TestCliSessionEndWhenHostIsDeleted(t *testing.T) {
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -66,7 +67,7 @@ func TestCliSessionEndWhenHostIsDeleted(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ func TestCliSessionEndWhenProjectIsDeleted(t *testing.T) {
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithAddress(c.TargetAddress))
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -57,7 +58,7 @@ func TestCliSessionEndWhenProjectIsDeleted(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ func TestCliSessionEndWhenTargetIsDeleted(t *testing.T) {
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -66,7 +67,7 @@ func TestCliSessionEndWhenTargetIsDeleted(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -71,7 +72,7 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
require.NoError(t, output.Err, string(output.Stderr))
}
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
Expand Down
14 changes: 8 additions & 6 deletions testing/internal/e2e/tests/base_plus/rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ func TestHttpRateLimit(t *testing.T) {

// Create a user
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -175,7 +176,7 @@ func TestHttpRateLimit(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
Expand Down Expand Up @@ -302,11 +303,12 @@ func TestCliRateLimit(t *testing.T) {

// Create a user
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
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))
})
Expand All @@ -319,7 +321,7 @@ func TestCliRateLimit(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions testing/internal/e2e/tests/database/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T
boundary.WaitForHostsInHostSetCli(t, ctx, awsHostSetId)

// Create a user/group and add role to group
newAccountId, _ := boundary.CreateNewAccountCli(t, ctx, te.DbInitInfo.AuthMethod.AuthMethodId, "test-account")
accountId, _, err := boundary.CreateAccountCli(t, ctx, te.DbInitInfo.AuthMethod.AuthMethodId, "test-account")
require.NoError(t, err)
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
groupId, err := boundary.CreateGroupCli(t, ctx, "global")
require.NoError(t, err)
Expand Down

0 comments on commit d73b748

Please sign in to comment.