2020-10-12 20:57:57 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
|
|
load _accounts
|
|
|
|
|
load _auth
|
|
|
|
|
load _roles
|
|
|
|
|
load _helpers
|
|
|
|
|
|
|
|
|
|
export NEW_ROLE='test'
|
2023-10-17 13:42:11 -04:00
|
|
|
export NEW_GRANT='ids=*;type=*;actions=create,read,update,delete,list'
|
2020-10-12 20:57:57 -07:00
|
|
|
|
|
|
|
|
@test "boundary/login: can login as default principal" {
|
|
|
|
|
run login $DEFAULT_LOGIN
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "boundary/roles: can add $NEW_ROLE role to global scope granting rights in default org scope" {
|
2024-06-17 12:09:33 -07:00
|
|
|
run create_role $DEFAULT_GLOBAL $NEW_ROLE
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
|
|
run set_grant_scopes $DEFAULT_GLOBAL $NEW_ROLE $DEFAULT_O_ID
|
2020-10-12 20:57:57 -07:00
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "boundary/roles: can not add already created $NEW_ROLE role" {
|
2024-06-17 12:09:33 -07:00
|
|
|
run create_role $DEFAULT_GLOBAL $NEW_ROLE
|
2020-10-12 20:57:57 -07:00
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "boundary/roles: can read $NEW_ROLE role" {
|
|
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run read_role $rid
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-29 08:04:46 -08:00
|
|
|
@test "boundary/roles: the $NEW_ROLE role contains default authorized-actions" {
|
|
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
local out=$(read_role $rid)
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
run has_default_role_actions "$out"
|
2021-01-29 08:04:46 -08:00
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
@test "boundary/role/add-principals: can associate $NEW_ROLE role with default principal" {
|
2020-10-12 20:57:57 -07:00
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run assoc_role_principal $DEFAULT_USER $rid
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
@test "boundary/role/add-principals: $NEW_ROLE role contains default principal" {
|
2020-10-12 20:57:57 -07:00
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run role_has_principal_id $rid $DEFAULT_USER
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
@test "boundary/role/remove-principals: can remove default principal from $NEW_ROLE role" {
|
2020-10-12 20:57:57 -07:00
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run remove_role_principal $DEFAULT_USER $rid
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
@test "boundary/role/remove-principals: $NEW_ROLE role no longer contains default principal" {
|
2020-10-12 20:57:57 -07:00
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run role_has_principal_id $rid $DEFAULT_USER
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
@test "boundary/role/add-grants: can associate $NEW_ROLE role with $NEW_GRANT grant" {
|
2020-10-12 20:57:57 -07:00
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run assoc_role_grant $NEW_GRANT $rid
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
@test "boundary/role/add-grantss: $NEW_ROLE role contains $NEW_GRANT grant" {
|
2020-10-12 20:57:57 -07:00
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run role_has_grant $rid $NEW_GRANT
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
@test "boundary/role/remove-grants: can remove $NEW_GRANT grant from $NEW_ROLE role" {
|
2020-10-12 20:57:57 -07:00
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run remove_role_grant $NEW_GRANT $rid
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 14:48:51 -06:00
|
|
|
@test "boundary/role/remove-grants: $NEW_ROLE role no longer contains $NEW_GRANT grant" {
|
2020-10-12 20:57:57 -07:00
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run role_has_grant $rid $NEW_GRANT
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "boundary/role: can delete $NEW_ROLE role" {
|
|
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
2022-07-28 14:48:51 -06:00
|
|
|
run delete_role $rid
|
2020-10-12 20:57:57 -07:00
|
|
|
echo "$output"
|
2021-10-19 17:21:41 -04:00
|
|
|
run has_status_code "$output" "204"
|
2020-10-12 20:57:57 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "boundary/roles: can not read deleted $NEW_ROLE role" {
|
|
|
|
|
local rid=$(role_id $NEW_ROLE $DEFAULT_GLOBAL)
|
|
|
|
|
run read_role $rid
|
|
|
|
|
echo "$output"
|
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
}
|