You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/10/16 07:37:52 UTC

svn commit: r464384 - /incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/LoginContextTest.java

Author: smishura
Date: Sun Oct 15 22:37:51 2006
New Revision: 464384

URL: http://svn.apache.org/viewvc?view=rev&rev=464384
Log:
Regression test for HARMONY-771 ([classlib][security] different exceptions for javax.security.auth.login.LoginContext(String name) LoginException vs. SecurityException)

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=464384&r1=464383&r2=464384
==============================================================================
--- 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 Sun Oct 15 22:37:51 2006
@@ -22,10 +22,12 @@
 
 package org.apache.harmony.auth.tests.javax.security.auth.login;
 
+import java.io.File;
 import java.security.Security;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.Map;
+import java.util.Properties;
 
 import javax.security.auth.Subject;
 import javax.security.auth.callback.Callback;
@@ -38,13 +40,18 @@
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.auth.tests.support.TestUtils;
+
+import tests.support.Support_Exec;
 
 /**
  * Tests LoginContext class
  */
-
 public class LoginContextTest extends TestCase {
 
+    // system property to specify another login configuration file 
+    private static final String AUTH_LOGIN_CONFIG = "java.security.auth.login.config";
+
     public static void main(String[] args) {
         junit.textui.TestRunner.run(LoginContextTest.class);
     }
@@ -747,6 +754,59 @@
     public final void testGetSubject() {
         //TODO Implement getSubject().
         // test failed login
+    }
+
+    /**
+     * @tests javax.security.auth.login.LoginContext
+     */
+    public void test_LoginContext_defaultConfigProvider() throws Exception {
+
+        // test: LoginContext constructor fails because there are no config
+        // files to be read (the test is modification of test case
+        // in ConfigurationTest)
+
+        // no login.config.url.N security properties should be set
+        String javaSecurityFile = TestUtils
+                .createJavaPropertiesFile(new Properties());
+
+        // tmp user home to avoid presence of ${user.home}/.java.login.config
+        String tmpUserHome = System.getProperty("java.io.tmpdir")
+                + File.separatorChar + "tmpUserHomeForLogingContextTest";
+        File dir = new File(tmpUserHome);
+        if (!dir.exists()) {
+            dir.mkdirs();
+            dir.deleteOnExit();
+        }
+        String javaLoginConfig = tmpUserHome + File.separatorChar
+                + ".java.login.config";
+        assertFalse("There should be no login config file: " + javaLoginConfig,
+                new File(javaLoginConfig).exists());
+
+        String[] arg = new String[] { "-Duser.home=" + tmpUserHome,
+                "-Djava.security.properties=" + javaSecurityFile,
+                NoConfigFileToBeRead.class.getName() };
+
+        Support_Exec.execJava(arg, null, true);
+    }
+
+    public static class NoConfigFileToBeRead {
+
+        // the test is based on assumption that security properties 
+        // login.config.url.N are unset and there is no file
+        // ${user.home}/.java.login.config
+        public static void main(String[] args) throws LoginException {
+
+            //reset path to alternative configuration file
+            TestUtils.setSystemProperty(AUTH_LOGIN_CONFIG, null);
+
+            Configuration.setConfiguration(null); // reset default config
+            try {
+                // Regression for HARMONY-771
+                new LoginContext("0"); 
+                TestCase.fail("No expected SecurityException");
+            } catch (SecurityException e) {
+            }
+        }
     }
 
     private static class MyConfig extends Configuration {