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/07/24 22:55:41 UTC

svn commit: r1365275 - in /shiro/branches/1.2.x: core/src/test/groovy/org/apache/shiro/realm/AuthenticatingRealmIntegrationTest.groovy core/src/test/groovy/org/apache/shiro/realm/TestAuthenticatingRealm.groovy pom.xml

Author: lhazlewood
Date: Tue Jul 24 20:55:41 2012
New Revision: 1365275

URL: http://svn.apache.org/viewvc?rev=1365275&view=rev
Log:
SHIRO-354: provided integration test verifying correct functionality

Added:
    shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/AuthenticatingRealmIntegrationTest.groovy
    shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/TestAuthenticatingRealm.groovy
Modified:
    shiro/branches/1.2.x/pom.xml

Added: shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/AuthenticatingRealmIntegrationTest.groovy
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/AuthenticatingRealmIntegrationTest.groovy?rev=1365275&view=auto
==============================================================================
--- shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/AuthenticatingRealmIntegrationTest.groovy (added)
+++ shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/AuthenticatingRealmIntegrationTest.groovy Tue Jul 24 20:55:41 2012
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.realm
+
+import org.apache.shiro.authc.AuthenticationToken
+import org.apache.shiro.authc.UsernamePasswordToken
+import org.apache.shiro.config.Ini
+import org.apache.shiro.config.IniSecurityManagerFactory
+import org.apache.shiro.mgt.SecurityManager
+import org.apache.shiro.subject.Subject
+
+/**
+ * Integration tests for the AuthenticatingRealm implementation.
+ *
+ * @since 1.2.1
+ */
+class AuthenticatingRealmIntegrationTest extends GroovyTestCase {
+
+    void testShiro354() {
+
+        Ini ini = new Ini();
+        ini.load('''
+
+        [main]
+        realm = org.apache.shiro.realm.TestAuthenticatingRealm
+        securityManager.realms = $realm
+        cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
+        securityManager.cacheManager = $cacheManager
+        # if you comment this line out, the test will fail as expected:
+        realm.authenticationCachingEnabled = true
+
+        ''');
+
+        SecurityManager sm = new IniSecurityManagerFactory(ini).getInstance();
+
+        AuthenticationToken token = new UsernamePasswordToken("user1", "secret");
+
+        Subject subject = new Subject.Builder(sm).buildSubject();
+        subject.login(token);
+
+        Subject subject2 = new Subject.Builder(sm).buildSubject();
+        subject2.login(token);
+
+        //2 login calls for the same account, but the count on realm.doGetAuthenticationInfo should only be 1 due to caching:
+        assertEquals 1, sm.getRealms().iterator().next().authenticationInfoCount
+    }
+}

Added: shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/TestAuthenticatingRealm.groovy
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/TestAuthenticatingRealm.groovy?rev=1365275&view=auto
==============================================================================
--- shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/TestAuthenticatingRealm.groovy (added)
+++ shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/realm/TestAuthenticatingRealm.groovy Tue Jul 24 20:55:41 2012
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.realm
+
+import org.apache.shiro.authc.AuthenticationInfo
+import org.apache.shiro.authc.AuthenticationToken
+import org.apache.shiro.authc.SimpleAccount
+
+/**
+ * Used by the AuthenticatingRealmIntegrationTest.
+ *
+ * @since 1.2.1
+ */
+class TestAuthenticatingRealm extends AuthenticatingRealm {
+
+    int authenticationInfoCount = 0;
+
+    @Override
+    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
+        authenticationInfoCount++
+        return new SimpleAccount("user1", "secret", getName());
+    }
+}

Modified: shiro/branches/1.2.x/pom.xml
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/pom.xml?rev=1365275&r1=1365274&r2=1365275&view=diff
==============================================================================
--- shiro/branches/1.2.x/pom.xml (original)
+++ shiro/branches/1.2.x/pom.xml Tue Jul 24 20:55:41 2012
@@ -361,6 +361,14 @@
                     <encoding>${project.build.sourceEncoding}</encoding>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.12</version>
+                <configuration>
+                    <printSummary>true</printSummary>
+                </configuration>
+            </plugin>
             <!-- Allow Groovy tests to run: -->
             <plugin>
                 <groupId>org.codehaus.gmaven</groupId>