Skip to content

Commit

Permalink
FIX NullPointerException in ServerRelativeArchivalRedirect for non-re…
Browse files Browse the repository at this point in the history
…play requests.
  • Loading branch information
kngenie committed Jan 28, 2015
1 parent 955ccd2 commit 06f71e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private String handleRequestWithCollection(HttpServletRequest httpRequest,
HttpServletResponse httpResponse) throws ServletException,
IOException {
ArchivalUrlRef ref = getOrigin(httpRequest);
if (ref == null) return null;

String thisPath = httpRequest.getRequestURI();
String queryString = httpRequest.getQueryString();
Expand Down Expand Up @@ -204,6 +205,7 @@ private String handleRequestWithoutCollection(
throws ServletException, IOException {

ArchivalUrlRef ref = getOrigin(httpRequest);
if (ref == null) return null;

String thisPath = httpRequest.getRequestURI();
String queryString = httpRequest.getQueryString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,26 @@ public void testCustomOrigin() throws Exception {
assertTrue(handled);
}

/**
* Test of non-ArchivalUrl requests.
* ServerRelativeArchivalRedirect is setup as catch-all handler ("{@code +"}).
* It must handle non-replay URLs like {@code /} and {@code /favicon.ico}, with
* non-ArchivalUrl Referer. It must not fail, and return {@code false}.
* @throws Exception
*/
public void testNonArchivalUrl() throws Exception {
final String REQUEST_URI = "/";
final String REFERER = "http://www.example.com/index.html";

setUpRequest(REQUEST_URI, REFERER);

HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
// no actions on response
EasyMock.replay(request, response);

boolean handled = cut.handleRequest(request, response);

EasyMock.verify(response);
assertFalse(handled);
}
}

0 comments on commit 06f71e6

Please sign in to comment.