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+ # add agent to the writers group
11+
12+ add-agent-to-group.sh \
13+ -f " $OWNER_CERT_FILE " \
14+ -p " $OWNER_CERT_PWD " \
15+ --agent " $AGENT_URI " \
16+ " ${ADMIN_BASE_URL} acl/groups/writers/"
17+
18+ # create a new document with PUT to establish initial state
19+
20+ slug=" post-metadata-test-item"
21+ item=" ${END_USER_BASE_URL}${slug} /"
22+
23+ (
24+ curl -k -w " %{http_code}\n" -o /dev/null -s \
25+ -E " $AGENT_CERT_FILE " :" $AGENT_CERT_PWD " \
26+ -X PUT \
27+ -H " Accept: application/n-triples" \
28+ -H " Content-Type: application/n-triples" \
29+ --data-binary @- \
30+ " $item " << EOF
31+ <${item} > <http://purl.org/dc/terms/title> "POST Metadata Test Item" .
32+ <${item} > <http://example.com/initial-predicate> "initial value" .
33+ EOF
34+ ) \
35+ | grep -q " $STATUS_CREATED "
36+
37+ # get initial state and verify cardinalities after PUT
38+
39+ item_ntriples=$( get.sh \
40+ -f " $AGENT_CERT_FILE " \
41+ -p " $AGENT_CERT_PWD " \
42+ --accept ' application/n-triples' \
43+ " $item "
44+ )
45+
46+ # check that exactly one dct:created exists and no dct:modified yet
47+ created_count=$( echo " $item_ntriples " | grep -c " <${item} > <http://purl.org/dc/terms/created> " || true)
48+ if [ " $created_count " -ne 1 ]; then
49+ echo " Expected exactly 1 dct:created property after creation, found $created_count "
50+ exit 1
51+ fi
52+
53+ modified_count=$( echo " $item_ntriples " | grep -c " <${item} > <http://purl.org/dc/terms/modified> " || true)
54+ if [ " $modified_count " -ne 0 ]; then
55+ echo " Expected no dct:modified property after creation, found $modified_count "
56+ exit 1
57+ fi
58+
59+ # perform first POST operation
60+
61+ (
62+ curl -k -w " %{http_code}\n" -o /dev/null -f -s \
63+ -E " $AGENT_CERT_FILE " :" $AGENT_CERT_PWD " \
64+ -H " Accept: application/n-triples" \
65+ -H " Content-Type: application/n-triples" \
66+ --data-binary @- \
67+ " $item " << EOF
68+ <${item} > <http://example.com/post-predicate-1> "first POST value" .
69+ EOF
70+ ) \
71+ | grep -q " $STATUS_NO_CONTENT "
72+
73+ # get state after first POST and verify cardinalities
74+
75+ item_ntriples=$( get.sh \
76+ -f " $AGENT_CERT_FILE " \
77+ -p " $AGENT_CERT_PWD " \
78+ --accept ' application/n-triples' \
79+ " $item "
80+ )
81+
82+ # check that exactly one dct:created and one dct:modified exist
83+ created_count=$( echo " $item_ntriples " | grep -c " <${item} > <http://purl.org/dc/terms/created> " || true)
84+ if [ " $created_count " -ne 1 ]; then
85+ echo " Expected exactly 1 dct:created property after first POST, found $created_count "
86+ exit 1
87+ fi
88+
89+ modified_count=$( echo " $item_ntriples " | grep -c " <${item} > <http://purl.org/dc/terms/modified> " || true)
90+ if [ " $modified_count " -ne 1 ]; then
91+ echo " Expected exactly 1 dct:modified property after first POST, found $modified_count "
92+ exit 1
93+ fi
94+
95+ # perform second POST operation (this is the key test for accumulation bug)
96+
97+ (
98+ curl -k -w " %{http_code}\n" -o /dev/null -f -s \
99+ -E " $AGENT_CERT_FILE " :" $AGENT_CERT_PWD " \
100+ -H " Accept: application/n-triples" \
101+ -H " Content-Type: application/n-triples" \
102+ --data-binary @- \
103+ " $item " << EOF
104+ <${item} > <http://example.com/post-predicate-2> "second POST value" .
105+ EOF
106+ ) \
107+ | grep -q " $STATUS_NO_CONTENT "
108+
109+ # get final state and verify cardinalities (key test for the fix)
110+
111+ item_ntriples=$( get.sh \
112+ -f " $AGENT_CERT_FILE " \
113+ -p " $AGENT_CERT_PWD " \
114+ --accept ' application/n-triples' \
115+ " $item "
116+ )
117+
118+ # check that exactly one dct:created and one dct:modified still exist
119+ created_count=$( echo " $item_ntriples " | grep -c " <${item} > <http://purl.org/dc/terms/created> " || true)
120+ if [ " $created_count " -ne 1 ]; then
121+ echo " Expected exactly 1 dct:created property after second POST, found $created_count "
122+ exit 1
123+ fi
124+
125+ modified_count=$( echo " $item_ntriples " | grep -c " <${item} > <http://purl.org/dc/terms/modified> " || true)
126+ if [ " $modified_count " -ne 1 ]; then
127+ echo " Expected exactly 1 dct:modified property after second POST, found $modified_count "
128+ echo " This indicates the fix for accumulating dct:modified values in Graph::post() is not working"
129+ exit 1
130+ fi
131+
132+ # verify that all POST content was added (ensure POST operations work correctly)
133+ echo " $item_ntriples " | grep " \" first POST value\" " > /dev/null
134+ echo " $item_ntriples " | grep " \" second POST value\" " > /dev/null
0 commit comments