shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r795387 - /incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java
Date Sat, 18 Jul 2009 15:43:13 GMT
Author: lhazlewood
Date: Sat Jul 18 15:43:12 2009
New Revision: 795387

URL: http://svn.apache.org/viewvc?rev=795387&view=rev
Log:
Added another test case for sessionTimeout

Modified:
    incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java

Modified: incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java?rev=795387&r1=795386&r2=795387&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java
(original)
+++ incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java
Sat Jul 18 15:43:12 2009
@@ -19,9 +19,22 @@
 package org.apache.shiro.web;
 
 import org.apache.shiro.util.ThreadContext;
+import org.apache.shiro.session.Session;
+import org.apache.shiro.session.mgt.AbstractSessionManager;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.SimpleAuthenticationInfo;
+import org.apache.shiro.mgt.DefaultSecurityManager;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.Serializable;
 
 /**
  * @author Les Hazlewood
@@ -48,4 +61,43 @@
         sm.setSessionMode(DefaultWebSecurityManager.NATIVE_SESSION_MODE);
     }
 
+    protected void sleep(long millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Test
+    public void testSessionTimeout() {
+        shiroSessionModeInit();
+        long globalTimeout = 50;
+        sm.setGlobalSessionTimeout(globalTimeout);
+
+        HttpServletRequest mockRequest = createNiceMock(HttpServletRequest.class);
+        WebUtils.bind(mockRequest);
+        HttpServletResponse mockResponse = createNiceMock(HttpServletResponse.class);
+        WebUtils.bind(mockResponse);
+
+        expect(mockRequest.getCookies()).andReturn(null);
+        expect(mockRequest.getContextPath()).andReturn("/");
+
+        replay(mockRequest);
+
+        Subject subject = sm.getSubject();
+        Session session = subject.getSession();
+        Serializable origId = session.getId();
+        assertEquals(session.getTimeout(), globalTimeout);
+        session.setTimeout(100);
+        assertEquals(session.getTimeout(), 100);
+        sleep(100);
+        //now the underlying session should have been expired and a new one replaced by default.
+        //so ensure the replaced session has the default session timeout:
+        assertEquals(session.getTimeout(), globalTimeout);
+        assertFalse(origId.equals(session.getId())); //new ID would have been generated
+
+        //verify(mockRequest);
+    }
+
 }



Mime
View raw message