harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r464903 - in /incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth: login/DefaultConfigurationTest.java tests/javax/security/auth/login/ConfigurationTest.java tests/support/TestUtils.java
Date Tue, 17 Oct 2006 11:24:38 GMT
Author: smishura
Date: Tue Oct 17 04:24:37 2006
New Revision: 464903

URL: http://svn.apache.org/viewvc?view=rev&rev=464903
Log:
Move

DefaultConfigurationTest.testLoadConfigFile
  to
ConfigurationTest.test_defaultProvider_securityProperties

and update it to make it implementation independent

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java?view=diff&rev=464903&r1=464902&r2=464903
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java
Tue Oct 17 04:24:37 2006
@@ -23,11 +23,8 @@
 package org.apache.harmony.auth.login;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStream;
 import java.security.Permission;
-import java.security.Security;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -37,7 +34,6 @@
 import junit.framework.TestCase;
 
 import org.apache.harmony.auth.tests.support.TestUtils;
-import org.apache.harmony.auth.login.DefaultConfiguration;
 
 import tests.support.resource.Support_Resources;
 
@@ -52,75 +48,21 @@
     static String otherConfFile = Support_Resources
             .getAbsoluteResourcePath("auth.conf");
 
-	private static File defaultConfFile;
-
 	static AppConfigurationEntry[] ents;
 
 	SecurityManager old = System.getSecurityManager();
 
-	String oldp1;
-	String oldp2;
-
-	@Override
-    public void setUp() throws Exception {
-		createConfFile();
-		
-		oldp1 = Security.getProperty("login.config.url.1");
-		oldp2 = Security.getProperty("login.config.url.2");
-	}
-
 	@Override
     public void tearDown() throws Exception {
 		System.setSecurityManager(old);
-
-		TestUtils.setSystemProperty("login.config.url.1", oldp1);
-		TestUtils.setSystemProperty("login.config.url.2", oldp2);
-
-		defaultConfFile.delete();
 	}
 
 	public static void main(String[] args) {
 		junit.textui.TestRunner.run(DefaultConfigurationTest.class);
 	}
 	
-	/**
-	 * loading a config file specified on the security property  
-	 * using login.config.url.1
-	 * XXX: load a default config file
-	 */
-	public static void testLoadConfigFile() throws Exception {
-			Security.setProperty("login.config.url.1", "file:"
-					+ defaultConfFile.getCanonicalPath());
-			Security.setProperty("login.config.url.2", "file:"
-					+ new File(otherConfFile).getCanonicalPath());
-
-            DefaultConfiguration dc = new DefaultConfiguration();
-			ents = dc.getAppConfigurationEntry("LoginNew");
-			assertNotNull(ents);
-			assertEquals("com.intel.security.auth.module.LoginModule1", ents[0].getLoginModuleName());
-			Map<String, String> m = new HashMap<String, String>();
-			m.put("debug", "true");
-			m.put("test", "false");
-			assertEquals(m, ents[0].getOptions());
-			assertEquals("LoginModuleControlFlag: optional", ents[0].getControlFlag().toString());
-
-			ents = dc.getAppConfigurationEntry("Login1");
-			assertNotNull(ents);
-			for (AppConfigurationEntry element : ents) {
-				assertEquals("com.intel.security.auth.module.LoginModule1",
-						element.getLoginModuleName());
-				m.clear();
-				m.put("debug1", "true");
-				m.put("test1", "false");
-				assertEquals(m, element.getOptions());
-				assertEquals("LoginModuleControlFlag: required", element
-						.getControlFlag().toString());
-			}
-			
-			
-			
-	}
-	/**
+
+    /**
 	 * loading a config file specified on the system property
 	 * using -Djava.security.auth.login.config    
 	 */
@@ -211,23 +153,6 @@
 		    TestUtils.setSystemProperty(LOGIN_CONFIG, oldp);
 		}
 
