### Question:
S3V4Authentication { static void validateExpiresFromParams(Map<String, String> parameters, Date date) throws AccessDeniedException { String expires = parameters.get(AWS_EXPIRES_PARAM); if (expires == null) throw new AccessDeniedException(null, "X-Amz-Expires parameter must be specified."); Long expireTime; try { expireTime = Long.parseLong(expires); } catch (NumberFormatException e) { throw new AccessDeniedException(null, "Invalid X-Amz-Expires parameter."); } if (expireTime < 1 || expireTime > 604800) throw new AccessDeniedException(null, "Invalid Expires parameter."); DateTime currentTime = DateTime.now(); DateTime dt = new DateTime(date); if (currentTime.isBefore(dt.minusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT))) throw new AccessDeniedException(null, "Cannot process request. X-Amz-Date is not yet valid."); if (currentTime.isAfter(dt.plusSeconds(expireTime.intValue() + StackConfiguration.CLOCK_SKEW_SEC))) throw new AccessDeniedException(null, "Cannot process request. Expired."); } private  S3V4Authentication();  static final String AWS_V4_AUTH_TYPE; static final String AWS_CONTENT_SHA_HEADER; static final String AWS_EXPIRES_PARAM; static final String AWS_DECODED_CONTENT_LEN; static final String STREAMING_PAYLOAD; static final String UNSIGNED_PAYLOAD; }### Answer:
@Test public void testValidateExpiresFromParams() throws Throwable { Map<String, String> params = new HashMap<>(); params.put(AWS_EXPIRES_PARAM, "10"); S3V4Authentication.validateExpiresFromParams(params, DateTime.now().toDate()); try { S3V4Authentication.validateExpiresFromParams(params, DateTime.now().plusMinutes(20).toDate()); fail("Date should have been not yet valid"); } catch (AccessDeniedException expected) { assertTrue(expected.getMessage().contains("not yet valid")); } S3V4Authentication.validateExpiresFromParams(params, DateTime.now().minusSeconds(8).toDate()); try { S3V4Authentication.validateExpiresFromParams(params, DateTime.now().minusSeconds(40).toDate()); fail("Date should have been expired"); } catch (AccessDeniedException expected) { assertTrue(expected.getMessage().toLowerCase().contains("expired")); } }