fix(bats): Fix flakiness in sessions.bats tests (#2537)
The sessions.bats tests were seeing some flaky behavior when listing sessions but not getting the expected amount back. This is due to the connect_nc command that is currently used, which will immediately set the session to be "canceled" once it returns. This can cause subsequent operations to get unexpected results (sometimes, listing sessions would return an empty list if the created sessions go to a "terminated" state).
This commit is contained in:
1 parent
3be8b6efed
commit
16e90ddd35
3 files changed
+21
-13
No files matched your search
@@ -1,4 +1,5 @@
|
||||
function connect_nc() {
|
||||
local id=$1
|
||||
# Note: When this command returns, the session immediately goes into a "canceling" state
|
||||
echo "foo" | boundary connect -exec nc -target-id $id -- {{boundary.ip}} {{boundary.port}}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
load _authorized_actions
|
||||
|
||||
function list_sessions() {
|
||||
boundary sessions list -scope-id $1 -format json
|
||||
function list_sessions_include_terminated() {
|
||||
boundary sessions list -scope-id $1 -include-terminated -format json
|
||||
}
|
||||
|
||||
function count_sessions() {
|
||||
list_sessions $1 | jq '.items | length'
|
||||
function count_sessions_include_terminated() {
|
||||
list_sessions_include_terminated $1 | jq '.items | length'
|
||||
}
|
||||
|
||||
function cancel_session() {
|
||||
|
||||
@@ -7,6 +7,7 @@ load _helpers
|
||||
|
||||
@test "boundary/session: admin user can connect to default target" {
|
||||
run login $DEFAULT_LOGIN
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run connect_nc $DEFAULT_TARGET
|
||||
@@ -21,11 +22,11 @@ load _helpers
|
||||
|
||||
@test "boundary/session/connect: unpriv user can connect to default target" {
|
||||
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||
echo $output
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run connect_nc $DEFAULT_TARGET
|
||||
echo $output
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# Run twice so we have two values for later testing
|
||||
@@ -39,15 +40,18 @@ load _helpers
|
||||
# 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
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run count_sessions $DEFAULT_P_ID
|
||||
run count_sessions_include_terminated $DEFAULT_P_ID
|
||||
echo "Number of sessions (unpriv): $output"
|
||||
[ "$status" -eq 0 ]
|
||||
unpriv_sessions="$output"
|
||||
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run count_sessions $DEFAULT_P_ID
|
||||
run count_sessions_include_terminated $DEFAULT_P_ID
|
||||
echo "Number of sessions (admin): $output"
|
||||
[ "$status" -eq 0 ]
|
||||
admin_sessions="$output"
|
||||
|
||||
@@ -57,8 +61,10 @@ load _helpers
|
||||
@test "boundary/session: verify read and cancellation permissions on admin session" {
|
||||
# Find an admin session
|
||||
run login $DEFAULT_LOGIN
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
run list_sessions $DEFAULT_P_ID
|
||||
run list_sessions_include_terminated $DEFAULT_P_ID
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
id=$(echo "$output" | jq -r "[.items[]|select(.user_id == \"$DEFAULT_USER\")][0].id")
|
||||
|
||||
@@ -74,19 +80,20 @@ load _helpers
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run read_session $id
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
echo $output
|
||||
echo "$output"
|
||||
run cancel_session $id
|
||||
[ "$status" -eq 0 ]
|
||||
echo $output
|
||||
echo "$output"
|
||||
}
|
||||
|
||||
@test "boundary/session: verify read and cancellation permissions on unpriv session" {
|
||||
# Find an unpriv session
|
||||
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run list_sessions $DEFAULT_P_ID
|
||||
echo $output
|
||||
run list_sessions_include_terminated $DEFAULT_P_ID
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
id=$(echo "$output" | jq -r "[.items[]|select(.user_id == \"$DEFAULT_UNPRIVILEGED_USER\")][0].id")
|
||||
|
||||
|
||||
Reference in new issue
Block a user