Adds a new test to the e2e test suite that checks that an active session ends once the user is deleted.
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package boundary
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/api"
|
|
"github.com/hashicorp/boundary/api/users"
|
|
"github.com/hashicorp/boundary/testing/internal/e2e"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// CreateNewUserCli creates a new user using the Go api.
|
|
// Returns the id of the new user
|
|
func CreateNewUserApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
|
|
uClient := users.NewClient(client)
|
|
newUserResult, err := uClient.Create(ctx, scopeId)
|
|
require.NoError(t, err)
|
|
newUserId := newUserResult.Item.Id
|
|
t.Logf("Created User: %s", newUserId)
|
|
t.Cleanup(func() {
|
|
_, err := uClient.Delete(ctx, newUserId)
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
return newUserId
|
|
}
|
|
|
|
// CreateNewUserCli creates a new user using the cli.
|
|
// Returns the id of the new user
|
|
func CreateNewUserCli(t testing.TB, ctx context.Context, scopeId string) string {
|
|
output := e2e.RunCommand(ctx, "boundary",
|
|
e2e.WithArgs(
|
|
"users", "create",
|
|
"-scope-id", scopeId,
|
|
"-name", "e2e User",
|
|
"-description", "e2e User",
|
|
"-format", "json",
|
|
),
|
|
)
|
|
require.NoError(t, output.Err, string(output.Stderr))
|
|
|
|
var newUserResult users.UserCreateResult
|
|
err := json.Unmarshal(output.Stdout, &newUserResult)
|
|
require.NoError(t, err)
|
|
|
|
newUserId := newUserResult.Item.Id
|
|
t.Cleanup(func() {
|
|
AuthenticateAdminCli(t, context.Background())
|
|
output := e2e.RunCommand(ctx, "boundary",
|
|
e2e.WithArgs("users", "delete", "-id", newUserId, "-format", "json"),
|
|
)
|
|
// Only allow an error if it's due to a Resource Not Found (404)
|
|
// This was needed since there's a test that already deletes the user and would run into an
|
|
// error during cleanup
|
|
if output.Err != nil {
|
|
var response e2e.CliError
|
|
err := json.Unmarshal(output.Stderr, &response)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 404, int(response.Status))
|
|
}
|
|
})
|
|
t.Logf("Created User: %s", newUserId)
|
|
|
|
return newUserId
|
|
}
|
|
|
|
// SetAccountToUserCli sets an account to a the specified user using the cli.
|
|
func SetAccountToUserCli(t testing.TB, ctx context.Context, userId string, accountId string) {
|
|
output := e2e.RunCommand(ctx, "boundary",
|
|
e2e.WithArgs(
|
|
"users", "set-accounts",
|
|
"-id", userId,
|
|
"-account", accountId,
|
|
),
|
|
)
|
|
require.NoError(t, output.Err, string(output.Stderr))
|
|
}
|