Skip to content

Commit

Permalink
Allow delegate system to produce valid HTTP 401 info.json responses (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark A. Matney, Jr committed Jun 1, 2022
1 parent 017af48 commit e60f33c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 5.0.6

* IIIF information endpoints return JSON in HTTP 401 responses.
* Fixed a bug whereby the values of the `operations` and `page_count` keys
in the delegate context were not set.
* TurboJpegProcessor is able to generate non-JPEG derivative images, which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ private boolean processAuthInfo(AuthInfo info)
if (code == 401) {
getResponse().setHeader("WWW-Authenticate",
info.getChallengeValue());
if (getRequestContext().getLocalURI().getPath().endsWith("info.json")) {
return true;
}
}
throw new ResourceException(new Status(code));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testAuthorizationWhenAuthorized(URI uri) {
assertStatus(200, uri);
}

public void testAuthorizationWhenUnauthorized(URI uri) {
public void testAuthorizationWhenUnauthorized(URI uri, String endpointPath) {
// This may vary depending on the return value of a delegate method,
// but the way the tests are set up, it's 401.
assertStatus(401, uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.illinois.library.cantaloupe.http.Response;
import edu.illinois.library.cantaloupe.image.Identifier;
import edu.illinois.library.cantaloupe.resource.AbstractResource;
import edu.illinois.library.cantaloupe.resource.Route;
import edu.illinois.library.cantaloupe.test.TestUtil;

import java.io.File;
Expand All @@ -27,6 +28,20 @@
*/
public class InformationResourceTester extends ImageAPIResourceTester {

@Override
public void testAuthorizationWhenUnauthorized(URI uri, String endpointPath) {
final String requiredJsonLdContent;

if (endpointPath.equals(Route.IIIF_1_PATH)) {
requiredJsonLdContent = "\"@context\":\"http://library.stanford.edu/iiif/image-api/1.1/context.json\"";
} else {
requiredJsonLdContent = "\"protocol\":\"http://iiif.io/api/image\"";
}

assertStatus(401, uri);
assertRepresentationContains(requiredJsonLdContent, uri);
}

public void testCacheWithDerivativeCacheEnabledAndInfoCacheEnabledAndResolveFirstEnabled(
URI uri, Path sourceFile) throws Exception {
final Path cacheDir = initializeFilesystemCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void testGETAuthorizationWhenAuthorized() {
@Test
void testGETAuthorizationWhenUnauthorized() {
URI uri = getHTTPURI("/unauthorized.jpg/full/full/0/color.jpg");
tester.testAuthorizationWhenUnauthorized(uri);
tester.testAuthorizationWhenUnauthorized(uri, getEndpointPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void testGETAuthorizationWhenAuthorized() {
@Test
void testGETAuthorizationWhenUnauthorized() {
URI uri = getHTTPURI("/unauthorized.jpg/info.json");
tester.testAuthorizationWhenUnauthorized(uri);
tester.testAuthorizationWhenUnauthorized(uri, getEndpointPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void testGETAuthorizationWhenAuthorized() {
@Test
void testGETAuthorizationWhenUnauthorized() {
URI uri = getHTTPURI("/unauthorized.jpg/full/full/0/color.jpg");
tester.testAuthorizationWhenUnauthorized(uri);
tester.testAuthorizationWhenUnauthorized(uri, getEndpointPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void testGETAuthorizationWhenAuthorized() {
@Test
void testGETAuthorizationWhenUnauthorized() {
URI uri = getHTTPURI("/unauthorized.jpg/info.json");
tester.testAuthorizationWhenUnauthorized(uri);
tester.testAuthorizationWhenUnauthorized(uri, getEndpointPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void testGETAuthorizationWhenAuthorized() {
@Test
void testGETAuthorizationWhenUnauthorized() {
URI uri = getHTTPURI("/unauthorized.jpg/full/max/0/color.jpg");
tester.testAuthorizationWhenUnauthorized(uri);
tester.testAuthorizationWhenUnauthorized(uri, getEndpointPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void testGETAuthorizationWhenAuthorized() {
@Test
void testGETAuthorizationWhenUnauthorized() {
URI uri = getHTTPURI("/unauthorized.jpg/info.json");
tester.testAuthorizationWhenUnauthorized(uri);
tester.testAuthorizationWhenUnauthorized(uri, getEndpointPath());
}

@Test
Expand Down

0 comments on commit e60f33c

Please sign in to comment.