コード例 #1
0
  /**
   * Expect that a policy with the configuration of 'ValidationOptional' still permits the request
   * to the back-end service even if the session cookie is present but for an expired session.
   *
   * @throws Throwable
   */
  @Test
  @Configuration(classpathConfigFile = "validation-optional-config.json")
  @BackEndApi(EchoBackEndApi.class)
  public void testExpiredSessionRequestSuccessValidationOptional() throws Throwable {
    // test data - session has already expired
    final Session originalSession = CommonTestUtil.insertTestSession(-60, true);

    // make request
    final Session updatedSession = makeSessionRequest(originalSession, false);

    // verify expiry not updated
    assertTrue(updatedSession.getExpires() == originalSession.getExpires());
  }
コード例 #2
0
  /**
   * Expect that a policy with the configuration of 'ValidationOptional' permits the request to the
   * back-end service if the cookie is present and the session is valid.
   *
   * @throws Throwable
   */
  @Test
  @Configuration(classpathConfigFile = "validation-optional-config.json")
  @BackEndApi(RequiresAuthHeaderBackEndApi.class)
  public void testAuthenticatedRequestSuccessValidationOptional() throws Throwable {
    // test data - session expires in 60s
    final Session originalSession = CommonTestUtil.insertTestSession(60, true);

    // make request
    final Session updatedSession = makeSessionRequest(originalSession, true);

    // verify expiry updated
    assertTrue(TimeUtil.isAfterNow(updatedSession.getExpires()));
    assertTrue(updatedSession.getExpires() > originalSession.getExpires());
  }
コード例 #3
0
  /**
   * Send the request and expect a 401 Unauthorized response, and for session data to remain
   * unchanged.
   *
   * @param request the service request
   * @param originalSession the Session state before the request is made
   * @throws Throwable
   */
  private void sendAndExpect401(PolicyTestRequest request, Session originalSession)
      throws Throwable {
    try {
      send(request);
      fail(PolicyFailureError.class + " expected");

    } catch (PolicyFailureError failure) {
      assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, failure.getFailure().getFailureCode());
      assertEquals(PolicyFailureType.Authentication, failure.getFailure().getType());

      // verify the session data in the shared state has not changed
      final Session updatedSession = CommonTestUtil.fetchSession(originalSession.getSessionId());
      assertNotNull(updatedSession);
      assertEquals(originalSession.getSessionId(), updatedSession.getSessionId());

      // verify expiry not updated
      assertEquals(originalSession.getExpires(), updatedSession.getExpires());
    }
  }