1010import com .joyent .manta .config .ConfigContext ;
1111import com .joyent .manta .config .IntegrationTestConfigContext ;
1212import org .apache .commons .io .IOUtils ;
13+ import org .apache .http .HttpStatus ;
1314import org .testng .Assert ;
1415import org .testng .SkipException ;
1516import org .testng .annotations .AfterClass ;
2223import java .net .HttpURLConnection ;
2324import java .net .URI ;
2425import java .nio .charset .Charset ;
25- import java .nio . charset . StandardCharsets ;
26+ import java .time . Duration ;
2627import java .time .Instant ;
2728import java .time .temporal .ChronoUnit ;
2829import java .util .List ;
2930import java .util .Map ;
3031import java .util .UUID ;
3132
33+ import static java .nio .charset .StandardCharsets .UTF_8 ;
34+
3235/**
3336 * Tests the functionality of signing private Manta URLs for public access.
3437 *
@@ -53,7 +56,7 @@ public void beforeClass() throws IOException {
5356
5457 mantaClient = new MantaClient (config );
5558 testPathPrefix = IntegrationTestConfigContext .generateBasePath (config , this .getClass ().getSimpleName ());
56- mantaClient .putDirectory (testPathPrefix , null );
59+ mantaClient .putDirectory (testPathPrefix , true );
5760 }
5861
5962 @ AfterClass
@@ -155,7 +158,7 @@ public final void testCanCreateSignedPUTUriFromPath()
155158 connection .connect ();
156159
157160 try (OutputStreamWriter out = new OutputStreamWriter (
158- connection .getOutputStream (), StandardCharsets . UTF_8 )) {
161+ connection .getOutputStream (), UTF_8 )) {
159162 out .write (TEST_DATA );
160163 } finally {
161164 connection .disconnect ();
@@ -221,4 +224,25 @@ public final void testCanCreateSignedOPTIONSUriFromPath()
221224 connection .disconnect ();
222225 }
223226 }
227+
228+ @ Test
229+ public final void testCanCreateSignedURIWithEncodedCharacters () throws IOException {
230+ final String path = testPathPrefix + "⛰ quack 🦆" ;
231+
232+ mantaClient .put (path , TEST_DATA , UTF_8 );
233+ Assert .assertEquals (mantaClient .getAsString (path ), TEST_DATA );
234+
235+ final URI uri = mantaClient .getAsSignedURI (path , "GET" , Instant .now ().plus (Duration .ofHours (1 )));
236+ final HttpURLConnection conn = (HttpURLConnection ) uri .toURL ().openConnection ();
237+
238+ try (final InputStream is = conn .getInputStream ()) {
239+ conn .setReadTimeout (3000 );
240+ conn .connect ();
241+
242+ Assert .assertEquals (conn .getResponseCode (), HttpStatus .SC_OK );
243+ Assert .assertEquals (IOUtils .toString (is , UTF_8 ), TEST_DATA );
244+ } finally {
245+ conn .disconnect ();
246+ }
247+ }
224248}
0 commit comments