From 61c49255301cf9ad5ca997836211db4a776d36a2 Mon Sep 17 00:00:00 2001 From: Leandro Doctors Date: Sat, 14 Dec 2024 13:18:04 +0100 Subject: [PATCH] Fix Failing Binary Emit case The body should contain a JSON payload with the OperationOutcome, not the OperationOutcome itself. We use JSON because it is our default. --- .../read-binary-content-via-json-invalid.sh | 90 +++++++++++++++++++ .github/workflows/build.yml | 3 + .../src/blaze/middleware/fhir/output.clj | 2 +- .../blaze/middleware/fhir/output_test.clj | 6 +- 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100755 .github/scripts/read-binary-content-via-json-invalid.sh diff --git a/.github/scripts/read-binary-content-via-json-invalid.sh b/.github/scripts/read-binary-content-via-json-invalid.sh new file mode 100755 index 000000000..71a86db50 --- /dev/null +++ b/.github/scripts/read-binary-content-via-json-invalid.sh @@ -0,0 +1,90 @@ +#!/bin/bash -e + +# This script creates a binary resource with invalid data and verifies that, +# when trying to read its binary content, an error is generated. + +BASE="http://localhost:8080/fhir" + +# 10 KiB of random data, base64 encoded +ORIGINAL_DATA="$(openssl rand -base64 10240 | tr -d '\n')" + + +# Higher-order function to apply a transformation based on a condition +apply_generic_transformation() { + local data="$1" + local transform_function="$2" + + local result="" + + # Iterate over the data and apply the transform function + for i in $(seq 0 ${#data}-1); do + result+=$(eval "$transform_function \"${data:$i:1}\" $i") + done + + echo "$result" +} + +remove_parts_transform() { + local char="$1" + local index="$2" + + # Randomly decide whether to remove this character (skip it) + if (( RANDOM % 10 == 0 )); then + echo "" # Skip (remove this character) + else + echo "$char" # Keep the character + fi +} + +insert_non_base64_transform() { + local char="$1" + local index="$2" + + # Every 5th character, insert a random non-base64 character + if (( index % 5 == 0 )); then + echo "$((RANDOM % 10))" # Insert a non-base64 digit + else + echo "$char" # Keep the character + fi +} + +# Apply Remove Parts of the Data +FAULTY_DATA=$(apply_generic_transformation "$ORIGINAL_DATA" "remove_parts_transform") +# echo "Faulty Data (Removed Parts): $FAULTY_DATA" + +# Apply Insert Non-Base64 Characters +FAULTY_DATA=$(apply_generic_transformation "$FAULTY_DATA" "insert_non_base64_transform") +# echo "Faulty Data (also with Non-Base64 Characters): $FAULTY_DATA" + +DATA=$FAULTY_DATA + + +binary() { +cat <