Add read:self and delete:self to auth tokens and add logout command (#1162)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-04-23 13:45:08 -04:00
1 parent 3fe94335d4
commit e6af51943d
20 files changed
+966 -223

No files matched your search

@@ -0,0 +1,34 @@
function read_token() {
if [[ "x$1" == "x" ]]
then
echo "y" | boundary auth-tokens read
else
boundary auth-tokens read -id $1
fi
}
function delete_token() {
if [[ "x$1" == "x" ]]
then
echo "y" | boundary auth-tokens delete
else
boundary auth-tokens delete -id $1
fi
}
function token_id() {
local tid=$1
strip $(read_token $tid | jq '.item.id')
}
function logout_cmd() {
boundary logout
}
function get_token() {
boundary config get-token
}
function read_token_no_keyring() {
boundary auth-tokens read -keyring-type=none -id $1
}
@@ -0,0 +1,72 @@
#!/usr/bin/env bats
load _auth
load _auth_tokens
load _helpers
export NEW_USER='test'
@test "boundary/token: can login as unpriv user" {
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
}
@test "boundary/token: can read own token with no id given" {
run read_token ""
[ "$status" -eq 0 ]
}
@test "boundary/token: can read own token with self given" {
run read_token "self"
[ "$status" -eq 0 ]
}
@test "boundary/token: can read own token id given" {
local tid=$(token_id "self")
run read_token "$tid"
[ "$status" -eq 0 ]
}
@test "boundary/token: can delete own token with no id given" {
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run delete_token ""
[ "$status" -eq 0 ]
run read_token ""
[ "$status" -eq 1 ]
}
@test "boundary/token: can delete own token with self given" {
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run delete_token "self"
[ "$status" -eq 0 ]
run read_token ""
[ "$status" -eq 1 ]
}
@test "boundary/token: can delete own token with id given" {
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run token_id "self"
[ "$status" -eq 0 ]
tid=$(echo "$output")
run delete_token $tid
[ "$status" -eq 0 ]
run read_token $tid
[ "$status" -eq 1 ]
}
@test "boundary/token/logout: can logout" {
run login $DEFAULT_UNPRIVILEGED_LOGIN
[ "$status" -eq 0 ]
run get_token
[ "$status" -eq 0 ]
local tid=$(token_id "self")
run logout_cmd
[ "$status" -eq 0 ]
run get_token
[ "$status" -eq 2 ]
run read_token_no_keyring $tid
[ "$status" -eq 1 ]
}
-2
View File
@@ -49,8 +49,6 @@ export NEW_GRANT='id=*;type=*;actions=create,read,update,delete,list'
[ "$status" -eq 0 ]
}
@test "boundary/role/add-principals: $NEW_ROLE role contains default principal" {
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
run role_has_principal_id $rid $DEFAULT_USER