Skip to content

Commit b2d3bce

Browse files
committed
Additional HTTP tests for file uploads
1 parent 7159796 commit b2d3bce

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 test file with sample content
21+
22+
test_file=$(mktemp)
23+
echo "test,data,sample" > "$test_file"
24+
echo "1,2,3" >> "$test_file"
25+
echo "4,5,6" >> "$test_file"
26+
27+
# upload file WITHOUT explicit media type (rely on browser detection via `file -b --mime-type`)
28+
29+
file_doc=$(create-file.sh \
30+
-f "$AGENT_CERT_FILE" \
31+
-p "$AGENT_CERT_PWD" \
32+
-b "$END_USER_BASE_URL" \
33+
--title "Test File for Browser Media Type" \
34+
--file "$test_file")
35+
36+
# get the file resource URI and initial dct:format
37+
38+
file_doc_ntriples=$(get.sh \
39+
-f "$AGENT_CERT_FILE" \
40+
-p "$AGENT_CERT_PWD" \
41+
--accept 'application/n-triples' \
42+
"$file_doc")
43+
44+
file_uri=$(echo "$file_doc_ntriples" | sed -rn "s/<${file_doc//\//\\/}> <http:\/\/xmlns.com\/foaf\/0.1\/primaryTopic> <(.*)> \./\1/p")
45+
46+
# get initial SHA1 hash
47+
initial_sha1=$(echo "$file_doc_ntriples" | sed -rn "s/<${file_uri//\//\\/}> <http:\/\/xmlns.com\/foaf\/0.1\/sha1> \"(.*)\" \./\1/p")
48+
49+
# get initial dct:format (should be browser-detected)
50+
initial_format=$(echo "$file_doc_ntriples" | sed -rn "s/<${file_uri//\//\\/}> <http:\/\/purl.org\/dc\/terms\/format> <(.*)> \./\1/p")
51+
52+
# re-upload the same file to the same document with explicit media type: text/csv
53+
# using PUT with RDF/POST multipart format
54+
# IMPORTANT: Include explicit dct:format in RDF to simulate user editing the format field in the form
55+
56+
rdf_post=""
57+
rdf_post+="-F \"rdf=\"\n"
58+
rdf_post+="-F \"sb=file\"\n"
59+
rdf_post+="-F \"pu=http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName\"\n"
60+
rdf_post+="-F \"ol=@${test_file};type=text/csv\"\n"
61+
rdf_post+="-F \"pu=http://purl.org/dc/terms/title\"\n"
62+
rdf_post+="-F \"ol=Test File for Browser Media Type\"\n"
63+
rdf_post+="-F \"pu=http://www.w3.org/1999/02/22-rdf-syntax-ns#type\"\n"
64+
rdf_post+="-F \"ou=http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#FileDataObject\"\n"
65+
rdf_post+="-F \"pu=http://purl.org/dc/terms/format\"\n"
66+
rdf_post+="-F \"ou=http://www.sparontologies.net/mediatype/text/csv\"\n"
67+
rdf_post+="-F \"su=${file_doc}\"\n"
68+
rdf_post+="-F \"pu=http://purl.org/dc/terms/title\"\n"
69+
rdf_post+="-F \"ol=Test File for Browser Media Type\"\n"
70+
rdf_post+="-F \"pu=http://www.w3.org/1999/02/22-rdf-syntax-ns#type\"\n"
71+
rdf_post+="-F \"ou=https://www.w3.org/ns/ldt/document-hierarchy#Item\"\n"
72+
rdf_post+="-F \"pu=http://xmlns.com/foaf/0.1/primaryTopic\"\n"
73+
rdf_post+="-F \"ob=file\"\n"
74+
rdf_post+="-F \"pu=http://rdfs.org/sioc/ns#has_container\"\n"
75+
rdf_post+="-F \"ou=${END_USER_BASE_URL}files/\"\n"
76+
77+
echo -e "$rdf_post" | curl -f -v -s -k -X PUT -H "Accept: text/turtle" -E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" -o /dev/null --config - "$file_doc"
78+
79+
# get updated document
80+
81+
updated_ntriples=$(get.sh \
82+
-f "$AGENT_CERT_FILE" \
83+
-p "$AGENT_CERT_PWD" \
84+
--accept 'application/n-triples' \
85+
"$file_doc")
86+
87+
# get updated SHA1 hash (should be same as initial)
88+
updated_sha1=$(echo "$updated_ntriples" | sed -rn "s/<${file_uri//\//\\/}> <http:\/\/xmlns.com\/foaf\/0.1\/sha1> \"(.*)\" \./\1/p")
89+
90+
# get updated dct:format (should be text/csv)
91+
updated_format=$(echo "$updated_ntriples" | sed -rn "s/<${file_uri//\//\\/}> <http:\/\/purl.org\/dc\/terms\/format> <(.*)> \./\1/p")
92+
93+
# verify SHA1 is unchanged (same file content)
94+
if [ "$initial_sha1" != "$updated_sha1" ]; then
95+
echo "ERROR: SHA1 hash changed! Initial: $initial_sha1, Updated: $updated_sha1"
96+
exit 1
97+
fi
98+
99+
# verify dct:format was updated to text/csv
100+
if [[ ! "$updated_format" =~ text/csv ]]; then
101+
echo "ERROR: Format should have been updated to text/csv but got: $updated_format"
102+
echo "Initial format was: $initial_format"
103+
exit 1
104+
fi
105+
106+
# cleanup
107+
rm -f "$test_file"
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 test file with sample content
21+
22+
test_file=$(mktemp)
23+
echo "test,data,sample" > "$test_file"
24+
echo "1,2,3" >> "$test_file"
25+
echo "4,5,6" >> "$test_file"
26+
27+
# upload file with explicit media type: text/plain
28+
29+
file_doc=$(create-file.sh \
30+
-f "$AGENT_CERT_FILE" \
31+
-p "$AGENT_CERT_PWD" \
32+
-b "$END_USER_BASE_URL" \
33+
--title "Test File for Media Type Update" \
34+
--file "$test_file" \
35+
--file-content-type "text/plain")
36+
37+
# get the file resource URI and initial dct:format
38+
39+
file_doc_ntriples=$(get.sh \
40+
-f "$AGENT_CERT_FILE" \
41+
-p "$AGENT_CERT_PWD" \
42+
--accept 'application/n-triples' \
43+
"$file_doc")
44+
45+
file_uri=$(echo "$file_doc_ntriples" | sed -rn "s/<${file_doc//\//\\/}> <http:\/\/xmlns.com\/foaf\/0.1\/primaryTopic> <(.*)> \./\1/p")
46+
47+
# get initial SHA1 hash
48+
initial_sha1=$(echo "$file_doc_ntriples" | sed -rn "s/<${file_uri//\//\\/}> <http:\/\/xmlns.com\/foaf\/0.1\/sha1> \"(.*)\" \./\1/p")
49+
50+
# get initial dct:format
51+
initial_format=$(echo "$file_doc_ntriples" | sed -rn "s/<${file_uri//\//\\/}> <http:\/\/purl.org\/dc\/terms\/format> <(.*)> \./\1/p")
52+
53+
# verify initial format is text/plain
54+
if [[ ! "$initial_format" =~ text/plain ]]; then
55+
echo "ERROR: Initial format should contain text/plain but got: $initial_format"
56+
exit 1
57+
fi
58+
59+
# re-upload the same file to the same document with different explicit media type: text/csv
60+
# using PUT with RDF/POST multipart format
61+
# IMPORTANT: Include explicit dct:format in RDF to simulate user editing the format field in the form
62+
63+
rdf_post=""
64+
rdf_post+="-F \"rdf=\"\n"
65+
rdf_post+="-F \"sb=file\"\n"
66+
rdf_post+="-F \"pu=http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName\"\n"
67+
rdf_post+="-F \"ol=@${test_file};type=text/csv\"\n"
68+
rdf_post+="-F \"pu=http://purl.org/dc/terms/title\"\n"
69+
rdf_post+="-F \"ol=Test File for Media Type Update\"\n"
70+
rdf_post+="-F \"pu=http://www.w3.org/1999/02/22-rdf-syntax-ns#type\"\n"
71+
rdf_post+="-F \"ou=http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#FileDataObject\"\n"
72+
rdf_post+="-F \"pu=http://purl.org/dc/terms/format\"\n"
73+
rdf_post+="-F \"ou=http://www.sparontologies.net/mediatype/text/csv\"\n"
74+
rdf_post+="-F \"su=${file_doc}\"\n"
75+
rdf_post+="-F \"pu=http://purl.org/dc/terms/title\"\n"
76+
rdf_post+="-F \"ol=Test File for Media Type Update\"\n"
77+
rdf_post+="-F \"pu=http://www.w3.org/1999/02/22-rdf-syntax-ns#type\"\n"
78+
rdf_post+="-F \"ou=https://www.w3.org/ns/ldt/document-hierarchy#Item\"\n"
79+
rdf_post+="-F \"pu=http://xmlns.com/foaf/0.1/primaryTopic\"\n"
80+
rdf_post+="-F \"ob=file\"\n"
81+
rdf_post+="-F \"pu=http://rdfs.org/sioc/ns#has_container\"\n"
82+
rdf_post+="-F \"ou=${END_USER_BASE_URL}files/\"\n"
83+
84+
echo -e "$rdf_post" | curl -f -v -s -k -X PUT -H "Accept: text/turtle" -E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" -o /dev/null --config - "$file_doc"
85+
86+
# get updated document
87+
88+
updated_ntriples=$(get.sh \
89+
-f "$AGENT_CERT_FILE" \
90+
-p "$AGENT_CERT_PWD" \
91+
--accept 'application/n-triples' \
92+
"$file_doc")
93+
94+
# get updated SHA1 hash (should be same as initial)
95+
updated_sha1=$(echo "$updated_ntriples" | sed -rn "s/<${file_uri//\//\\/}> <http:\/\/xmlns.com\/foaf\/0.1\/sha1> \"(.*)\" \./\1/p")
96+
97+
# get updated dct:format (should be text/csv)
98+
updated_format=$(echo "$updated_ntriples" | sed -rn "s/<${file_uri//\//\\/}> <http:\/\/purl.org\/dc\/terms\/format> <(.*)> \./\1/p")
99+
100+
# verify SHA1 is unchanged (same file content)
101+
if [ "$initial_sha1" != "$updated_sha1" ]; then
102+
echo "ERROR: SHA1 hash changed! Initial: $initial_sha1, Updated: $updated_sha1"
103+
exit 1
104+
fi
105+
106+
# verify dct:format was updated to text/csv
107+
if [[ ! "$updated_format" =~ text/csv ]]; then
108+
echo "ERROR: Format should have been updated to text/csv but got: $updated_format"
109+
exit 1
110+
fi
111+
112+
# cleanup
113+
rm -f "$test_file"

0 commit comments

Comments
 (0)