harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r472464 - in /incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login: LoginContext2Test.java LoginContextTest.java
Date Wed, 08 Nov 2006 12:19:47 GMT
Author: smishura
Date: Wed Nov  8 04:19:47 2006
New Revision: 472464

URL: http://svn.apache.org/viewvc?view=rev&rev=472464
Log:
Move test case test_login_resourcesLeakage: LoginContext2Test -> LoginContextTest

Removed:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/LoginContext2Test.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/LoginContextTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/LoginContextTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/LoginContextTest.java?view=diff&rev=472464&r1=472463&r2=472464
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/LoginContextTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/LoginContextTest.java
Wed Nov  8 04:19:47 2006
@@ -25,6 +25,7 @@
 import java.io.File;
 import java.security.Security;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;
@@ -36,6 +37,7 @@
 import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
 import javax.security.auth.spi.LoginModule;
 
 import junit.framework.TestCase;
@@ -803,6 +805,68 @@
                 fail("No expected SecurityException");
             } catch (SecurityException e) {
             }
+        }
+    }
+    /**
+     * @tests javax.security.auth.login.LoginContext.login()
+     */
+    public void test_login_resourcesLeakage() throws Exception {
+
+        // This is a compatibility test.
+        // The test verifies that LoginContext allows to invoke login() method
+        // multiple times without invoking logout() before. In testing scenario
+        // each login() invocation adds new credentials to the passed subject.
+        Configuration.setConfiguration(new Configuration() {
+
+            @Override
+            public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
+                return new AppConfigurationEntry[] { new AppConfigurationEntry(
+                        MyModule.class.getName(),
+                        LoginModuleControlFlag.REQUIRED,
+                        new HashMap<String, Object>()) };
+            }
+
+            @Override
+            public void refresh() {
+            }
+        });
+
+        LoginContext context = new LoginContext("moduleName", new Subject());
+
+        context.login();
+        context.login();
+
+        Subject subject = context.getSubject();
+
+        assertEquals(2, subject.getPrivateCredentials().size());
+        assertEquals(2, subject.getPublicCredentials().size());
+    }
+
+    public static class MyModule implements LoginModule {
+
+        Subject sub;
+
+        public boolean abort() throws LoginException {
+            return false;
+        }
+
+        public boolean commit() throws LoginException {
+            sub.getPrivateCredentials().add(new Object());
+            return true;
+        }
+
+        public void initialize(Subject arg0, CallbackHandler arg1,
+                Map<String, ?> arg2, Map<String, ?> arg3) {
+            sub = arg0;
+        }
+
+        public boolean login() throws LoginException {
+            sub.getPublicCredentials().add(new Object());
+            return true;
+        }
+
+        public boolean logout() throws LoginException {
+            return false;
         }
     }
 



Mime
View raw message