Skip to content

Commit 0c2d06e

Browse files
committed
HTTP test for the Transform endpoint
Fixed ACL of `<admin/transform>`
1 parent bfca184 commit 0c2d06e

8 files changed

Lines changed: 100 additions & 6 deletions

File tree

http-tests/access/group-authorization.sh

100644100755
File mode changed.

http-tests/access/owner-authorization.sh

100644100755
File mode changed.

http-tests/admin/POST-transform.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
9+
namespace_doc="${END_USER_BASE_URL}ns"
10+
namespace="${namespace_doc}#"
11+
ontology_doc="${ADMIN_BASE_URL}ontologies/namespace/"
12+
import_uri="http://www.w3.org/2004/02/skos/core"
13+
14+
# create item
15+
16+
slug="test"
17+
18+
item=$(create-item.sh \
19+
-f "$OWNER_CERT_FILE" \
20+
-p "$OWNER_CERT_PWD" \
21+
-b "$ADMIN_BASE_URL" \
22+
--title "Test" \
23+
--slug "$slug" \
24+
--container "${ADMIN_BASE_URL}ontologies/")
25+
26+
# load the ontology, transform it and append it to the item document
27+
28+
curl -w "%{http_code}\n" -o /dev/null -k -s \
29+
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
30+
-H "Accept: text/turtle" \
31+
-H "Content-Type: application/x-www-form-urlencoded" \
32+
--data-urlencode "rdf=" \
33+
--data-urlencode "sb=transform" \
34+
--data-urlencode "pu=http://spinrdf.org/spin#query" \
35+
--data-urlencode "ou=${ADMIN_BASE_URL}queries/construct-constructors/#this" \
36+
--data-urlencode "pu=http://purl.org/dc/terms/source" \
37+
--data-urlencode "ou=${import_uri}" \
38+
--data-urlencode "pu=http://www.w3.org/ns/sparql-service-description#name" \
39+
--data-urlencode "ou=${item}" \
40+
"${ADMIN_BASE_URL}transform" \
41+
| grep -q "$STATUS_NO_CONTENT"
42+
43+
# add ontology import
44+
45+
add-ontology-import.sh \
46+
-f "$OWNER_CERT_FILE" \
47+
-p "$OWNER_CERT_PWD" \
48+
--import "$import_uri" \
49+
"$ontology_doc"
50+
51+
# clear the namespace ontology from memory
52+
53+
clear-ontology.sh \
54+
-f "$OWNER_CERT_FILE" \
55+
-p "$OWNER_CERT_PWD" \
56+
-b "$ADMIN_BASE_URL" \
57+
--ontology "$namespace"
58+
59+
# check that the imported ontology is present in the ontology model TO-DO: replace with an ASK query when #118 is fixed
60+
61+
curl -k -f -s \
62+
-G \
63+
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
64+
-H 'Accept: application/sparql-results+xml' \
65+
--data-urlencode "query=SELECT * { <${import_uri}> ?p ?o }" \
66+
"$namespace_doc" \
67+
| grep '<literal xml:lang="en">SKOS Vocabulary</literal>' > /dev/null

http-tests/document-hierarchy/owner-container.sh

100644100755
File mode changed.

http-tests/document-hierarchy/owner-item.sh

100644100755
File mode changed.

platform/datasets/admin.trig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ WHERE
382382

383383
}
384384

