Skip to content

Commit

Permalink
Update tests to work with the mock AAI
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Feb 6, 2025
1 parent e6c96dd commit d96099a
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 87 deletions.
51 changes: 45 additions & 6 deletions .github/integration/scripts/make_sda_credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,58 @@ done
mkdir -p /shared/keys/pub
if [ ! -f "/shared/keys/jwt.key" ]; then
echo "creating jwt key"
openssl ecparam -genkey -name prime256v1 -noout -out /shared/keys/jwt.key
openssl ec -in /shared/keys/jwt.key -outform PEM -pubout >/shared/keys/pub/jwt.pub
cat << 'EOF' > /shared/keys/jwt.key
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDhuZjxPmOGUIW1
LhxzKfxkN+1aTbvI5w+AptqT33X+bWuzfjvhEodiNz0bBfQgJJpQ3TZ8J1IZpM2F
Tnzox+FGxKPe5T9Mgngzd4N6eByWVPXoNMk7IdmBXMdPZBFSyjMW4ba1MELCpiKV
05de4J5opRDwmHmyMqYJxBk78e3iiYYixVk+j1Ku+yFl4d2R29y2+O9PlZegJloe
8FGnKIGZApS/8t9iyCkXg8WbjSPzgYCTQKxn/E4lcGdTrAt/McKrWmAuppcr+rpP
+BInm3l5Zu/QiRSZcMb5O460ojP9eKnaUlDpGZv9CY5j4x4lq8vjU2kK77YXBO8I
2oxse5a5AgMBAAECggEABbwSX6anHqVzECxQurhJWj51gELTT4JXSXxztygJNmKP
RushGFHBMMSYf9RB5IMpjH5iQPs6wb4HHqjk0YEqfwLF6wbF+eqipSQXKghdKZCV
AsY8io0MmpXB1omDSygp7h3j52yHdayE2muav+VTAPOYn5QwG0/gGgVqYrR9x7CM
iTuyOIuGNO4Wlly4/5RhLtSo0pal9AgBvX4crtVEwN8tPgqPVo9w71bSROt9EVNI
3cZiFFrrapYiifckIGiPGQYQUd5ej9Mq/77Fa0f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gKCAQEA4bmY8T5jhlCFtS4ccyn8
ZDftWk27yOcPgKbak991/m1rs3474RKHYjc9GwX0ICSaUN02fCdSGaTNhU586Mfh
RsSj3uU/TIJ4M3eDengcllT16DTJOyHZgVzHT2QRUsozFuG2tTBCwqYildOXXuCe
aKUQ8Jh5sjKmCcQZO/Ht4omGIsVZPo9SrvshZeHdkdvctvjvT5WXoCZaHvBRpyiB
mQKUv/LfYsgpF4PFm40j84GAk0CsZ/xOJXBnU6wLfzHCq1pgLqaXK/q6T/gSJ5t5
eWbv0IkUmXDG+TuOtKIz/Xip2lJQ6Rmb/QmOY+MeJavL41NpCu+2FwTvCNqMbHuW
uQIDAQAB
-----END PUBLIC KEY-----
EOF
chmod 644 /shared/keys/pub/jwt.pub /shared/keys/jwt.key
fi

echo "creating token"
token="$(python /scripts/sign_jwt.py)"
python /scripts/sign_jwt.py [email protected] > "/shared/token"

cat >/shared/s3cfg <<EOD
[default]
access_key=test_dummy.org
secret_key=test_dummy.org
access_token=$token
access_key=test@dummy.org
secret_key=test@dummy.org
access_token="$(python /scripts/sign_jwt.py [email protected])"
check_ssl_certificate = False
check_ssl_hostname = False
encoding = UTF-8
Expand Down
13 changes: 7 additions & 6 deletions .github/integration/scripts/sign_jwt.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
from datetime import date, timedelta
from joserfc import jwt
from joserfc.jwk import ECKey
from joserfc.jwk import RSAKey
from pathlib import Path
import sys

p = Path('/shared/keys/jwt.key')
raw = p.read_text()
key = ECKey.import_key(raw)
key = RSAKey.import_key(raw)
iat = date.today() - timedelta(days=1)
exp = date.today() + timedelta(days=1)

header = {
'alg': 'ES256',
'kid': key.thumbprint(),
'alg': 'RS256',
'kid': 'rsa1',
'typ': 'JWT'
}

payload = {
'aud': 'XC56EL11xx',
'exp': exp.strftime('%s'),
'iat': iat.strftime('%s'),
'iss': 'http://oidc',
'sub': '[email protected]'
'iss': 'http://localhost',
'sub': sys.argv[1]
}

token = jwt.encode(header, payload, key)
Expand Down
44 changes: 9 additions & 35 deletions .github/integration/sda-s3-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ services:
condition: service_completed_successfully
minio:
condition: service_healthy
oidc:
mock-aai:
condition: service_healthy
postgres:
condition: service_healthy
Expand Down Expand Up @@ -211,39 +211,6 @@ services:
- ./sda/config.yaml:/config.yaml
- shared:/shared

