@Test public void verifyNullSignature( @Mocked(stubOutClassInitialization = true) final LocalTime localTime) { final AbstractStoredObject object = createStoredObjectForTempURL("welkom#42"); assertFalse( "This signature is null and therefore invalid", object.verifyTempUrl("GET", null, 123456789)); }
protected boolean verifyTempURL( final LocalTime localTime, final String method, String plainText, long expiryInSeconds) { final String password = "******"; final long todayInMS = 1369581129861L; final AbstractStoredObject object = createStoredObjectForTempURL(password); useFixedDateForToday(todayInMS); String signature = HashSignature.getSignature(password, plainText); return object.verifyTempUrl(method, signature, expiryInSeconds); }
@Test public void requiresSegmentation() { final UploadInstructions instructions = new UploadInstructions(new byte[] {0x01}); new NonStrictExpectations(instructions) { { instructions.requiresSegmentation(); result = true; } }; Container container1 = account.getContainer("alpha"); final AbstractStoredObject object = (AbstractStoredObject) container1.getObject("alpha"); new Expectations(object) { { object.uploadObjectAsSegments(instructions); result = null; times = 1; } }; object.uploadObject(instructions); }
protected void testTempUrl(final String method, final LocalTime localTime) { final String password = "******"; final long todayInMS = 1369581129861L; final long oneDayInSeconds = 86400L; final long tomorrowInSeconds = todayInMS / 1000 + oneDayInSeconds; final AbstractStoredObject object = createStoredObjectForTempURL(password); // Make sure that a fixed date is used useFixedDateForToday(todayInMS); // Check whether the secure URL contains the right signature and expiry date final String secureUrl; if (method.equals("GET")) { secureUrl = object.getTempGetUrl(oneDayInSeconds); } else { secureUrl = object.getTempPutUrl(oneDayInSeconds); } assertTrue( "Does not contain the timestamp of 'tomorrow'", secureUrl.contains(Long.toString(tomorrowInSeconds))); String plainText = method + "\n" + tomorrowInSeconds + "\n/internal/path/alpha/some-image.jpg"; String signature = HashSignature.getSignature(password, plainText); assertTrue("The signature of the secure URL", secureUrl.contains(signature)); }