37
37
*/
38
38
public class HauthDelegateIT {
39
39
40
+ /**
41
+ * A sample thumbnail IIIF request.
42
+ */
43
+ private static final String THUMBNAIL = "/full/!200,200/0/default.tif" ;
44
+
40
45
/**
41
46
* The template for image URLs. The slots are:
42
47
* <ul>
@@ -54,7 +59,7 @@ public class HauthDelegateIT {
54
59
* </code>
55
60
* <p>
56
61
* 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>.
58
63
*/
59
64
private static final String ACCESS_TOKEN =
60
65
"eyJ2ZXJzaW9uIjogIjAuMC4wLVNOQVBTSE9UIiwgImNhbXB1c05ldHdvcmsiOiB0cnVlfQo=" ;
@@ -66,39 +71,11 @@ public class HauthDelegateIT {
66
71
* </code>
67
72
* <p>
68
73
* 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>.
70
75
*/
71
76
private static final String SINAI_ACCESS_TOKEN =
72
77
"eyJ2ZXJzaW9uIjogIjAuMC4wLVNOQVBTSE9UIiwgInNpbmFpQWZmaWxpYXRlIjogdHJ1ZX0K" ;
73
78
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
-
102
79
/**
103
80
* The id of the non-restricted image.
104
81
*/
@@ -183,12 +160,38 @@ public class HauthDelegateIT {
183
160
184
161
/**
185
162
* 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
186
166
*/
187
167
@ 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 );
192
195
final HttpRequest .Builder requestBuilder = HttpRequest .newBuilder (URI .create (imageURL ));
193
196
final HttpResponse <byte []> response = HTTP_CLIENT .send (requestBuilder .build (), BodyHandlers .ofByteArray ());
194
197
final ByteArrayInputStream byteArrayInputStream ;
@@ -350,7 +353,8 @@ private static String getImageURL(final String aBaseURL, final int aImageApiVers
350
353
final String imageApiPathTemplate ;
351
354
final String imageApiPath ;
352
355
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
354
358
switch (aImageApiVersion ) {
355
359
case 2 :
356
360
imageApiPathTemplate = "{}/full/full/0/default.tif" ;
@@ -481,6 +485,8 @@ public final void testErrorResponseTieredDisallowedScale() throws IOException, I
481
485
final HttpResponse <String > response =
482
486
sendImageInfoRequest (TIERED_ACCESS_IMAGE_DEGRADED_UNAVAILABLE , null , 2 );
483
487
488
+ System .out .println (response .headers ().toString ());
489
+
484
490
assertEquals (HTTP .FORBIDDEN , response .statusCode ());
485
491
assertFalse (TestUtils .responseHasContentType (response , MediaType .APPLICATION_JSON ,
486
492
MediaType .APPLICATION_LD_PLUS_JSON ));
@@ -506,6 +512,9 @@ public final void testNoAccessResponseAllOrNothingUnauthorized() throws IOExcept
506
512
getExpectedImageInfo (ALL_OR_NOTHING_ACCESS_IMAGE , NO_ACCESS_RESPONSE_TEMPLATE_V2 , 2 );
507
513
508
514
assertEquals (HTTP .UNAUTHORIZED , response .statusCode ());
515
+
516
+ System .out .println (response .headers ().toString ());
517
+
509
518
assertTrue (TestUtils .responseHasContentType (response , MediaType .APPLICATION_JSON ,
510
519
MediaType .APPLICATION_LD_PLUS_JSON ));
511
520
TestUtils .assertEquals (expectedResponse , response .body ());
0 commit comments