oidc:
container_name: oidc
command:
- /bin/sh
- -c
- |
pip install --upgrade pip
pip install aiohttp Authlib joserfc requests
python -u /oidc.py
depends_on:
credentials:
condition: service_completed_successfully
extra_hosts:
- "localhost:host-gateway"
healthcheck:
test:
[
"CMD",
"python3",
"-c",
'import requests; print(requests.get(url = "http://localhost:8080/jwk").text)',
]
interval: 10s
timeout: 2s
retries: 6
image: python:3.11-slim
ports:
- "8080:8080"
restart: always
volumes:
- ./sda/oidc.py:/oidc.py
- shared:/shared

api:
command: [sda-api]
container_name: api
Expand All @@ -252,7 +219,7 @@ services:
condition: service_completed_successfully
postgres:
condition: service_healthy
oidc:
mock-aai:
condition: service_healthy
rabbitmq:
condition: service_healthy
Expand Down Expand Up @@ -348,6 +315,7 @@ services:
volumes:
- ./sda/config.yaml:/config.yaml
- shared:/shared

mock-aai:
container_name: ls-aai-mock
depends_on:
Expand All @@ -357,6 +325,12 @@ services:
- DOCKERHOST=localhost
extra_hosts:
- "localhost:host-gateway"
healthcheck:
test:
[ "CMD", "/bin/true" ]
interval: 10s
timeout: 2s
retries: 6
image: registry.gitlab.ics.muni.cz:443/perun/deployment/proxyidp/proxyidp-public-docker-images/ls_aai_mock:2.5.2-broker2.1.10-tomcat9.0-jdk11
ports:
- "8800:8080"
Expand Down
2 changes: 1 addition & 1 deletion .github/integration/sda/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ auth:
jwt:
issuer: "https://auth:8888"
privateKey: /shared/keys/jwt.key
signatureAlg: ES256
signatureAlg: RS256
tokenTTL: 168
publicFile: "/shared/c4gh.pub.pem"
resignJwt:
Expand Down
2 changes: 1 addition & 1 deletion .github/integration/sda/rbac.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"rolebinding": "submission"
},
{
"role": "[email protected]",
"role": "[email protected]",
"rolebinding": "admin"
}
]
Expand Down
34 changes: 0 additions & 34 deletions .github/integration/tests/sda/10_upload_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,4 @@ if [ "$num_log_rows" -ne 12 ]; then
exit 1
fi

## test with token from OIDC service
echo "testing with OIDC token"
newToken=$(curl http://oidc:8080/tokens | jq '.[0]')
cp s3cfg oidc_s3cfg
sed -i "s/access_token=.*/access_token=$newToken/" oidc_s3cfg

s3cmd -c oidc_s3cfg put NA12878.bam.c4gh s3://requester_demo.org/data/file1.c4gh

## verify that messages exists in MQ
echo "waiting for upload to complete"
RETRY_TIMES=0
until [ "$(curl -s -k -u guest:guest $URI/api/queues/sda/inbox | jq -r '."messages_ready"')" -eq 7 ]; do
echo "waiting for upload to complete"
RETRY_TIMES=$((RETRY_TIMES + 1))
if [ "$RETRY_TIMES" -eq 30 ]; then
echo "::error::Time out while waiting for upload to complete"
exit 1
fi
sleep 2
done

num_rows=$(psql -U postgres -h postgres -d sda -At -c "SELECT COUNT(*) from sda.files;")
if [ "$num_rows" -ne 6 ]; then
echo "database queries for register_files failed, expected 6 got $num_rows"
exit 1
fi

num_log_rows=$(psql -U postgres -h postgres -d sda -At -c "SELECT COUNT(*) from sda.file_event_log;")
if [ "$num_log_rows" -ne 14 ]; then
echo "database queries for file_event_logs failed, expected 14 got $num_log_rows"
exit 1
fi


echo "files uploaded successfully"
4 changes: 2 additions & 2 deletions .github/integration/tests/sda/11_api_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -e

# Test the API files endpoint
token="$(curl -s 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')"
token="$(cat /shared/token)"
response="$(curl -s -k -L "http://api:8080/users/[email protected]/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
Expand Down
2 changes: 1 addition & 1 deletion .github/integration/tests/sda/40_mapper_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ done


## Use API to list the datasets
token="$(curl http://oidc:8080/tokens | jq -r '.[0]')"
token="$(cat /shared/token)"
resp="$(curl -s -k -L -H "Authorization: Bearer $token" -X GET "http://api:8080/datasets/list" | jq '. | length')"
if [ "$resp" -ne 2 ]; then
echo "Error when listing key hash, expected 2 entries got: $resp"
Expand Down
2 changes: 1 addition & 1 deletion .github/integration/tests/sda/60_api_admin_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
cd shared || true

token="$(curl http://oidc:8080/tokens | jq -r '.[0]')"
token="$(cat /shared/token)"
# Upload a file and make sure it's listed
result="$(curl -sk -L "http://api:8080/users/[email protected]/files" -H "Authorization: Bearer $token" | jq '. | length')"
if [ "$result" -ne 2 ]; then
Expand Down

0 comments on commit d96099a

Please sign in to comment.