Skip to content

Commit

Permalink
Update API integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Oct 21, 2024
1 parent 8cadbb4 commit 619cd9f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
5 changes: 2 additions & 3 deletions .github/integration/sda-s3-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,8 @@ services:
rabbitmq:
condition: service_healthy
environment:
- BROKER_PASSWORD=ingest
- BROKER_USER=ingest
- BROKER_ROUTINGKEY=ingest
- BROKER_PASSWORD=api
- BROKER_USER=api
- DB_PASSWORD=api
- DB_USER=api
image: ghcr.io/neicnordic/sensitive-data-archive:PR${PR_NUMBER}
Expand Down
15 changes: 15 additions & 0 deletions .github/integration/tests/sda/01_install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -e

# install tools if missing
for t in curl expect jq openssh-client postgresql-client xxd; do
if [ ! "$(command -v $t)" ]; then
if [ "$(id -u)" != 0 ]; then
echo "$t is missing, unable to install it"
exit 1
fi

apt-get -o DPkg::Lock::Timeout=60 update >/dev/null
apt-get -o DPkg::Lock::Timeout=60 install -y "$t" >/dev/null
fi
done
14 changes: 0 additions & 14 deletions .github/integration/tests/sda/09_healthchecks.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
#!/bin/sh
set -e

# install tools if missing
for t in curl jq ; do
if [ ! "$(command -v $t)" ]; then
if [ "$(id -u)" != 0 ]; then
echo "$t is missing, unable to install it"
exit 1
fi

apt-get -o DPkg::Lock::Timeout=60 update >/dev/null
apt-get -o DPkg::Lock::Timeout=60 install -y "$t" >/dev/null
fi
done


# Test the s3inbox's healthchecks, GET /health and HEAD /
response="$(curl -s -k -LI "http://s3inbox:8000" -o /dev/null -w "%{http_code}\n")"
if [ "$response" != "200" ]; then
Expand Down
13 changes: 0 additions & 13 deletions .github/integration/tests/sda/10_upload_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ if [ -z "$STORAGETYPE" ]; then
exit 1
fi

# install tools if missing
for t in curl expect jq openssh-client postgresql-client; do
if [ ! "$(command -v $t)" ]; then
if [ "$(id -u)" != 0 ]; then
echo "$t is missing, unable to install it"
exit 1
fi

apt-get -o DPkg::Lock::Timeout=60 update >/dev/null
apt-get -o DPkg::Lock::Timeout=60 install -y "$t" >/dev/null
fi
done

cd shared || true

## verify that messages exists in MQ
Expand Down
32 changes: 30 additions & 2 deletions .github/integration/tests/sda/11_api-getfiles_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,39 @@ set -e

# Test the API files endpoint
token="$(curl http://oidc:8080/tokens | jq -r '.[0]')"
curl -k -L "http://api:8080/files" -H "Authorization: Bearer $token"
response="$(curl -k -L "http://api:8080/files" -H "Authorization: Bearer $token" | jq -r 'sort_by(.inboxPath)|.[-1].fileStatus')"
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

manual_hash=$(sed -n '2p' /shared/c4gh.pub.pem | base64 -d -w0 | xxd -c64 -ps)

db_hash=$(psql -U postgres -h postgres -d sda -At -c "SELECT key_hash FROM sda.encryption_keys WHERE description = 'this is the key description';")
if [ "$db_hash" != "$manual_hash" ]; then
echo "wrong hash in the database, expected $manual_hash got $db_hash"
exit 1
fi

echo "api test completed successfully"

0 comments on commit 619cd9f

Please sign in to comment.