Skip to content

Commit

Permalink
Add Auth to Curl in Integration Test
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianschaffer committed Nov 22, 2024
1 parent 463c016 commit f947733
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/integration-test/basic-auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Image is uses as base for a dummy container from which curl can request data within the same network as the other containers
FROM alpine
RUN apk add --no-cache curl
CMD ["sh", "-c", "while true; do sleep 3600; done"]
4 changes: 4 additions & 0 deletions .github/integration-test/basic-auth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@ services:
volumes:
- "${FDE_INPUT_MEASURE:-../Documentation/example-measures/example-measure-kds.json}:/app/measure.json"
- "${FDE_OUTPUT_DIR:-../output}:/app/output"
curl-tester: # dummy container from which curl can request data within the same network as the other containers
build: .
entrypoint: [ "tail", "-f", "/dev/null" ]
command: ""
volumes:
data-store-data:
38 changes: 36 additions & 2 deletions .github/integration-test/evaluate-and-post-different-doc-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,42 @@ export FDE_SEND_REPORT_TO_SERVER=true

docker compose -f "$DOCKER_COMPOSE_FILE" run -e TZ="$(cat /etc/timezone)" fhir-data-evaluator

reference_response=$(curl -s "http://localhost:8082/fhir/DocumentReference" \
-H "Content-Type: application/fhir+json")
get_response() {
URL="$1"
CURL_TESTER_ID=$(docker ps --filter "name=$AUTH-curl-tester-1" --format "{{.ID}}")
if [ "$AUTH" == "no-auth" ]; then
response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'http://fhir-server:8080/fhir/$URL' -H 'Content-Type: application/fhir+json'")
echo "$response"
elif [ "$AUTH" == "basic-auth" ]; then
response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'http://proxy:8080/fhir/$URL' \
-H 'Content-Type: application/fhir+json' \
-u 'test:bar'")
echo "$response"
else
docker exec "$CURL_TESTER_ID" sh -c "
cp /app/certs/cert.pem /usr/local/share/ca-certificates/cert.crt &&
update-ca-certificates"

oauth_response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s -X POST 'https://secure-keycloak:8443/realms/test/protocol/openid-connect/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials' \
-d 'client_id=account' \
-d 'client_secret=test'")
FHIR_DESTINATION_BEARER_TOKEN=$(echo "$oauth_response" | jq -r '.access_token')

response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'https://secure-fhir-server:8443/fhir/$URL' \
-H 'Content-Type: application/fhir+json' \
-H 'Authorization: Bearer $FHIR_DESTINATION_BEARER_TOKEN'")

echo "$response"
fi
}

reference_response=$(get_response "DocumentReference")

reference_count=$(echo "$reference_response" | jq -r '.entry | length')

Expand Down
44 changes: 38 additions & 6 deletions .github/integration-test/evaluate-and-post-report.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash -e

AUTH="$1"
DOCKER_COMPOSE_FILE=.github/integration-test/"$1"/docker-compose.yml
PROJECT_IDENTIFIER_VALUE="$2"
export FDE_INPUT_MEASURE=/${PWD}/.github/integration-test/measures/icd10-measure.json
Expand All @@ -14,13 +15,44 @@ export FDE_SEND_REPORT_TO_SERVER=true
mkdir "$FDE_OUTPUT_DIR"
docker compose -f "$DOCKER_COMPOSE_FILE" run -e TZ="$(cat /etc/timezone)" fhir-data-evaluator

report_response=$(curl -s "http://localhost:8082/fhir/MeasureReport" \
-H "Content-Type: application/fhir+json")
echo "report response: $report_response"
get_response() {
URL="$1"
CURL_TESTER_ID=$(docker ps --filter "name=$AUTH-curl-tester-1" --format "{{.ID}}")
if [ "$AUTH" == "no-auth" ]; then
response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'http://fhir-server:8080/fhir/$URL' -H 'Content-Type: application/fhir+json'")
echo "$response"
elif [ "$AUTH" == "basic-auth" ]; then
response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'http://proxy:8080/fhir/$URL' \
-H 'Content-Type: application/fhir+json' \
-u 'test:bar'")
echo "$response"
else
docker exec "$CURL_TESTER_ID" sh -c "
cp /app/certs/cert.pem /usr/local/share/ca-certificates/cert.crt &&
update-ca-certificates"

reference_response=$(curl -s "http://localhost:8082/fhir/DocumentReference" \
-H "Content-Type: application/fhir+json")
echo "reference response: $reference_response"
oauth_response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s -X POST 'https://secure-keycloak:8443/realms/test/protocol/openid-connect/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials' \
-d 'client_id=account' \
-d 'client_secret=test'")
FHIR_DESTINATION_BEARER_TOKEN=$(echo "$oauth_response" | jq -r '.access_token')

response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'https://secure-fhir-server:8443/fhir/$URL' \
-H 'Content-Type: application/fhir+json' \
-H 'Authorization: Bearer $FHIR_DESTINATION_BEARER_TOKEN'")

echo "$response"
fi
}

