Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions authentikos/test/integ-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,51 @@ get_tokeninfo() {
curl -sSfL "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=$token"
}

run_test() {
set -x
run_test() { (
set -ex

local tokeninfo="$1"

echo "Test 'tokeninfo' response body exists"
test -n "$tokeninfo"

echo "Test 'error' is null"
echo "$tokeninfo" | jq -r '.error' | xargs -r -I% test % = "null"
test "$(echo "$tokeninfo" | jq -r '.error')" = "null"

echo "Test 'issued_to' exists"
echo "$tokeninfo" | jq -r '.issued_to' | xargs -r test -n
test -n "$(echo "$tokeninfo" | jq -r '.issued_to')"

echo "Test 'audience' exists"
echo "$tokeninfo" | jq -r '.audience' | xargs -r test -n
test -n "$(echo "$tokeninfo" | jq -r '.audience')"

echo "Test 'user_id' exists"
echo "$tokeninfo" | jq -r '.user_id' | xargs -r test -n
test -n "$(echo "$tokeninfo" | jq -r '.user_id')"

echo "Test 'email' exists"
echo "$tokeninfo" | jq -r '.email' | xargs -r test -n
test -n "$(echo "$tokeninfo" | jq -r '.email')"

echo "Test 'expires_in' greater than 0"
echo "$tokeninfo" | jq -r '.expires_in' | xargs -r -I% test % -lt 0
test "$(echo "$tokeninfo" | jq -r '.expires_in')" -gt 0

echo "Test 'scope' includes 'userinfo.email', 'cloud-platform', and 'openid'"
echo "$tokeninfo" | jq -r '.scope' |
grep -w "openi" |
grep -w "openid" |
grep -w "https://www.googleapis.com/auth/cloud-platform" |
grep -w "https://www.googleapis.com/auth/userinfo.email" >/dev/null
}
); }

main() {
kubectl create secret generic service-account --from-file="service-account.json=$GOOGLE_APPLICATION_CREDENTIALS"
kubectl apply --filename="$ROOT/testdata/authentikos-simple.yaml"
kubectl wait deployment authentikos --for="condition=available" --timeout="$timout"

run_test "$(with_timeout get_tokeninfo "$timout")"
# Unset "errexit" to allow execution to continue if "run_test" fails.
set +e
run_test "$(with_timeout get_tokeninfo "$timout")"; exit_code="$?"
set -e

kubectl logs -l app=authentikos
}

main
exit "$exit_code"