test: add functions variant usable with JWT without providing ORG ID

Common integration tests should not need to care about specific ORG ID
configured in the worker, but they should be able to get access token
and check compose status without providing a specific ORG ID. The only
integration test that should care about ORG ID is the
`multi-tenancy.sh`.

Modify the `access_token` and `compose_status` functions to hide the
existence of ORG ID from the user and instead read it from the worker's
configuration, specifically `/etc/osbuild-worker/token`.

The original implementations of the functions mentioned above are now
available under `access_token_with_org_id` and
`compose_status_with_org_id` names.

Modify the `multi-tenancy.sh` to use the new function names.
This commit is contained in:
Tomas Hozza 2022-07-25 13:02:31 +02:00 committed by Ondřej Budai
parent 765d218b6f
commit 4b96a79935
2 changed files with 27 additions and 7 deletions

View file

@ -45,9 +45,19 @@ function _instanceCheck() {
fi
}
# Fetch a JWT token
WORKER_REFRESH_TOKEN_PATH="/etc/osbuild-worker/token"
# Fetch a JWT token.
# The token is fetched using the refresh token configured in the worker.
function access_token {
# Refresh token represents the ORG ID
local refresh_token
refresh_token="$(cat $WORKER_REFRESH_TOKEN_PATH)"
access_token_with_org_id "$refresh_token"
}
# Fetch a JWT token.
# The token is fetched using the refresh token provided as an argument.
function access_token_with_org_id {
local refresh_token="$1"
curl --request POST \
--data "refresh_token=$refresh_token" \
@ -58,14 +68,24 @@ function access_token {
localhost:8081/token | jq -r .access_token
}
# Get the compose status using a JWT token
# Get the compose status using a JWT token.
# The token is fetched using the refresh token configured in the worker.
function compose_status {
local compose="$1"
local refresh_token
refresh_token="$(cat $WORKER_REFRESH_TOKEN_PATH)"
compose_status_with_org_id "$compose" "$refresh_token"
}
# Get the compose status using a JWT token.
# The token is fetched using the refresh token provided as the second argument.
function compose_status_with_org_id {
local compose="$1"
local refresh_token="$2"
curl \
--silent \
--show-error \
--fail \
--header "Authorization: Bearer $(access_token "$refresh_token")" \
--header "Authorization: Bearer $(access_token_with_org_id "$refresh_token")" \
"http://localhost:443/api/image-builder-composer/v2/composes/$compose"
}

View file

@ -114,7 +114,7 @@ function send_compose {
--show-error \
--fail \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $(access_token "$refresh_token")" \
--header "Authorization: Bearer $(access_token_with_org_id "$refresh_token")" \
--request POST \
--data @"$request_file" \
http://localhost:443/api/image-builder-composer/v2/compose | jq -r '.id'
@ -124,7 +124,7 @@ function assert_status {
local compose="$1"
local refresh_token="$2"
local status="$3"
[[ $(compose_status "$compose" "$refresh_token" | jq -r '.status') == "$status" ]]
[[ $(compose_status_with_org_id "$compose" "$refresh_token" | jq -r '.status') == "$status" ]]
}
function wait_for_status {
@ -134,7 +134,7 @@ function wait_for_status {
while true
do
local current_status
current_status=$(compose_status "$compose" "$refresh_token" | jq -r '.status')
current_status=$(compose_status_with_org_id "$compose" "$refresh_token" | jq -r '.status')
case "$current_status" in
"$desired_status")