@Test public void testSignGetUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text); } finally { returnContainer(container); } }
@Test public void testSignPutUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { HttpRequest request = view.getSigner().signPutBlob(container, blob); assertEquals(request.getFilters().size(), 0); Strings2.toString(view.utils().http().invoke(request).getPayload()); assertConsistencyAwareContainerSize(container, 1); } finally { returnContainer(container); } }
@Test public void testSignGetUrlOptions() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1)); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), "fo"); } finally { returnContainer(container); } }
@Test public void testSignPutUrlWithTime() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { HttpRequest request = view.getSigner().signPutBlob(container, blob, 3 /* seconds */); assertEquals(request.getFilters().size(), 0); Strings2.toString(view.utils().http().invoke(request).getPayload()); assertConsistencyAwareContainerSize(container, 1); view.getBlobStore().removeBlob(container, name); assertConsistencyAwareContainerSize(container, 0); TimeUnit.SECONDS.sleep(4); try { Strings2.toString(view.utils().http().invoke(request).getPayload()); fail("Temporary URL did not expire as expected"); } catch (AuthorizationException expected) { } } catch (UnsupportedOperationException ignore) { throw new SkipException("signPutUrl with a time limit is not supported on " + provider); } finally { returnContainer(container); } }
@Test public void testSignGetUrlWithTime() throws InterruptedException, IOException { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, getSignedUrlTimeout()); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), text); } finally { returnContainer(container); } }
@Test public void testSignGetUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), text); } finally { returnContainer(container); } }
@Test public void testSignGetUrlOptions() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1)); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), "fo"); } finally { returnContainer(container); } }
@Test public void testSignGetUrlWithTime() throws InterruptedException, IOException { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, 3 /* seconds */); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text); TimeUnit.SECONDS.sleep(4); try { Strings2.toString(view.utils().http().invoke(request).getPayload()); fail("Temporary URL did not expire as expected"); } catch (AuthorizationException expected) { } } catch (UnsupportedOperationException ignore) { throw new SkipException("signGetUrl with a time limit is not supported on " + provider); } finally { returnContainer(container); } }
@Test public void testSignRemoveUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signRemoveBlob(container, name); assertEquals(request.getFilters().size(), 0); view.utils().http().invoke(request); assert !view.getBlobStore().blobExists(container, name); } finally { returnContainer(container); } } }
public void testSignGetUrlWithTime(final long timeout) throws InterruptedException, IOException { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, timeout); assertEquals(request.getFilters().size(), 0); try { Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()); fail("Temporary URL did not expire as expected"); } catch (AuthorizationException expected) { } } finally { returnContainer(container); } }