Search in sources :

Example 1 with CryptoException

use of org.apache.shiro.crypto.CryptoException in project shiro by apache.

the class CookieRememberMeManagerTest method getRememberedPrincipalsDecryptionError.

// SHIRO-69
@Test
public void getRememberedPrincipalsDecryptionError() {
    HttpServletRequest mockRequest = createNiceMock(HttpServletRequest.class);
    HttpServletResponse mockResponse = createNiceMock(HttpServletResponse.class);
    WebSubjectContext context = new DefaultWebSubjectContext();
    context.setServletRequest(mockRequest);
    context.setServletResponse(mockResponse);
    expect(mockRequest.getAttribute(ShiroHttpServletRequest.IDENTITY_REMOVED_KEY)).andReturn(null);
    // Simulate a bad return value here (for example if this was encrypted with a different key
    final String userPCAesBase64 = "garbage";
    Cookie[] cookies = new Cookie[] { new Cookie(CookieRememberMeManager.DEFAULT_REMEMBER_ME_COOKIE_NAME, userPCAesBase64) };
    expect(mockRequest.getCookies()).andReturn(cookies).anyTimes();
    replay(mockRequest);
    CookieRememberMeManager mgr = new CookieRememberMeManager();
    try {
        mgr.getRememberedPrincipals(context);
    } catch (CryptoException expected) {
        return;
    }
    fail("CryptoException was expected to be thrown");
}
Also used : ShiroHttpServletRequest(org.apache.shiro.web.servlet.ShiroHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) DefaultWebSubjectContext(org.apache.shiro.web.subject.support.DefaultWebSubjectContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebSubjectContext(org.apache.shiro.web.subject.WebSubjectContext) DefaultWebSubjectContext(org.apache.shiro.web.subject.support.DefaultWebSubjectContext) CryptoException(org.apache.shiro.crypto.CryptoException) Test(org.junit.Test)

Aggregations

Cookie (javax.servlet.http.Cookie)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CryptoException (org.apache.shiro.crypto.CryptoException)1 ShiroHttpServletRequest (org.apache.shiro.web.servlet.ShiroHttpServletRequest)1 SimpleCookie (org.apache.shiro.web.servlet.SimpleCookie)1 WebSubjectContext (org.apache.shiro.web.subject.WebSubjectContext)1 DefaultWebSubjectContext (org.apache.shiro.web.subject.support.DefaultWebSubjectContext)1 Test (org.junit.Test)1