tests: add bats tests for testing CLI on arbitrary Boundary deployments (#614)

This commit is contained in:
Jeff Malnick authored and GitHub committed 2020-10-12 10:26:26 -07:00
1 parent 3db9a07ace
commit 90e1dbe444
10 files changed
+308

No files matched your search

@@ -0,0 +1,20 @@
function create_account() {
boundary accounts create password -login-name $1 -password $DEFAULT_PASSWORD -auth-method-id $DEFAULT_AMPW
}
function read_account() {
boundary accounts read -id $1
}
function delete_account() {
boundary accounts delete -id $1
}
function list_accounts() {
boundary accounts list -auth-method-id $DEFAULT_AMPW -format json
}
function account_id() {
local acct=$1
strip $(list_accounts | jq -c ".[] | select(.attributes.login_name | contains(\"$acct\")) | .[\"id\"]")
}
+3
View File
@@ -0,0 +1,3 @@
function login() {
boundary authenticate password -auth-method-id $DEFAULT_AMPW -login-name $1 -password $DEFAULT_PASSWORD
}
@@ -0,0 +1,4 @@
function connect_nc() {
local id=$1
echo "foo" | boundary connect -exec nc -target-id $id -- {{boundary.ip}} {{boundary.port}}
}
+12
View File
@@ -0,0 +1,12 @@
export BOUNDARY_ADDR='http://127.0.0.1:9200'
export DEFAULT_PASSWORD='password'
export DEFAULT_USER='admin'
export DEFAULT_AMPW='ampw_1234567890'
export DEFAULT_P_ID='p_1234567890'
export DEFAULT_O_ID='o_1234567890'
export DEFAULT_TARGET='ttcp_1234567890'
export DEFAULT_HOST_SET='hsst_1234567890'
function strip() {
echo "$1" | tr -d '"'
}
+24
View File
@@ -0,0 +1,24 @@
function create_host() {
local name=$1
local addr=$2
boundary hosts create static -name $name -address $addr
}
function read_host() {
boundary hosts read -id $1
}
function delete_host() {
boundary hosts delete -id $1
}
function list_hosts() {
boundary hosts list -scope-id $1 -format json
}
function host_id() {
local sid=$1
local name=$2
strip $(list_hosts $sid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]")
}
+36
View File
@@ -0,0 +1,36 @@
export TGT_NAME='test'
function create_tcp_target() {
local sid=$1
local port=$2
local name=$3
boundary targets create tcp \
-default-port $port \
-name $name \
-scope-id $sid \
-format json
}
function read_target() {
boundary targets read -id $1
}
function delete_target() {
boundary targets delete -id $1
}
function list_targets() {
boundary targets list -scope-id $1 -format json
}
function assoc_host_sets() {
local id=$1
local hst=$2
boundary targets add-host-sets -id $id -host-set $hst
}
function target_id() {
local sid=$1
local name=$2
strip $(list_targets $sid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]")
}
+24
View File
@@ -0,0 +1,24 @@
function create_user() {
boundary users create -scope-id global -name $1 -description 'test user'
}
function read_user() {
boundary users read -id $1
}
function delete_user() {
boundary users delete -id $1
}
function list_users() {
boundary users list -format json
}
function assoc_user_acct() {
boundary users add-accounts -account $1 -id $2
}
function user_id() {
local user=$1
strip $(list_users | jq -c ".[] | select(.name | contains(\"$user\")) | .[\"id\"]")
}
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bats
load _auth
load _connect
load _targets
load _helpers
@test "boundary/login: can login as default user" {
run login $DEFAULT_USER
[ "$status" -eq 0 ]
}
@test "boundary/target: default user can create target" {
run create_tcp_target $DEFAULT_P_ID 22 $TGT_NAME
[ "$status" -eq 0 ]
}
@test "boundary/target: default user can not create already created target" {
run create_tcp_target $DEFAULT_P_ID 22 $TGT_NAME
[ "$status" -eq 1 ]
}
@test "boundary/target: default user can read created target" {
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
run read_target $id
[ "$status" -eq 0 ]
}
@test "boundary/target: default user can add default host set to created target" {
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
run assoc_host_sets $id $DEFAULT_HOST_SET
echo "$output"
[ "$status" -eq 0 ]
}
@test "boundary/target: default user can connect to created target" {
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
run connect_nc $id
echo "connecting to $id: $output"
[ "$status" -eq 0 ]
}
@test "boundary/target: default user can delete target" {
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
run delete_target $id
[ "$status" -eq 0 ]
}
@test "boundary/target: default user can not read deleted target" {
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
run read_target $id
[ "$status" -eq 1 ]
}
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env bats
load _accounts
load _auth
load _users
load _helpers
export NEW_USER='test'
@test "boundary/login: can login as default user" {
run login $DEFAULT_USER
[ "$status" -eq 0 ]
}
@test "boundary/users: can add $NEW_USER user" {
run create_user $NEW_USER
[ "$status" -eq 0 ]
}
@test "boundary/users: can not add already created $NEW_USER user" {
run create_user $NEW_USER
[ "$status" -eq 1 ]
}
@test "boundary/users: can read $NEW_USER user" {
local uid=$(user_id $NEW_USER)
run read_user $uid
[ "$status" -eq 0 ]
}
@test "boundary/account/password: can add $NEW_USER account" {
run create_account $NEW_USER
[ "$status" -eq 0 ]
}
@test "boundary/account/password: can not add already created $NEW_USER account" {
run create_account $NEW_USER
[ "$status" -eq 1 ]
}
@test "boundary/account/password: can read created $NEW_USER account" {
local aid=$(account_id $NEW_USER)
run read_account $aid
[ "$status" -eq 0 ]
}
@test "boundary/user/account-add: can associate $NEW_USER account with $NEW_USER user" {
local uid=$(user_id $NEW_USER)
local aid=$(account_id $NEW_USER)
run assoc_user_acct $aid $uid
[ "$status" -eq 0 ]
}
@test "boundary/login: can login as $NEW_USER user" {
run login $NEW_USER
[ "$status" -eq 0 ]
}
@test "boundary/user: can delete $NEW_USER user" {
login $DEFAULT_USER
local uid=$(user_id $NEW_USER)
run delete_user $uid
[ "$status" -eq 0 ]
}
@test "boundary/user: can not delete already deleted $NEW_USER user" {
login $DEFAULT_USER
local uid=$(user_id $NEW_USER)
run delete_user $uid
[ "$status" -eq 1 ]
}
@test "boundary/users: can not read deleted $NEW_USER user" {
local uid=$(user_id $NEW_USER)
run read_user $uid
[ "$status" -eq 1 ]
}
@test "boundary/account/password: can delete $NEW_USER account" {
local aid=$(account_id $NEW_USER)
run delete_account $aid
[ "$status" -eq 0 ]
}
@test "boundary/account/password: can not delete already deleted $NEW_USER account" {
local aid=$(account_id $NEW_USER)
run delete_account $aid
[ "$status" -eq 1 ]
}
@test "boundary/account/password: can not read deleted $NEW_USER account" {
local aid=$(account_id $NEW_USER)
run read_account $aid
[ "$status" -eq 1 ]
}