Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ITs for FCREPO-1411
  • Loading branch information
ajs6f committed Apr 9, 2015
1 parent 3de050c commit 1455833
Showing 1 changed file with 64 additions and 0 deletions.
Expand Up @@ -32,6 +32,7 @@
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.FORBIDDEN;
import static javax.ws.rs.core.Response.Status.NOT_MODIFIED;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static javax.ws.rs.core.Response.Status.OK;
Expand Down Expand Up @@ -108,6 +109,7 @@
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
Expand Down Expand Up @@ -152,6 +154,7 @@

/**
* @author cabeer
* @author ajs6f
*/
public class FedoraLdpIT extends AbstractResourceIT {

Expand Down Expand Up @@ -559,6 +562,27 @@ public void testUpdateObjectGraph() throws Exception {

}

@Test
public void testUpdateObjectGraphWithNonLocalTriples() throws Exception {
final String pid = getRandomUniquePid();
createObject(pid);
final String otherPid = getRandomUniquePid();
createObject(otherPid);
final String location = serverAddress + pid;
final String otherLocation = serverAddress + otherPid;
final HttpPatch updateObjectGraphMethod = new HttpPatch(location);
updateObjectGraphMethod.addHeader("Content-Type", "application/sparql-update");
final BasicHttpEntity e = new BasicHttpEntity();
e.setContent(new ByteArrayInputStream(("INSERT { <" + location +
"> <http://purl.org/dc/elements/1.1/identifier> \"this is an identifier\". " + "<" + otherLocation +
"> <http://purl.org/dc/elements/1.1/identifier> \"this is an identifier\"" + " } WHERE {}")
.getBytes()));
updateObjectGraphMethod.setEntity(e);
final HttpResponse response = client.execute(updateObjectGraphMethod);
assertEquals("It ought not be possible to use PATCH to create non-local triples!", FORBIDDEN.getStatusCode(),
response.getStatusLine().getStatusCode());
}

@Test
public void testPatchBinary() throws Exception {
final String pid = getRandomUniquePid();
Expand Down Expand Up @@ -738,6 +762,25 @@ public void testCreateGraph() throws Exception {
createPlainLiteral("asdfg")));
}

@Test
public void testCreateGraphWithNonLocalTriples() throws IOException {
final String subjectURI = serverAddress + getRandomUniquePid();
final String otherPid = getRandomUniquePid();
createObject(otherPid);
final String otherLocation = serverAddress + otherPid;
final HttpPut replaceMethod = new HttpPut(subjectURI);
replaceMethod.addHeader("Content-Type", "application/n3");
final BasicHttpEntity e = new BasicHttpEntity();
e.setContent(new ByteArrayInputStream(
("<" + subjectURI + "> <info:rubydora#label> \"asdfg\".\n" +
"<" + otherLocation + "> <info:rubydora#label> \"asdfg\"." )
.getBytes()));
replaceMethod.setEntity(e);
final HttpResponse response = client.execute(replaceMethod);
assertEquals("It ought not be possible to create triples about a non-local resource!", FORBIDDEN
.getStatusCode(), response.getStatusLine().getStatusCode());
}

@Test
public void testCreateGraphWithBlanknodes() throws Exception {
final String pid = getRandomUniquePid();
Expand Down Expand Up @@ -920,6 +963,27 @@ public void testIngestWithNewAndSparqlQuery() throws Exception {
assertNotEquals("Last-Modified should not be blank for new nodes", lastmod.trim(), "");
}

@Test
public void testIngestWithNewAndSparqlQueryWithNonLocalTriples() throws ParseException, IOException {
final String otherPid = getRandomUniquePid();
createObject(otherPid);
final String otherLocation = serverAddress + otherPid;
final HttpPost method = postObjMethod("");
method.addHeader("Content-Type", "application/sparql-update");
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream(
("INSERT { <> <http://purl.org/dc/elements/1.1/title> \"this is a title\". " +
"<" + otherLocation + "> <http://purl.org/dc/elements/1.1/title> \"this is a title\"" +
" } WHERE {}")
.getBytes()));
method.setEntity(entity);
final HttpResponse response = client.execute(method);
final String content = EntityUtils.toString(response.getEntity());
final int status = response.getStatusLine().getStatusCode();
assertEquals("It ought no be possible to create triples about non-local resources!" + content, FORBIDDEN
.getStatusCode(), status);
}

@Test
public void testIngestWithSparqlQueryJcrNS() throws Exception {
final HttpPost method = postObjMethod("");
Expand Down

0 comments on commit 1455833

Please sign in to comment.