Skip to content

Commit

Permalink
[integration tests] expand the tests for the API
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Nov 4, 2024
1 parent 9028513 commit 446d782
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/integration/tests/sda/10_upload_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for q in accession archived backup completed inbox ingest mappings verified; do
curl -s -k -u guest:guest -X DELETE "$URI/api/queues/sda/$q/contents"
done
## truncate database
psql -U postgres -h postgres -d sda -At -c "TRUNCATE TABLE sda.files CASCADE;"
psql -U postgres -h postgres -d sda -At -c "TRUNCATE TABLE sda.files, sda.encryption_keys CASCADE;"

pip -q install s3cmd

Expand Down
41 changes: 0 additions & 41 deletions .github/integration/tests/sda/11_api-getfiles_test.sh

This file was deleted.

76 changes: 76 additions & 0 deletions .github/integration/tests/sda/11_api_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/sh
set -e

# Test the API files endpoint
token="$(curl http://oidc:8080/tokens | jq -r '.[0]')"
response="$(curl -s -k -L "http://api:8080/files" -H "Authorization: Bearer $token" | jq -r 'sort_by(.inboxPath)|.[-1].fileStatus')"
if [ "$response" != "uploaded" ]; then
echo "API returned incorrect value, expected ready got: $response"
exit 1
fi

# test inserting a c4gh public key hash
payload=$(
jq -c -n \
--arg description "this is the key description" \
--arg pubkey "$( base64 -w0 /shared/c4gh.pub.pem)" \
'$ARGS.named'
)

resp="$(curl -s -k -L -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$payload" "http://api:8080/c4gh-keys/add")"
if [ "$resp" != "200" ]; then
echo "Error when adding a public key hash, expected 200 got: $resp"
exit 1
fi

# again to verify we get an error
resp="$(curl -s -k -L -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$payload" "http://api:8080/c4gh-keys/add")"
if [ "$resp" != "409" ]; then
echo "Error when adding a public key hash, expected 409 got: $resp"
exit 1
fi

# add key that will be deprecated
new_payload=$(
jq -c -n \
--arg description "this key will be deprecated" \
--arg pubkey "LS0tLS1CRUdJTiBDUllQVDRHSCBQVUJMSUMgS0VZLS0tLS0KTmdUdEFNLzRIUVR4b0I5bHZlRHVaYW5sRmVpWXVHRzBQTTg1eHNBU2xrZz0KLS0tLS1FTkQgQ1JZUFQ0R0ggUFVCTElDIEtFWS0tLS0tCg==" \
'$ARGS.named'
)

resp="$(curl -s -k -L -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$new_payload" "http://api:8080/c4gh-keys/add")"
if [ "$resp" != "200" ]; then
echo "Error when adding a public key hash, expected 200 got: $resp"
exit 1
fi

deprecated_hash="3604ed00cff81d04f1a01f65bde0ee65a9e515e898b861b43ccf39c6c0129648"

resp="$(curl -s -k -L -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST "http://api:8080/c4gh-keys/deprecate/$deprecated_hash")"
if [ "$resp" != "200" ]; then
echo "Error when adding a public key hash, expected 200 got: $resp"
exit 1
fi


# list key hashes
resp="$(curl -s -k -L -H "Authorization: Bearer $token" -X GET "http://api:8080/c4gh-keys/list" | jq '. | length')"
if [ "$resp" -ne 2 ]; then
echo "Error when listing key hash, expected 2 entries got: $resp"
exit 1
fi

manual_hash=$(sed -n '2p' /shared/c4gh.pub.pem | base64 -d -w0 | xxd -c64 -ps)
resp="$(curl -s -k -L -H "Authorization: Bearer $token" -X GET "http://api:8080/c4gh-keys/list" | jq -r .[0].hash)"
if [ "$resp" != "$manual_hash" ]; then
echo "Error when listing key hash, expected $manual_hash got: $resp"
exit 1
fi
ts=$(date +"%F %T")
depr="$(curl -s -k -L -H "Authorization: Bearer $token" -X GET "http://api:8080/c4gh-keys/list" | jq -r .[1].deprecated_at)"
if [ "$depr" != "$ts" ]; then
echo "Error when listing key hash, expected $ts got: $depr"
exit 1
fi

echo "api test completed successfully"

0 comments on commit 446d782

Please sign in to comment.