|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL" |
| 5 | +initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL" |
| 6 | +purge_cache "$END_USER_VARNISH_SERVICE" |
| 7 | +purge_cache "$ADMIN_VARNISH_SERVICE" |
| 8 | +purge_cache "$FRONTEND_VARNISH_SERVICE" |
| 9 | + |
| 10 | +pwd=$(realpath "$PWD") |
| 11 | + |
| 12 | +# add agent to the writers group |
| 13 | + |
| 14 | +add-agent-to-group.sh \ |
| 15 | + -f "$OWNER_CERT_FILE" \ |
| 16 | + -p "$OWNER_CERT_PWD" \ |
| 17 | + --agent "$AGENT_URI" \ |
| 18 | + "${ADMIN_BASE_URL}acl/groups/writers/" |
| 19 | + |
| 20 | +# create text file with UTF-8 characters |
| 21 | + |
| 22 | +filename="/tmp/utf8-test.md" |
| 23 | +cat > "$filename" <<'EOF' |
| 24 | +# UTF-8 Test File |
| 25 | +
|
| 26 | +This file contains UTF-8 characters: |
| 27 | +- Em dash: — |
| 28 | +- Arrow: → |
| 29 | +- Emoji: 🚀 |
| 30 | +- Accented: café, naïve |
| 31 | +EOF |
| 32 | + |
| 33 | +file_content_type="text/markdown" |
| 34 | + |
| 35 | +# Create a container for files first |
| 36 | +create-container.sh \ |
| 37 | + -f "$AGENT_CERT_FILE" \ |
| 38 | + -p "$AGENT_CERT_PWD" \ |
| 39 | + -b "$END_USER_BASE_URL" \ |
| 40 | + --title "Files" \ |
| 41 | + --parent "$END_USER_BASE_URL" \ |
| 42 | + --slug "files" |
| 43 | + |
| 44 | +# Create an item document to hold the file |
| 45 | +file_doc=$(create-item.sh \ |
| 46 | + -f "$AGENT_CERT_FILE" \ |
| 47 | + -p "$AGENT_CERT_PWD" \ |
| 48 | + -b "$END_USER_BASE_URL" \ |
| 49 | + --title "UTF-8 test file" \ |
| 50 | + --container "${END_USER_BASE_URL}files/") |
| 51 | + |
| 52 | +# Add the file to the document |
| 53 | +add-file.sh \ |
| 54 | + -f "$AGENT_CERT_FILE" \ |
| 55 | + -p "$AGENT_CERT_PWD" \ |
| 56 | + -b "$END_USER_BASE_URL" \ |
| 57 | + --title "UTF-8 test file" \ |
| 58 | + --file "$filename" \ |
| 59 | + --content-type "${file_content_type}" \ |
| 60 | + "$file_doc" |
| 61 | + |
| 62 | +# Calculate file URI from SHA1 hash |
| 63 | +sha1sum=$(shasum -a 1 "$filename" | awk '{print $1}') |
| 64 | +file="${END_USER_BASE_URL}uploads/${sha1sum}" |
| 65 | + |
| 66 | +# Get Content-Type header from the file |
| 67 | +content_type=$( |
| 68 | + curl -k -i -f -s -G \ |
| 69 | + -E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \ |
| 70 | + "$file" \ |
| 71 | +| grep -i 'Content-Type' \ |
| 72 | +| tr -d '\r' \ |
| 73 | +| sed -En 's/^[Cc]ontent-[Tt]ype: (.*)$/\1/p') |
| 74 | + |
| 75 | +# Verify Content-Type contains charset=UTF-8 |
| 76 | +if ! echo "$content_type" | grep -q "charset=UTF-8"; then |
| 77 | + exit 1 |
| 78 | +fi |
| 79 | + |
| 80 | +# Get the file content |
| 81 | +file_content=$( |
| 82 | + curl -k -f -s -G \ |
| 83 | + -E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \ |
| 84 | + "$file") |
| 85 | + |
| 86 | +# Verify UTF-8 characters are preserved |
| 87 | +if ! echo "$file_content" | grep -q "—"; then |
| 88 | + exit 1 |
| 89 | +fi |
| 90 | + |
| 91 | +if ! echo "$file_content" | grep -q "→"; then |
| 92 | + exit 1 |
| 93 | +fi |
| 94 | + |
| 95 | +if ! echo "$file_content" | grep -q "🚀"; then |
| 96 | + exit 1 |
| 97 | +fi |
0 commit comments