report_response=$(get_response "MeasureReport")

reference_response=$(get_response "DocumentReference")

report_url=MeasureReport/$(echo "$report_response" | jq -r '.entry[0].resource.id')
reference_url=$(echo "$reference_response" | jq -r '.entry[0].resource.content[0].attachment.url')
Expand Down
41 changes: 38 additions & 3 deletions .github/integration-test/evaluate-and-post-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,44 @@ export FDE_PROJECT_IDENTIFIER_SYSTEM=http://medizininformatik-initiative.de/sid/
export FDE_PROJECT_IDENTIFIER_VALUE="$PROJECT_IDENTIFIER_VALUE"
export FDE_SEND_REPORT_TO_SERVER=true

reference_response=$(curl -s "http://localhost:8082/fhir/DocumentReference" \
-H "Content-Type: application/fhir+json")
reference_url_before=$(echo "$reference_response" | jq -r '.entry[0].resource.content[0].attachment.url')
get_response() {
URL="$1"
CURL_TESTER_ID=$(docker ps --filter "name=$AUTH-curl-tester-1" --format "{{.ID}}")
if [ "$AUTH" == "no-auth" ]; then
response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'http://fhir-server:8080/fhir/$URL' -H 'Content-Type: application/fhir+json'")
echo "$response"
elif [ "$AUTH" == "basic-auth" ]; then
response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'http://proxy:8080/fhir/$URL' \
-H 'Content-Type: application/fhir+json' \
-u 'test:bar'")
echo "$response"
else
docker exec "$CURL_TESTER_ID" sh -c "
cp /app/certs/cert.pem /usr/local/share/ca-certificates/cert.crt &&
update-ca-certificates"

oauth_response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s -X POST 'https://secure-keycloak:8443/realms/test/protocol/openid-connect/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials' \
-d 'client_id=account' \
-d 'client_secret=test'")
FHIR_DESTINATION_BEARER_TOKEN=$(echo "$oauth_response" | jq -r '.access_token')

response=$(docker exec "$CURL_TESTER_ID" sh -c "
curl -s 'https://secure-fhir-server:8443/fhir/$URL' \
-H 'Content-Type: application/fhir+json' \
-H 'Authorization: Bearer $FHIR_DESTINATION_BEARER_TOKEN'")

echo "$response"
fi
}

report_response=$(get_response "MeasureReport")

reference_response=$(get_response "DocumentReference")

docker compose -f "$DOCKER_COMPOSE_FILE" run -e TZ="$(cat /etc/timezone)" fhir-data-evaluator

Expand Down
4 changes: 4 additions & 0 deletions .github/integration-test/no-auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Image is uses as base for a dummy container from which curl can request data within the same network as the other containers
FROM alpine
RUN apk add --no-cache curl
CMD ["sh", "-c", "while true; do sleep 3600; done"]
4 changes: 4 additions & 0 deletions .github/integration-test/no-auth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ services:
volumes:
- "${FDE_INPUT_MEASURE:-../Documentation/example-measures/example-measure-kds.json}:/app/measure.json"
- "${FDE_OUTPUT_DIR:-../output}:/app/output"
curl-tester: # dummy container from which curl can request data within the same network as the other containers
build: .
entrypoint: ["tail", "-f", "/dev/null"]
command: ""

volumes:
data-store-data:
4 changes: 4 additions & 0 deletions .github/integration-test/oauth/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Image is uses as base for a dummy container from which curl can request data within the same network as the other containers
FROM alpine
RUN apk add --no-cache curl
CMD ["sh", "-c", "while true; do sleep 3600; done"]
8 changes: 8 additions & 0 deletions .github/integration-test/oauth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ services:
- "${FDE_INPUT_MEASURE:-../Documentation/example-measures/example-measure-kds.json}:/app/measure.json"
- "${FDE_OUTPUT_DIR:-../output}:/app/output"
- "certs:/app/certs"
curl-tester: # dummy container from which curl can request data within the same network as the other containers
build: .
entrypoint: [ "tail", "-f", "/dev/null" ]
command: ""
networks:
test-oauth:
volumes:
- "certs:/app/certs"
volumes:
data-store-data:
certs:
Expand Down

0 comments on commit f947733

Please sign in to comment.