コード例 #1
0
  @Test
  public void testGetCredentialsValid() {
    ComponentContext context = configureForCookie();
    HttpServletRequest request = createMock(HttpServletRequest.class);
    Cookie[] cookies =
        new Cookie[] {
          new Cookie("sdfsd", "fsdfs"),
          new Cookie("sdfsd1", "fsdfs"),
          null,
          new Cookie("sdfsd3", "fsdfs"),
          new Cookie("sdfsd4", "fsdfs"),
        };
    EasyMock.expect(request.getCookies()).andReturn(cookies);
    HttpServletResponse response = createMock(HttpServletResponse.class);

    replay();
    trustedTokenService.activate(context);
    Cookie secureCookie = new Cookie("secure-cookie", trustedTokenService.encodeCookie("ieb"));
    cookies[2] = secureCookie;
    Credentials ieb = trustedTokenService.getCredentials(request, response);
    Assert.assertTrue(ieb instanceof SimpleCredentials);
    SimpleCredentials sc = (SimpleCredentials) ieb;
    TrustedUser tu = (TrustedUser) sc.getAttribute(TrustedTokenService.CA_AUTHENTICATION_USER);
    Assert.assertNotNull(tu);
    Assert.assertEquals("ieb", tu.getUser());
    verify();
  }
コード例 #2
0
 @Test
 public void testCookieEncodingSafety() {
   ComponentContext context = configureForCookie();
   replay();
   trustedTokenService.activate(context);
   Assert.assertNull(trustedTokenService.encodeCookie(null));
   Assert.assertNull(trustedTokenService.decodeCookie(null));
   verify();
 }
コード例 #3
0
 @Test
 public void testCookieNoRefresh() throws InterruptedException {
   ComponentContext context = configureForCookie();
   HttpServletResponse response = createMock(HttpServletResponse.class);
   replay();
   trustedTokenService.activate(context);
   String cookie = trustedTokenService.encodeCookie("ieb");
   Thread.sleep(10L);
   trustedTokenService.refreshToken(response, cookie, "ieb");
   verify();
 }
コード例 #4
0
 @Test
 public void testCookieEncodingTokens() throws InterruptedException {
   ComponentContext context = configureForCookieFast();
   replay();
   trustedTokenService.activate(context);
   String cookie = trustedTokenService.encodeCookie("ieb");
   Thread.sleep(30L);
   String cookie2 = trustedTokenService.encodeCookie("ieb2");
   String user = trustedTokenService.decodeCookie(cookie);
   Assert.assertNotNull(user);
   Assert.assertEquals("ieb", user);
   user = trustedTokenService.decodeCookie(cookie2);
   Assert.assertNotNull(user);
   Assert.assertEquals("ieb2", user);
   for (int i = 0; i < 20; i++) {
     Thread.sleep(50L);
     trustedTokenService.encodeCookie("ieb2");
   }
   verify();
 }
コード例 #5
0
 @Test
 public void testCookieEncodingSafety3() {
   ComponentContext context = configureForCookie();
   replay();
   trustedTokenService.activate(context);
   String cookie = trustedTokenService.encodeCookie("ieb");
   cookie = "a;" + cookie;
   String user = trustedTokenService.decodeCookie(cookie);
   Assert.assertNull(user);
   verify();
 }
コード例 #6
0
 @Test
 public void testCookieEncodingSafety4() {
   ComponentContext context = configureForCookie();
   replay();
   trustedTokenService.activate(context);
   String cookie = trustedTokenService.encodeCookie("ieb");
   System.err.println("Cookie is " + cookie);
   String[] parts = StringUtils.split(cookie, "@");
   parts[1] = String.valueOf(System.currentTimeMillis() - 3600000L);
   cookie = parts[0] + "@" + parts[1] + "@" + parts[2];
   String user = trustedTokenService.decodeCookie(cookie);
   Assert.assertNull(user);
   verify();
 }
コード例 #7
0
  @Test
  public void testCookieEncoding() {
    ComponentContext context = configureForCookie();
    replay();
    trustedTokenService.activate(context);

    String cookie = trustedTokenService.encodeCookie("ieb");
    String user = trustedTokenService.decodeCookie(cookie);
    Assert.assertNotNull(user);
    Assert.assertEquals("ieb", user);

    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
      cookie = trustedTokenService.encodeCookie("ieb");
    }
    System.err.println("Encode Time " + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
      user = trustedTokenService.decodeCookie(cookie);
    }
    System.err.println("Decode Time " + (System.currentTimeMillis() - start));

    verify();
  }
コード例 #8
0
 @Test
 public void testCookieRefresh() throws InterruptedException {
   ComponentContext context = configureForCookieFast();
   HttpServletResponse response = createMock(HttpServletResponse.class);
   Capture<Cookie> cookieCapture = new Capture<Cookie>();
   response.addCookie(EasyMock.capture(cookieCapture));
   EasyMock.expectLastCall();
   replay();
   trustedTokenService.activate(context);
   String cookie = trustedTokenService.encodeCookie("ieb");
   Thread.sleep(100L);
   trustedTokenService.refreshToken(response, cookie, "ieb");
   Assert.assertTrue(cookieCapture.hasCaptured());
   Cookie cookie2 = cookieCapture.getValue();
   Assert.assertNotNull(cookie);
   Assert.assertNotSame(cookie, cookie2.getValue());
   Assert.assertEquals("secure-cookie", cookie2.getName());
   String user = trustedTokenService.decodeCookie(cookie2.getValue());
   Assert.assertEquals("ieb", user);
   verify();
 }