385+
<transform>
386+
{
387+
388+
<transform> a foaf:Document ;
389+
dct:title "Transform/import endpoint" .
390+
391+
}
392+
385393
<oauth2/login>
386394
{
387395

@@ -748,7 +756,7 @@ WHERE
748756
rdfs:label "Full control" ;
749757
rdfs:comment "Allows full read/write access to all application resources" ;
750758
acl:accessToClass dh:Item, dh:Container, def:Root ;
751-
acl:accessTo <../sparql>, <../importer>, <../transform>, <../generate>, <../ns>, <clear> ;
759+
acl:accessTo <../sparql>, <../importer>, <../generate>, <../ns>, <clear>, <transform> ;
752760
acl:mode acl:Read, acl:Append, acl:Write, acl:Control ;
753761
acl:agentGroup <acl/groups/owners/#this> .
754762

@@ -768,7 +776,7 @@ WHERE
768776
rdfs:label "Write/append access" ;
769777
rdfs:comment "Allows write access to all documents and containers" ;
770778
acl:accessToClass dh:Item, dh:Container, def:Root ;
771-
acl:accessTo <../sparql>, <../importer>, <../transform>, <../generate>, <../ns> ;
779+
acl:accessTo <../sparql>, <../importer>, <../generate>, <../ns> ;
772780
acl:mode acl:Write, acl:Append ;
773781
acl:agentGroup <acl/groups/owners/#this>, <acl/groups/writers/#this> .
774782

src/main/java/com/atomgraph/linkeddatahub/resource/Transform.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.atomgraph.linkeddatahub.imports.QueryLoader;
2424
import com.atomgraph.linkeddatahub.model.Service;
2525
import com.atomgraph.linkeddatahub.server.io.ValidatingModelProvider;
26+
import com.atomgraph.linkeddatahub.server.model.impl.GraphStoreImpl;
2627
import com.atomgraph.linkeddatahub.server.security.AgentContext;
2728
import com.atomgraph.linkeddatahub.vocabulary.NFO;
2829
import com.atomgraph.spinrdf.vocabulary.SPIN;
@@ -64,7 +65,7 @@
6465
*
6566
* @author {@literal Martynas Jusevičius <martynas@atomgraph.com>}
6667
*/
67-
public class Transform extends Add
68+
public class Transform extends GraphStoreImpl
6869
{
6970

7071
private static final Logger log = LoggerFactory.getLogger(Transform.class);
@@ -144,7 +145,6 @@ public Response post(Model model, @QueryParam("default") @DefaultValue("false")
144145
*/
145146
@POST
146147
@Consumes(MediaType.MULTIPART_FORM_DATA)
147-
@Override
148148
public Response postMultipart(FormDataMultiPart multiPart, @QueryParam("default") @DefaultValue("false") Boolean defaultGraph, @QueryParam("graph") URI graphUri)
149149
{
150150
if (log.isDebugEnabled()) log.debug("MultiPart fields: {} body parts: {}", multiPart.getFields(), multiPart.getBodyParts());
@@ -177,7 +177,6 @@ public Response postMultipart(FormDataMultiPart multiPart, @QueryParam("default"
177177
* @param fileNameBodyPartMap parts of the multipart request
178178
* @return response response
179179
*/
180-
@Override
181180
public Response postFileBodyPart(Model model, Map<String, FormDataBodyPart> fileNameBodyPartMap)
182181
{
183182
if (model == null) throw new IllegalArgumentException("Model cannot be null");
@@ -223,4 +222,24 @@ public Response postFileBodyPart(Model model, Map<String, FormDataBodyPart> file
223222
}
224223
}
225224

225+
/**
226+
* Forwards <code>POST</code> request to a graph.
227+
*
228+
* @param entity request entity
229+
* @param graphURI the graph URI
230+
* @return JAX-RS response
231+
*/
232+
protected Response forwardPost(Entity entity, String graphURI)
233+
{
234+
LinkedDataClient ldc = LinkedDataClient.create(getSystem().getClient(), getSystem().getMediaTypes()).
235+
delegation(getUriInfo().getBaseUri(), getAgentContext().orElse(null));
236+
// forward the stream to the named graph document. Buffer the entity first so that the server response is not returned before the client response completes
237+
try (Response response = ldc.post(URI.create(graphURI), ldc.getReadableMediaTypes(Model.class), entity))
238+
{
239+
return Response.status(response.getStatus()).
240+
entity(response.readEntity(Model.class)).
241+
build();
242+
}
243+
}
244+
226245
}

src/main/webapp/WEB-INF/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ WHERE
124124
$Type (rdfs:subClassOf)* ?Class
125125
}
126126
# only namespace, signup, OAuth2 login and WebID profiles can be public in admin app, nothing else
127-
FILTER ( $this IN (uri(concat(str($base), "ns")), uri(concat(str($base), "sign%20up")), uri(concat(str($base), "oauth2/login")), uri(concat(str($base), "oauth2/authorize/google"))) || strstarts(str($this), concat(str($base), "acl/agents/")) || strstarts(str($this), concat(str($base), "acl/public-keys/")))
127+
FILTER ( $this IN (uri(concat(str($base), "ns")), uri(concat(str($base), "sign%20up")), uri(concat(str($base), "oauth2/login")), uri(concat(str($base), "oauth2/authorize/google")), uri(concat(str($base), "transform"))) || strstarts(str($this), concat(str($base), "acl/agents/")) || strstarts(str($this), concat(str($base), "acl/public-keys/")))
128128
}
129129
}
130130
]]></param-value>

0 commit comments

Comments
 (0)