Files
threshold/internal/tests/cli/boundary/sessions.bats
T
9169c6bacb [QTI-220] Add infrastructure integration testing (#2282)
* [QTI-275] Add infrastructure integration testing

On pull requests that originate from branches of the `hashicorp/boundary`
repo, we now conditionally dispatch infrastructure integration tests using
the Enos framework. The `integration` Enos scenario includes two `builder`
variants which allow developers or CI to deploy a Boundary cluster in AWS
using either a local `boundary` install bundle or that which is produced
in the `build` workflow for CRT. The `test` variants determine which type
of infrastructure integration test to run. At present those options are
`cli_ui` (Bats CLI tests) or `smoke` (creates target instances and a
target host catalog and verifies that `boundary` works).

In addition to the new workflow and quality scenarios, we simplified the
some `build` workflow steps and added Go module caching to speed up the
build pipeline.

See the [enos/README.md](https://github.com/hashicorp/boundary/blob/main/enos/README.md)
for a detailed explanation on how to configure and execute Enos scenarios
from your machine.

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Rebecca Willett <rwillett@hashicorp.com>
Co-authored-by: Josh Branch <jbrand@hashicorp.com>
2022-07-28 14:48:51 -06:00

117 lines
2.9 KiB
Bash

#!/usr/bin/env bats
load _auth
load _connect
load _sessions
load _helpers
@test "boundary/session: admin user can connect to default target" {
run login $DEFAULT_LOGIN
[ "$status" -eq 0 ]
run connect_nc $DEFAULT_TARGET
echo "$output"
[ "$status" -eq 0 ]
# Run twice so we have two values for later testing
run connect_nc $DEFAULT_TARGET
echo "$output"
[ "$status" -eq 0 ]
}
@test "boundary/session/connect: unpriv user can connect to default target" {
if [ "$SKIP_FAILING_TESTS_IN_CI" == "true" ]; then
skip
fi
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run connect_nc $DEFAULT_TARGET
[ "$status" -eq 0 ]
# Run twice so we have two values for later testing
run connect_nc $DEFAULT_TARGET
echo "$output"
diag "$output"
[ "$status" -eq 0 ]
}
# Note: there seems to be an issue with jq's length calculation -- an increase
# in the returned array by 2 shows up as a 4 or more increase in jq's length count.
# So for now, verify they're not the same.
@test "boundary/session: verify admin and unpriv user see different counts" {
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run count_sessions $DEFAULT_P_ID
[ "$status" -eq 0 ]
unpriv_sessions="$output"
run login $DEFAULT_LOGIN
[ "$status" -eq 0 ]
run count_sessions $DEFAULT_P_ID
[ "$status" -eq 0 ]
admin_sessions="$output"
[ "$unpriv_sessions" -lt "$admin_sessions" ]
}
@test "boundary/session: verify read and cancellation permissions on admin session" {
# Find an admin session
run login $DEFAULT_LOGIN
[ "$status" -eq 0 ]
run list_sessions $DEFAULT_P_ID
[ "$status" -eq 0 ]
id=$(echo "$output" | jq -r "[.items[]|select(.user_id == \"$DEFAULT_USER\")][0].id")
# Check unpriv cannot read or cancel an admin's session
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run read_session $id
[ "$status" -eq 1 ]
run cancel_session $id
[ "$status" -eq 1 ]
# Check that admin _can_
run login $DEFAULT_LOGIN
[ "$status" -eq 0 ]
run read_session $id
[ "$status" -eq 0 ]
echo $output
run cancel_session $id
[ "$status" -eq 0 ]
echo $output
}
@test "boundary/session: verify read and cancellation permissions on unpriv session" {
if [ "$SKIP_FAILING_TESTS_IN_CI" == "true" ]; then
skip
fi
# Find an unpriv session
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run list_sessions $DEFAULT_P_ID
[ "$status" -eq 0 ]
id=$(echo "$output" | jq -r "[.items[]|select(.user_id == \"$DEFAULT_USER\")][0].id")
# Check unpriv can read and cancel their own session
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run read_session $id
[ "$status" -eq 0 ]
run cancel_session $id
[ "$status" -eq 0 ]
# Check that admin can too
run login $DEFAULT_LOGIN
[ "$status" -eq 0 ]
run read_session $id
[ "$status" -eq 0 ]
run cancel_session $id
[ "$status" -eq 0 ]
diag "$output"
}