3737 */
3838public class HauthDelegateIT {
3939
40+ /**
41+ * A sample thumbnail IIIF request.
42+ */
43+ private static final String THUMBNAIL = "/full/!200,200/0/default.tif" ;
44+
4045 /**
4146 * The template for image URLs. The slots are:
4247 * <ul>
@@ -54,7 +59,7 @@ public class HauthDelegateIT {
5459 * </code>
5560 * <p>
5661 * This would be the value of the "accessToken" key shown
57- * <a href="https://iiif.io/api/auth/1.0/#the-json-access-token-response">here</a>.
62+ * <a href= "https://iiif.io/api/auth/1.0/#the-json-access-token-response">here</a>.
5863 */
5964 private static final String ACCESS_TOKEN =
6065 "eyJ2ZXJzaW9uIjogIjAuMC4wLVNOQVBTSE9UIiwgImNhbXB1c05ldHdvcmsiOiB0cnVlfQo=" ;
@@ -66,39 +71,11 @@ public class HauthDelegateIT {
6671 * </code>
6772 * <p>
6873 * This would be the value of the "accessToken" key shown
69- * <a href="https://iiif.io/api/auth/1.0/#the-json-access-token-response">here</a>.
74+ * <a href= "https://iiif.io/api/auth/1.0/#the-json-access-token-response">here</a>.
7075 */
7176 private static final String SINAI_ACCESS_TOKEN =
7277 "eyJ2ZXJzaW9uIjogIjAuMC4wLVNOQVBTSE9UIiwgInNpbmFpQWZmaWxpYXRlIjogdHJ1ZX0K" ;
7378
74- /**
75- * A test initialization vector used to encrypt {@link #TEST_SINAI_AUTHENTICATED_3DAY}. This is just the value
76- * "0123456789ABCDEF" (see Ruby script below) encoded in hexadecimal.
77- */
78- private static final String TEST_INITIALIZATION_VECTOR = "30313233343536373839414243444546" ;
79-
80- /**
81- * A test cookie generated using the following Ruby code, mocking the relevant part of the Sinai application.
82- * <p>
83- *
84- * <pre>
85- * #!/usr/bin/env ruby
86- *
87- * require "openssl"
88- *
89- * cipher = OpenSSL::Cipher::AES256.new :CBC
90- * cipher.encrypt
91- * cipher.key = "ThisPasswordIsReallyHardToGuess!"
92- * cipher.iv = "0123456789ABCDEF"
93- * puts (cipher.update("Authenticated #{Time.at(0).utc}") + cipher.final).unpack("H*")[0].upcase
94- * </pre>
95- *
96- * @see <a href= "https://github.com/UCLALibrary/sinaimanuscripts/blob/44cbbd9bf508c32b742f1617205a679edf77603e/app/
97- * controllers/application_controller.rb#L98-L103">How the Sinai application encodes cookies</a>
98- */
99- private static final String TEST_SINAI_AUTHENTICATED_3DAY =
100- "5AFF80488740353F8A11B99C7A493D871807521908500772B92E4F8FC919E305A607ADB714B22EF08D2C22FC08C8A6EC" ;
101-
10279 /**
10380 * The id of the non-restricted image.
10481 */
@@ -183,12 +160,38 @@ public class HauthDelegateIT {
183160
184161 /**
185162 * Tests that thumbnails of access controlled items are still displayed.
163+ *
164+ * @throws InterruptedException If the test is interrupted
165+ * @throws IOException If there is trouble reading and writing test resources
186166 */
187167 @ Test
188- public final void testAccessControlledThumbnails () throws InterruptedException , IOException {
189- final String imageURL =
190- StringUtils .format (IMAGE_URL_TEMPLATE , System .getenv ().get (TestConfig .IIIF_URL_PROPERTY ), 2 ,
191- ALL_OR_NOTHING_ACCESS_IMAGE + "/full/!200,200/0/default.tif" );
168+ public final void testAllOrNothingThumbnails () throws InterruptedException , IOException {
169+ final String imageURL = StringUtils .format (IMAGE_URL_TEMPLATE ,
170+ System .getenv ().get (TestConfig .IIIF_URL_PROPERTY ), 2 , ALL_OR_NOTHING_ACCESS_IMAGE + THUMBNAIL );
171+ final HttpRequest .Builder requestBuilder = HttpRequest .newBuilder (URI .create (imageURL ));
172+ final HttpResponse <byte []> response = HTTP_CLIENT .send (requestBuilder .build (), BodyHandlers .ofByteArray ());
173+ final ByteArrayInputStream byteArrayInputStream ;
174+ final BufferedImage image ;
175+
176+ assertEquals (200 , response .statusCode ());
177+
178+ byteArrayInputStream = new ByteArrayInputStream (response .body ());
179+ image = ImageIO .read (byteArrayInputStream );
180+
181+ assertEquals (200 , image .getHeight ());
182+ assertEquals (200 , image .getWidth ());
183+ }
184+
185+ /**
186+ * Tests that thumbnails of access controlled items are still displayed.
187+ *
188+ * @throws InterruptedException If the test is interrupted
189+ * @throws IOException If there is trouble reading and writing test resources
190+ */
191+ @ Test
192+ public final void testTieredAccessControlledThumbnails () throws InterruptedException , IOException {
193+ final String imageURL = StringUtils .format (IMAGE_URL_TEMPLATE ,
194+ System .getenv ().get (TestConfig .IIIF_URL_PROPERTY ), 2 , TIERED_ACCESS_IMAGE_DEGRADED_VALID + THUMBNAIL );
192195 final HttpRequest .Builder requestBuilder = HttpRequest .newBuilder (URI .create (imageURL ));
193196 final HttpResponse <byte []> response = HTTP_CLIENT .send (requestBuilder .build (), BodyHandlers .ofByteArray ());
194197 final ByteArrayInputStream byteArrayInputStream ;
@@ -350,7 +353,8 @@ private static String getImageURL(final String aBaseURL, final int aImageApiVers
350353 final String imageApiPathTemplate ;
351354 final String imageApiPath ;
352355
353- // Use TIFFs so that we can easily compare the response payload with the source image
356+ // Use TIFFs so that we can easily compare the response payload with the source
357+ // image
354358 switch (aImageApiVersion ) {
355359 case 2 :
356360 imageApiPathTemplate = "{}/full/full/0/default.tif" ;
@@ -481,6 +485,8 @@ public final void testErrorResponseTieredDisallowedScale() throws IOException, I
481485 final HttpResponse <String > response =
482486 sendImageInfoRequest (TIERED_ACCESS_IMAGE_DEGRADED_UNAVAILABLE , null , 2 );
483487
488+ System .out .println (response .headers ().toString ());
489+
484490 assertEquals (HTTP .FORBIDDEN , response .statusCode ());
485491 assertFalse (TestUtils .responseHasContentType (response , MediaType .APPLICATION_JSON ,
486492 MediaType .APPLICATION_LD_PLUS_JSON ));
@@ -506,6 +512,9 @@ public final void testNoAccessResponseAllOrNothingUnauthorized() throws IOExcept
506512 getExpectedImageInfo (ALL_OR_NOTHING_ACCESS_IMAGE , NO_ACCESS_RESPONSE_TEMPLATE_V2 , 2 );
507513
508514 assertEquals (HTTP .UNAUTHORIZED , response .statusCode ());
515+
516+ System .out .println (response .headers ().toString ());
517+
509518 assertTrue (TestUtils .responseHasContentType (response , MediaType .APPLICATION_JSON ,
510519 MediaType .APPLICATION_LD_PLUS_JSON ));
511520 TestUtils .assertEquals (expectedResponse , response .body ());
0 commit comments