You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lh...@apache.org on 2012/10/30 22:40:21 UTC

svn commit: r1403880 - /shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/mgt/DefaultSubjectDAOTest.groovy

Author: lhazlewood
Date: Tue Oct 30 21:40:20 2012
New Revision: 1403880

URL: http://svn.apache.org/viewvc?rev=1403880&view=rev
Log:
SHIRO-380: added unit test for DelegatingSubject interaction

Modified:
    shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/mgt/DefaultSubjectDAOTest.groovy

Modified: shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/mgt/DefaultSubjectDAOTest.groovy
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/mgt/DefaultSubjectDAOTest.groovy?rev=1403880&r1=1403879&r2=1403880&view=diff
==============================================================================
--- shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/mgt/DefaultSubjectDAOTest.groovy (original)
+++ shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/mgt/DefaultSubjectDAOTest.groovy Tue Oct 30 21:40:20 2012
@@ -23,6 +23,7 @@ import org.apache.shiro.subject.Principa
 import org.apache.shiro.subject.Subject
 import org.apache.shiro.subject.support.DefaultSubjectContext
 import static org.easymock.EasyMock.*
+import org.apache.shiro.subject.support.DelegatingSubject
 
 /**
  * Unit tests for the {@link DefaultSubjectDAO} implementation.
@@ -142,6 +143,32 @@ class DefaultSubjectDAOTest extends Groo
     // BEGIN: mergePrincipals tests
 
     /**
+     * SHIRO-380
+     */
+    void testMergePrincipalsWithDelegatingSubject() {
+
+        def sessionId = "sessionId"
+
+        def principals = createStrictMock(PrincipalCollection)
+        def runAsPrincipals = createStrictMock(PrincipalCollection)
+        def session = createStrictMock(Session)
+        def securityManager = createStrictMock(SecurityManager)
+
+        expect(session.getId()).andStubReturn sessionId
+        expect(session.getAttribute(eq(DelegatingSubject.RUN_AS_PRINCIPALS_SESSION_KEY))).andReturn(Arrays.asList(runAsPrincipals))
+        expect(principals.isEmpty()).andStubReturn false
+        expect(session.getAttribute(eq(DefaultSubjectContext.PRINCIPALS_SESSION_KEY))).andReturn null
+        session.setAttribute(eq(DefaultSubjectContext.PRINCIPALS_SESSION_KEY), same(principals));
+
+        replay principals, runAsPrincipals, session, securityManager
+
+        def subject = new DelegatingSubject(principals, true, "localhost", session, true, securityManager)
+        new DefaultSubjectDAO().mergePrincipals(subject)
+
+        verify principals, runAsPrincipals, session, securityManager
+    }
+
+    /**
      * Tests the case when the Subject has principals but no session yet.  In this case, a session will be created
      * and the session will be set with the principals.
      */