From c4c1e108b0239f9656359029757f7d2ee0261948 Mon Sep 17 00:00:00 2001 From: Jeff Malnick Date: Mon, 12 Oct 2020 14:40:32 -0700 Subject: [PATCH] test: add groups resource CLI tests (#633) --- internal/tests/cli/boundary/_groups.bash | 41 ++++++++++++++ internal/tests/cli/boundary/groups.bats | 68 ++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 internal/tests/cli/boundary/_groups.bash create mode 100644 internal/tests/cli/boundary/groups.bats diff --git a/internal/tests/cli/boundary/_groups.bash b/internal/tests/cli/boundary/_groups.bash new file mode 100644 index 000000000..29e18a920 --- /dev/null +++ b/internal/tests/cli/boundary/_groups.bash @@ -0,0 +1,41 @@ +function create_group() { + boundary groups create -scope-id global -name $1 -description 'test group' +} + +function read_group() { + boundary groups read -id $1 +} + +function delete_group() { + boundary groups delete -id $1 +} + +function list_groups() { + boundary groups list -format json +} + +function assoc_group_acct() { + boundary groups add-members -member $1 -id $2 +} + +function group_id() { + local group=$1 + strip $(list_groups | jq -c ".[] | select(.name | contains(\"$group\")) | .[\"id\"]") +} + +function group_member_ids() { + local gid=$1 + boundary groups read -id $gid -format json | jq '.["members"][]["id"]' +} + +function group_has_member_id() { + local mid=$1 + local gid=$2 + ids=$(group_member_ids $gid) + for id in $ids; do + if [ $(strip "$id") == "$mid" ]; then + return 0 + fi + done + return 1 +} diff --git a/internal/tests/cli/boundary/groups.bats b/internal/tests/cli/boundary/groups.bats new file mode 100644 index 000000000..d7bc8ddbd --- /dev/null +++ b/internal/tests/cli/boundary/groups.bats @@ -0,0 +1,68 @@ +#!/usr/bin/env bats + +load _accounts +load _auth +load _groups +load _helpers + +export NEW_GROUP='test' + +@test "boundary/login: can login as default user" { + run login $DEFAULT_USER + echo "$output" + [ "$status" -eq 0 ] +} + +@test "boundary/groups: can add $NEW_GROUP group" { + run create_group $NEW_GROUP + echo "$output" + [ "$status" -eq 0 ] +} + +@test "boundary/groups: can not add already created $NEW_GROUP group" { + run create_group $NEW_GROUP + echo "$output" + [ "$status" -eq 1 ] +} + +@test "boundary/groups: can read $NEW_GROUP group" { + local gid=$(group_id $NEW_GROUP) + run read_group $gid + echo "$output" + [ "$status" -eq 0 ] +} + +@test "boundary/group/add-members: can associate $NEW_GROUP group with default user" { + local gid=$(group_id $NEW_GROUP) + run assoc_group_acct 'u_1234567890' $gid + echo "$output" + [ "$status" -eq 0 ] +} + +@test "boundary/group/add-members: $NEW_GROUP group contains default user" { + local gid=$(group_id $NEW_GROUP) + run group_has_member_id 'u_1234567890' $gid + echo "$output" + [ "$status" -eq 0 ] +} + +@test "boundary/group: can delete $NEW_GROUP group" { + local gid=$(group_id $NEW_GROUP) + run delete_group $gid + echo "$output" + [ "$status" -eq 0 ] +} + +@test "boundary/group: can not delete already deleted $NEW_GROUP group" { + local gid=$(group_id $NEW_GROUP) + run delete_group $gid + echo "$output" + [ "$status" -eq 1 ] +} + +@test "boundary/groups: can not read deleted $NEW_GROUP group" { + local gid=$(group_id $NEW_GROUP) + run read_group $gid + echo "$output" + [ "$status" -eq 1 ] +}