-	}
-
-	private static void createConfFile() throws SecurityException, IOException {
-		
-		defaultConfFile = File.createTempFile(".java.login.config", null);
-
-		String newConfFile = "LoginNew {\n com.intel.security.auth.module.LoginModule1 optional"
-			+ " debug=\"true\" test=false;\n};";
-
-		byte[] b = newConfFile.getBytes();
-
-		OutputStream os = new FileOutputStream(defaultConfFile);
-		for (byte element : b) {
-			os.write(element);
-		}
-		os.flush();
-		os.close();
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.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/ConfigurationTest.java?view=diff&rev=464903&r1=464902&r2=464903
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
Tue Oct 17 04:24:37 2006
@@ -23,7 +23,10 @@
 package org.apache.harmony.auth.tests.javax.security.auth.login;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.security.Security;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.security.auth.AuthPermission;
@@ -49,6 +52,10 @@
     // security property to specify default configuration implementation 
     private static final String LOGIN_CONFIG_PROVIDER = "login.configuration.provider";
 
+    // testing config file 
+    private static String testConfFile = Support_Resources
+            .getAbsoluteResourcePath("auth.conf");
+
 	/**
 	 * Ease the configuration class
 	 */
@@ -78,9 +85,8 @@
     protected void setUp() {
 
         // point to some existing file to be read 
-        String testConfig = Support_Resources
-                .getAbsoluteResourcePath("auth.conf");
-        oldAuthConfig = System.setProperty(AUTH_LOGIN_CONFIG, "=" + testConfig);
+        oldAuthConfig = System.setProperty(AUTH_LOGIN_CONFIG, "="
+                + testConfFile);
 
         defaultConfig = Configuration.getConfiguration();
 
@@ -226,6 +232,83 @@
                 Configuration.getConfiguration();
                 fail("No expected SecurityException");
             } catch (SecurityException e) {
+            }
+        }
+    }
+    
+    /**
+     * Tests loading config files specified with the security properties  
+     * login.config.url.N
+     * 
+     * TODO create test for loading a default config file:
+     * ${user.home}/.java.login.config
+     */
+    public void test_defaultProvider_securityProperties() throws Exception {
+
+        // create tmp config file
+        File tmpConfFile = File.createTempFile("login", "config");
+        tmpConfFile.deleteOnExit();
+        
+        String newConfFile = "LoginNew {\n org.apache.harmony.auth.module.LoginModule1 optional"
+                + " debug=\"true\" test=false;\n};";
+
+        FileOutputStream out = new FileOutputStream(tmpConfFile);
+        out.write(newConfFile.getBytes());
+        out.close();
+        
+        // set up security properties
+        Properties props = new Properties();
+        props.setProperty("login.config.url.1", "file:"
+                + tmpConfFile.getCanonicalPath());
+        props.setProperty("login.config.url.2", "file:"
+                + new File(testConfFile).getCanonicalPath());
+        String javaSecurityFile = TestUtils
+                .createJavaPropertiesFile(props);
+
+        // run test
+        String[] arg = new String[] {
+                "-Djava.security.properties=" + javaSecurityFile,
+                SecurityPropertiesToBeRead.class.getName() };
+        
+        Support_Exec.execJava(arg, null, true);
+    }
+    
+    public static class SecurityPropertiesToBeRead {
+
+        // the test is based on assumption that security properties 
+        // login.config.url.1 and login.config.url.1 are set
+        public static void main(String[] args) {
+
+            //reset path to alternative configuration file
+            TestUtils.setSystemProperty(AUTH_LOGIN_CONFIG, null);
+
+            Configuration.setConfiguration(null); // reset default config
+
+            Configuration config = Configuration.getConfiguration();
+
+            AppConfigurationEntry[] ents = config
+                    .getAppConfigurationEntry("LoginNew");
+            assertNotNull(ents);
+            assertEquals("org.apache.harmony.auth.module.LoginModule1", ents[0]
+                    .getLoginModuleName());
+            Map<String, String> m = new HashMap<String, String>();
+            m.put("debug", "true");
+            m.put("test", "false");
+            assertEquals(m, ents[0].getOptions());
+            assertEquals("LoginModuleControlFlag: optional", ents[0]
+                    .getControlFlag().toString());
+
+            ents = config.getAppConfigurationEntry("Login1");
+            assertNotNull(ents);
+            for (AppConfigurationEntry element : ents) {
+                assertEquals("com.intel.security.auth.module.LoginModule1",
+                        element.getLoginModuleName());
+                m.clear();
+                m.put("debug1", "true");
+                m.put("test1", "false");
+                assertEquals(m, element.getOptions());
+                assertEquals("LoginModuleControlFlag: required", element
+                        .getControlFlag().toString());
             }
         }
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java?view=diff&rev=464903&r1=464902&r2=464903
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java
Tue Oct 17 04:24:37 2006
@@ -102,7 +102,7 @@
 
         FileOutputStream out = new FileOutputStream(f);
 
-        Properties propsToFlush = new Properties(props);
+        Properties propsToFlush = new Properties();
         
         int i = 1;
         String provider = "security.provider.1";
@@ -111,6 +111,7 @@
             provider = "security.provider." + i++;
         }
 
+        props.store(out, null);
         propsToFlush.store(out, null);
 
         out.close();



Mime
View raw message