Skip to content

Commit

Permalink
Memento redirect must not also have payload. Added unittest to ensure it
Browse files Browse the repository at this point in the history
does not try to access warc-files for payload by setting playback
allowed.
  • Loading branch information
thomasegense committed Dec 29, 2023
1 parent 38089c0 commit 45e8ac8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ private static Response streamMementoFromNonRedirectingTimeGate(MementoDoc doc,
}

/**
* Streams the memento found for the timegate.
* Return the header with the 302 redirection location. Has no payload.
*
* @param doc containing data from solr for accessing the memento in the WARC files.
* @param metadata object which contains metadata on the memento. Including the additional headers.
* @return a response containing correct memento headers and the memento as the response entity.
Expand All @@ -199,9 +200,8 @@ private static Response streamMementoFromRedirectingTimeGate(MementoDoc doc, Mem
if (PropertiesLoader.PLAYBACK_DISABLED){
return Response.noContent().replaceAll(metadata.getHttpHeaders()).build();
} else {
try {
ArcEntry mementoEntity = Facade.getArcEntry(doc.getSource_file_path(), doc.getSource_file_offset());
ResponseBuilder entity = Response.status(302).entity(mementoEntity.getBinaryRaw());
try {
ResponseBuilder entity = Response.status(302);
addMementoHeadersToReponse(entity,metadata);
return entity.build();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void tearDown() throws Exception {

@Test
public void testHeadersForPatternTwoPointTwo() throws Exception {
PropertiesLoader.PLAYBACK_DISABLED = true;
PropertiesLoader.PLAYBACK_DISABLED = true; //Must be disabled since playback needs warc files
PropertiesLoader.MEMENTO_REDIRECT = false;

Response timeGate = DatetimeNegotiation.getMemento("http://kb.dk/", "Thu, 23 Mar 2019 14:05:57 GMT");
MultivaluedMap<String, Object> headers = timeGate.getHeaders();
Expand All @@ -87,7 +88,7 @@ public void testHeadersForPatternTwoPointTwo() throws Exception {

@Test
public void testHeadersForPatternTwoPointOne() throws Exception {
PropertiesLoader.PLAYBACK_DISABLED = true;
PropertiesLoader.PLAYBACK_DISABLED = false; //
PropertiesLoader.MEMENTO_REDIRECT = true;

Response timeGate = DatetimeNegotiation.getMemento("http://kb.dk/", "Thu, 23 Mar 2019 14:05:57 GMT");
Expand All @@ -97,7 +98,7 @@ public void testHeadersForPatternTwoPointOne() throws Exception {
assertNotNull(headers.get("Location"));
assertFalse(headers.containsKey("Memento-Datetime"));
assertTrue(headers.get("Link").get(0).toString().contains("rel=\"original\""));
assertEquals(0, headers.get("Content-Length").get(0));
assertEquals("0", headers.get("Content-Length").get(0));
assertEquals("text/html;charset=UTF-8", headers.get("Content-Type").get(0));
}

Expand Down

0 comments on commit 45e8ac8

Please sign in to comment.