diff options
author | Elliott Hughes <enh@google.com> | 2011-06-06 15:08:17 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2011-06-06 15:08:17 -0700 |
commit | 686dd6f676dc348ac260f54e544cf8d813df64a9 (patch) | |
tree | c8315e6e164773421b37cfce2805e3382a383e56 | |
parent | c320b4381faed584a33ed69f53076dd32193144d (diff) | |
download | libcore-686dd6f676dc348ac260f54e544cf8d813df64a9.zip libcore-686dd6f676dc348ac260f54e544cf8d813df64a9.tar.gz libcore-686dd6f676dc348ac260f54e544cf8d813df64a9.tar.bz2 |
Remove dead tests.
Change-Id: Ife89885ea95de3bb2617172b95cdfd46d586a644
36 files changed, 0 insertions, 4440 deletions
diff --git a/luni/src/test/java/libcore/java/io/OldFilePermissionTest.java b/luni/src/test/java/libcore/java/io/OldFilePermissionTest.java deleted file mode 100644 index 66fbbf6..0000000 --- a/luni/src/test/java/libcore/java/io/OldFilePermissionTest.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * 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 libcore.java.io; - -import java.io.File; -import java.io.FilePermission; -import java.security.PermissionCollection; - -public class OldFilePermissionTest extends junit.framework.TestCase { - - FilePermission readAllFiles; - FilePermission alsoReadAllFiles; - FilePermission allInCurrent; - FilePermission readInCurrent; - FilePermission readInFile; - - @Override protected void setUp() throws Exception { - super.setUp(); - - readAllFiles = new FilePermission("<<ALL FILES>>", "read"); - alsoReadAllFiles = new FilePermission("<<ALL FILES>>", "read"); - allInCurrent = new FilePermission("*", "read, write, execute,delete"); - readInCurrent = new FilePermission("*", "read"); - readInFile = new FilePermission("aFile.file", "read"); - } - - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.io.FilePermission(java.lang.String, - // java.lang.String) - assertTrue("Used to test", true); - FilePermission constructFile = new FilePermission("test constructor", - "write"); - assertEquals("action given to the constructor did not correspond - constructor failed", - "write", constructFile.getActions()); - assertEquals( - "name given to the constructor did not correspond - constructor failed", - "test constructor", constructFile.getName()); - - // Regression test for HARMONY-1050 - try { - new FilePermission(null, "drink"); - fail("Expected IAE"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - new FilePermission(null, "read"); - fail("Expected NPE"); - } catch (NullPointerException e) { - // Expected - } - - try { - new FilePermission(null, null); - fail("Expected IAE"); - } catch (IllegalArgumentException e) { - // Expected - } - } - - public void test_getActions() { - // Test for method java.lang.String java.io.FilePermission.getActions() - assertEquals("getActions should have returned only read", "read", readAllFiles - .getActions()); - assertEquals("getActions should have returned all actions", "read,write,execute,delete", allInCurrent - .getActions()); - } - - public void test_equalsLjava_lang_Object() { - // test for method java.io.FilePermission.equals() - assertTrue( - "returned false when two instance of FilePermission is equal", - readAllFiles.equals(alsoReadAllFiles)); - assertTrue( - "returned true when two instance of FilePermission is not equal", - !(readInCurrent.equals(readInFile))); - } - - public void test_impliesLjava_security_Permission() { - // Test for method boolean - // java.io.FilePermission.implies(java.security.Permission) - assertTrue("Returned true for non-subset of actions", !readAllFiles - .implies(allInCurrent)); - assertTrue("Returned true for non-subset of files", !allInCurrent - .implies(readAllFiles)); - assertTrue("Returned false for subset of actions", allInCurrent - .implies(readInCurrent)); - assertTrue("Returned false for subset of files", readAllFiles - .implies(readInCurrent)); - assertTrue("Returned false for subset of files and actions", - allInCurrent.implies(readInFile)); - assertTrue("Returned false for equal FilePermissions", readAllFiles - .implies(alsoReadAllFiles)); - - FilePermission fp3 = new FilePermission("/bob/*".replace('/', - File.separatorChar), "read,write"); - FilePermission fp4 = new FilePermission("/bob/".replace('/', - File.separatorChar), "write"); - assertTrue("returned true for same dir using * and not *", !fp3 - .implies(fp4)); - FilePermission fp5 = new FilePermission("/bob/file".replace('/', - File.separatorChar), "write"); - assertTrue("returned false for same dir using * and file", fp3 - .implies(fp5)); - - FilePermission fp6 = new FilePermission("/bob/".replace('/', - File.separatorChar), "read,write"); - FilePermission fp7 = new FilePermission("/bob/*".replace('/', - File.separatorChar), "write"); - assertTrue("returned false for same dir using not * and *", !fp6 - .implies(fp7)); - assertTrue("returned false for same subdir", fp6.implies(fp4)); - - FilePermission fp8 = new FilePermission("/".replace('/', - File.separatorChar), "read,write"); - FilePermission fp9 = new FilePermission("/".replace('/', - File.separatorChar), "write"); - assertTrue("returned false for same dir", fp8.implies(fp9)); - - FilePermission fp10 = new FilePermission("/".replace('/', - File.separatorChar), "read,write"); - FilePermission fp11 = new FilePermission("/".replace('/', - File.separatorChar), "write"); - assertTrue("returned false for same dir", fp10.implies(fp11)); - - FilePermission fp12 = new FilePermission("/*".replace('/', - File.separatorChar), "read,write"); - assertTrue("returned false for same dir using * and dir", !fp12 - .implies(fp10)); - } - - public void test_newPermissionCollection() { - // test for method java.io.FilePermission.newPermissionCollection - char s = File.separatorChar; - FilePermission perm[] = new FilePermission[4]; - perm[0] = readAllFiles; - perm[1] = allInCurrent; - perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*", - "read,write"); - perm[3] = new FilePermission(s + "tmp" + s + "test" + s - + "collection.file", "read"); - - PermissionCollection collect = perm[0].newPermissionCollection(); - for (int i = 0; i < perm.length; i++) { - collect.add(perm[i]); - } - assertTrue("returned false for subset of files", collect - .implies(new FilePermission("*", "write"))); - assertTrue("returned false for subset of name and action", collect - .implies(new FilePermission(s + "tmp", "read"))); - assertTrue("returned true for non subset of file and action", collect - .implies(readInFile)); - - FilePermission fp1 = new FilePermission("/tmp/-".replace('/', - File.separatorChar), "read"); - PermissionCollection fpc = fp1.newPermissionCollection(); - fpc.add(fp1); - fpc.add(new FilePermission("/tmp/scratch/foo/*".replace('/', - File.separatorChar), "write")); - FilePermission fp2 = new FilePermission("/tmp/scratch/foo/file" - .replace('/', File.separatorChar), "read,write"); - assertTrue("collection does not collate", fpc.implies(fp2)); - } - - public void test_hashCode() { - // test method java.io.FilePermission.hasCode() - assertTrue( - "two equal filePermission instances returned different hashCode", - readAllFiles.hashCode() == alsoReadAllFiles.hashCode()); - assertTrue( - "two filePermission instances with same permission name returned same hashCode", - readInCurrent.hashCode() != allInCurrent.hashCode()); - - } -} diff --git a/luni/src/test/java/libcore/java/net/OldNetPermissionTest.java b/luni/src/test/java/libcore/java/net/OldNetPermissionTest.java deleted file mode 100644 index 81ab2cf..0000000 --- a/luni/src/test/java/libcore/java/net/OldNetPermissionTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 libcore.java.net; - -import java.net.NetPermission; -import junit.framework.TestCase; - -public class OldNetPermissionTest extends TestCase { - - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - NetPermission n1 = new NetPermission("requestPasswordAuthentication", ""); - assertEquals("", n1.getActions()); - } -} diff --git a/luni/src/test/java/libcore/java/net/OldSocketPermissionTest.java b/luni/src/test/java/libcore/java/net/OldSocketPermissionTest.java deleted file mode 100644 index 656252e..0000000 --- a/luni/src/test/java/libcore/java/net/OldSocketPermissionTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 libcore.java.net; - -import java.net.SocketPermission; -import tests.support.Support_Configuration; - -public class OldSocketPermissionTest extends junit.framework.TestCase { - - String starName = "*." + Support_Configuration.DomainAddress; - - String wwwName = Support_Configuration.HomeAddress; - - SocketPermission star_All = new SocketPermission(starName, "listen,accept,connect"); - - SocketPermission www_All = new SocketPermission(wwwName, - "connect,listen,accept"); - - public void test_hashCode() { - SocketPermission sp1 = new SocketPermission( - Support_Configuration.InetTestIP, "resolve,connect"); - SocketPermission sp2 = new SocketPermission( - Support_Configuration.InetTestIP, "resolve,connect"); - assertTrue("Same IP address should have equal hash codes", - sp1.hashCode() == sp2.hashCode()); - - assertTrue("Different names but returned equal hash codes", - star_All.hashCode() != www_All.hashCode()); - } -} diff --git a/luni/src/test/java/libcore/java/net/OldURLClassLoaderTest.java b/luni/src/test/java/libcore/java/net/OldURLClassLoaderTest.java index aa36378..2646f98 100644 --- a/luni/src/test/java/libcore/java/net/OldURLClassLoaderTest.java +++ b/luni/src/test/java/libcore/java/net/OldURLClassLoaderTest.java @@ -150,21 +150,6 @@ public class OldURLClassLoaderTest extends junit.framework.TestCase { } } - public void test_getPermissions() throws MalformedURLException { - URL url = new URL("http://" + Support_Configuration.SpecialInetTestAddress); - Certificate[] chain = TestCertUtils.getCertChain(); - CodeSource cs = new CodeSource(url, chain); - TestURLClassLoader cl = new TestURLClassLoader(new URL[] {url}); - PermissionCollection permCol = cl.getPermissions(cs); - assertNotNull(permCol); - - URL url1 = new URL("file://foo/foo.c"); - TestURLClassLoader cl1 = new TestURLClassLoader(new URL[] {url}); - CodeSource cs1 = new CodeSource(url1, chain); - PermissionCollection permCol1 = cl1.getPermissions(cs1); - assertNotNull(permCol1); - } - public void test_definePackage() throws MalformedURLException { Manifest manifest = new Manifest(); URL[] u = new URL[0]; diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java index f2d64cd..9f414c3 100644 --- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java +++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java @@ -958,58 +958,6 @@ public class URLConnectionTest extends TestCase { } /** - * {@link java.net.URLConnection#getPermission()} - */ - public void test_getPermission() throws Exception { - java.security.Permission p = uc.getPermission(); - assertTrue("Permission of wrong type: " + p.toString(), - p instanceof java.net.SocketPermission); - assertTrue("Permission has wrong name: " + p.getName(), p.getName() - .contains("localhost:" + port)); - - URL fileUrl = new URL("file:myfile"); - Permission perm = new FilePermission("myfile", "read"); - Permission result = fileUrl.openConnection().getPermission(); - assertTrue("Wrong file: permission 1:" + perm + " , " + result, result - .equals(perm)); - - fileUrl = new URL("file:/myfile/"); - perm = new FilePermission("/myfile", "read"); - result = fileUrl.openConnection().getPermission(); - assertTrue("Wrong file: permission 2:" + perm + " , " + result, result - .equals(perm)); - - fileUrl = new URL("file:///host/volume/file"); - perm = new FilePermission("/host/volume/file", "read"); - result = fileUrl.openConnection().getPermission(); - assertTrue("Wrong file: permission 3:" + perm + " , " + result, result - .equals(perm)); - - URL httpUrl = new URL("http://home/myfile/"); - assertTrue("Wrong http: permission", httpUrl.openConnection() - .getPermission().equals( - new SocketPermission("home:80", "connect"))); - httpUrl = new URL("http://home2:8080/myfile/"); - assertTrue("Wrong http: permission", httpUrl.openConnection() - .getPermission().equals( - new SocketPermission("home2:8080", "connect"))); - URL ftpUrl = new URL("ftp://home/myfile/"); - assertTrue("Wrong ftp: permission", ftpUrl.openConnection() - .getPermission().equals( - new SocketPermission("home:21", "connect"))); - ftpUrl = new URL("ftp://home2:22/myfile/"); - assertTrue("Wrong ftp: permission", ftpUrl.openConnection() - .getPermission().equals( - new SocketPermission("home2:22", "connect"))); - - URL jarUrl = new URL("jar:file:myfile!/"); - perm = new FilePermission("myfile", "read"); - result = jarUrl.openConnection().getPermission(); - assertTrue("Wrong jar: permission:" + perm + " , " + result, result - .equals(new FilePermission("myfile", "read"))); - } - - /** * {@link java.net.URLConnection#getRequestProperties()} */ public void test_getRequestProperties() { diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlException2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlException2Test.java deleted file mode 100644 index d118d4e..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlException2Test.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.io.FilePermission; -import java.security.AccessControlException; - -public class AccessControlException2Test extends junit.framework.TestCase { - FilePermission filePermission; - - AccessControlException acException; - - AccessControlException acException1; - - /** - * java.security.AccessControlException#AccessControlException(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // Test for method - // java.security.AccessControlException(java.lang.String) - assertTrue("AccessControlException's toString() should have returned " - + "'java.security.AccessControlException: test message' but " - + "returned: " + acException.toString(), acException.toString() - .equals("java.security.AccessControlException: test message")); - } - - /** - * java.security.AccessControlException#AccessControlException(java.lang.String, - * java.security.Permission) - */ - public void test_ConstructorLjava_lang_StringLjava_security_Permission() { - // Test for method - // java.security.AccessControlException(java.lang.String, - // java.security.Permission) - assertTrue("AccessControlException's toString() should have returned " - + "'java.security.AccessControlException: test message " - + "(java.io.FilePermission /* read)' but returned: " - + acException1.toString(), acException1.toString().equals( - "java.security.AccessControlException: test message")); - } - - /** - * java.security.AccessControlException#getPermission() - */ - public void test_getPermission() { - // Test for method java.security.Permission - // java.security.AccessControlException.getPermission() - // make sure getPermission returns null when it's not set - assertNull( - "getPermission should have returned null if no permission was set", - acException.getPermission()); - assertTrue( - "getPermission should have returned the permission we assigned to it", - acException1.getPermission() == filePermission); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - filePermission = new FilePermission("/*", "read"); - acException = new AccessControlException("test message"); - acException1 = new AccessControlException("test message", - filePermission); - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java deleted file mode 100644 index 35f2b25..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexander V. Astapchuk -* @version $Revision$ -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.security.AccessControlException; -import java.security.AllPermission; -import java.security.Permission; -import java.security.UnresolvedPermission; - -import junit.framework.TestCase; - -/** - * Unit test for AccessControlException. - */ -public class AccessControlExceptionTest extends TestCase { - - /** - * Tests AccessControlException(String) - */ - public void testAccessControlExceptionString() { - new AccessControlException(null); - new AccessControlException("Failure"); - } - - /** - * Tests AccessControlException(String, Permission) - */ - public void testAccessControlExceptionStringPermission() { - Permission perm = new AllPermission(); - AccessControlException controlException = new AccessControlException("001", perm); - assertEquals("exception message", "001", controlException.getMessage()); - assertEquals("permission", perm, controlException.getPermission()); - } - - /** - * - * Tests AccessControlException.getPermission() - */ - public void testGetPermission() { - Permission perm = new UnresolvedPermission("unresolvedType", - "unresolvedName", "unresolvedActions", null); - AccessControlException ex = new AccessControlException("001", perm); - assertSame(ex.getPermission(), perm); - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java deleted file mode 100644 index be2903b..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.security.AccessControlContext; -import java.security.AccessControlException; -import java.security.AccessController; -import java.security.AllPermission; -import java.security.Permission; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -import dalvik.annotation.KnownFailure; - -public class AccessController2Test extends junit.framework.TestCase { - - PrivilegedAction<Boolean> privAction = new PrivilegedAction<Boolean>() { - public Boolean run() { - try { - AccessController.checkPermission(new AllPermission()); - return new Boolean(false); - } catch (SecurityException ex) { - return new Boolean(true); - } - } - }; - - PrivilegedExceptionAction<Boolean> privExceptAction = - new PrivilegedExceptionAction<Boolean>() { - public Boolean run() { - try { - AccessController.checkPermission(new AllPermission()); - return new Boolean(false); - } catch (SecurityException ex) { - return new Boolean(true); - } - } - }; - - /** - * java.security.AccessController#doPrivileged(java.security.PrivilegedAction, - * java.security.AccessControlContext)) - */ - @KnownFailure("Fails (probably) because no protection domain is set.") - public void test_doPrivilegedLjava_security_PrivilegedActionLjava_security_AccessControlContext() { - Boolean pass; - - try { - AccessController.doPrivileged((PrivilegedAction<?>) null, null); - fail("Test 1: NullPointerException expected."); - } catch (NullPointerException e) { - // Expected. - } - - pass = AccessController.doPrivileged(privAction, null); - assertTrue("Test 2: Got AllPermission when providing a null " + - "AccessControlContext.", pass.booleanValue()); - - AccessControlContext acc = AccessController.getContext(); - assertNotNull("Test 3: AccessControlContext must not be null", acc); - - pass = AccessController.doPrivileged(privAction, acc); - assertTrue("Test 4: Got AllPermission when providing a non-null " + - "AccessControlContext.", pass.booleanValue()); - } - - /** - * java.security.AccessController#doPrivileged(java.security.PrivilegedAction)) - */ - @KnownFailure("Fails (probably) because no protection domain is set.") - public void test_doPrivilegedLjava_security_PrivilegedAction() { - Boolean pass; - - try { - AccessController.doPrivileged((PrivilegedAction<?>) null); - fail("Test 1: NullPointerException expected."); - } catch (NullPointerException e) { - // Expected. - } - - pass = AccessController.doPrivileged(privAction); - assertTrue("Test 2: Got AllPermission when providing no " + - "AccessControlContext.", pass.booleanValue()); - } - - /** - * java.security.AccessController#doPrivileged(java.security.PrivilegedExceptionAction, - * java.security.AccessControlContext)) - */ - @KnownFailure("Fails (probably) because no protection domain is set.") - public void test_doPrivilegedLjava_security_PrivilegedExceptionActionLjava_security_AccessControlContext() { - Boolean pass; - - try { - AccessController.doPrivileged((PrivilegedExceptionAction<?>) null); - fail("Test 1: NullPointerException expected."); - } catch (NullPointerException e) { - // Expected. - } catch (PrivilegedActionException e) { - fail("Test 2: Unexpected PrivilegedActionException " + - e.getMessage()); - } - - try { - pass = AccessController.doPrivileged(privExceptAction, null); - assertTrue("Test 3: Got AllPermission when providing a null " + - "AccessControlContext.", pass.booleanValue()); - } catch (PrivilegedActionException e) { - fail("Test 4: Unexpected PrivilegedActionException " + - e.getMessage()); - } - - AccessControlContext acc = AccessController.getContext(); - assertNotNull("Test 5: AccessControlContext must not be null", acc); - - try { - pass = AccessController.doPrivileged(privExceptAction, acc); - assertTrue("Test 6: Got AllPermission when providing non-null " + - "AccessControlContext.", pass.booleanValue()); - } catch (PrivilegedActionException e) { - fail("Test 7: Unexpected PrivilegedActionException " + - e.getMessage()); - } - } - - /** - * java.security.AccessController#doPrivileged(java.security.PrivilegedExceptionAction)) - */ - @KnownFailure("Fails (probably) because no protection domain is set.") - public void test_doPrivilegedLjava_security_PrivilegedExceptionAction() { - Boolean pass; - - try { - AccessController.doPrivileged((PrivilegedExceptionAction<?>) null); - fail("Test 1: NullPointerException expected."); - } catch (NullPointerException e) { - // Expected. - } catch (PrivilegedActionException e) { - fail("Test 2: Unexpected PrivilegedActionException " + - e.getMessage()); - } - - try { - pass = AccessController.doPrivileged(privExceptAction); - assertTrue("Test 3: Got AllPermission when providing no " + - "AccessControlContext.", pass.booleanValue()); - } catch (PrivilegedActionException e) { - fail("Test 4: Unexpected exception " + e.getMessage()); - } - } - - /** - * java.security.AccessController#checkPermission(Permission perm) - */ - public void test_checkPermission_NullParameter() { - //Null parameter - try { - AccessController.checkPermission(null); - fail("Test 1: NullPointerException expected."); - } catch (NullPointerException npe) { - //expected - } - } - - /** - * java.security.AccessController#checkPermission(Permission perm) - */ - @KnownFailure("Fails (probably) because no protection domain is set.") - public void test_checkPermission_InvalidPermission() { - String[] perm_invalid = {null, "1", "", "invalid", "bla-bla", "testCtor123^%$#&^ &^$"}; - Permission perm; - - //Null parameter - try { - AccessController.checkPermission(null); - fail("NullPointerException should be thrown for NULL parameter"); - } catch (NullPointerException npe) { - //expected - } - - //Invalid parameter - for (int i = 0; i < perm_invalid.length; i++) { - try { - perm = new RealPermission(perm_invalid[i]); - AccessController.checkPermission(perm); - fail("AccessControlException should be thrown for INVALID parameter " + perm_invalid[i]); - } catch (AccessControlException ace) { - //expected - } catch (Exception e) { - fail("Unexpected exception caught: " + e.toString()); - } - - } - } - - /** - * java.security.AccessController#getContext() - */ - public void test_getContext() { - try { - AccessControlContext acc = AccessController.getContext(); - assertNotNull(acc); - assertTrue(acc instanceof AccessControlContext); - } catch (Exception e) { - fail("Unexpected exception"); - } - } - - // Bare extension to instantiate abstract Permission class - static final class RealPermission extends Permission { - - private static final long serialVersionUID = 1L; - - public RealPermission(String name) { - super(name); - } - - public boolean equals(Object obj) { - return false; - } - - public String getActions() { - return null; - } - - public int hashCode() { - return 0; - } - - public boolean implies(Permission permission) { - return false; - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java deleted file mode 100644 index b52a81b..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.security.AllPermission; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.SecurityPermission; -import java.util.Enumeration; - -public class AllPermission2Test extends junit.framework.TestCase { - - /** - * java.security.AllPermission#AllPermission() - */ - public void test_Constructor() { - // Test for method java.security.AllPermission() - AllPermission ap = new AllPermission(); - assertEquals("Bogus name for AllPermission \"" + ap.getName() + "\".", - "<all permissions>", ap.getName()); - } - - /** - * java.security.AllPermission#AllPermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.security.AllPermission(java.lang.String, - // java.lang.String) - AllPermission ap = new AllPermission("Don't remember this stupid name", - "or this action"); - assertEquals("Bogus name for AllPermission \"" + ap.getName() + "\".", - "<all permissions>", ap.getName()); - assertEquals( - "AllPermission constructed with actions didn't ignore them.", - "<all actions>", ap.getActions()); - } - - /** - * java.security.AllPermission#equals(java.lang.Object) - */ - public void test_equalsLjava_lang_Object() { - // Test for method boolean - // java.security.AllPermission.equals(java.lang.Object) - assertTrue("Two AllPermissions not equal to each other.", - new AllPermission().equals(new AllPermission())); - assertTrue("AllPermission equals a SecurityPermission.", - !(new AllPermission().equals(new SecurityPermission("ugh!")))); - } - - /** - * java.security.AllPermission#getActions() - */ - public void test_getActions() { - AllPermission ap = new AllPermission(); - // Test for method java.lang.String - // java.security.AllPermission.getActions() - assertTrue("AllPermission has non-empty actions. (" + ap.getActions() - + ")", ap.getActions().equals("<all actions>")); - } - - /** - * java.security.AllPermission#hashCode() - */ - public void test_hashCode() { - final int ALLPERMISSION_HASH = 1; - // Test for method int java.security.AllPermission.hashCode() - AllPermission TestAllPermission = new AllPermission(); - assertTrue("AllPermission hashCode is wrong. Should have been " - + ALLPERMISSION_HASH + " but was " - + TestAllPermission.hashCode(), - TestAllPermission.hashCode() == ALLPERMISSION_HASH); - } - - /** - * java.security.AllPermission#implies(java.security.Permission) - */ - public void test_impliesLjava_security_Permission() { - // Test for method boolean - // java.security.AllPermission.implies(java.security.Permission) - assertTrue("AllPermission does not imply a AllPermission.", - new AllPermission().implies(new AllPermission())); - assertTrue("AllPermission does not imply a SecurityPermission.", - new AllPermission().implies(new SecurityPermission("ugh!"))); - assertTrue("SecurityPermission implies AllPermission.", - !(new SecurityPermission("ugh!").implies(new AllPermission()))); - assertTrue("AllPermission does not imply when parametr NULL", new AllPermission().implies(null)); - } - - /** - * java.security.AllPermission#newPermissionCollection() - */ - public void test_newPermissionCollection() { - AllPermission ap1 = new AllPermission(); - AllPermission ap2 = new AllPermission("Don't remember this stupid name", - "or this action"); - AllPermission ap3 = new AllPermission("Remember this cool name", - "and this action"); - - PermissionCollection pc1 = ap1.newPermissionCollection(); - assertFalse(pc1.isReadOnly()); - - Enumeration<Permission> perm1 = pc1.elements(); - assertFalse(perm1.hasMoreElements()); - assertNotNull(perm1); - - pc1.add(ap1); - pc1.add(ap2); - assertTrue("Should imply", pc1.implies(ap1)); - assertTrue("Should imply", pc1.implies(ap2)); - assertTrue("Should imply", pc1.implies(ap3)); - perm1 = pc1.elements(); - assertTrue(perm1.hasMoreElements()); - - PermissionCollection pc2 = ap2.newPermissionCollection(); - assertFalse(pc2.isReadOnly()); - - Enumeration<Permission> perm2 = pc2.elements(); - assertFalse(perm2.hasMoreElements()); - assertNotNull(perm2); - - pc2.add(ap1); - pc2.add(ap2); - assertTrue("Should imply", pc2.implies(ap1)); - assertTrue("Should imply", pc2.implies(ap2)); - assertTrue("Should imply", pc2.implies(ap3)); - perm2 = pc2.elements(); - assertTrue(perm2.hasMoreElements()); - } - -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java deleted file mode 100644 index e398bc4..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.security.BasicPermission; -import java.security.PermissionCollection; - -public class BasicPermission2Test extends junit.framework.TestCase { - - public static class BasicPermissionSubclass extends BasicPermission { - public BasicPermissionSubclass(String name) { - super(name); - } - - public BasicPermissionSubclass(String name, String actions) { - super(name, actions); - } - } - - BasicPermission bp = new BasicPermissionSubclass("aName"); - - BasicPermission bp2 = new BasicPermissionSubclass("aName", "anAction"); - - BasicPermission bp3 = new BasicPermissionSubclass("*"); - - BasicPermission bp4 = new BasicPermissionSubclass("this.that"); - - BasicPermission bp5 = new BasicPermissionSubclass("this.*"); - - /** - * java.security.BasicPermission#BasicPermission(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // Test for method java.security.BasicPermission(java.lang.String) - assertEquals("Incorrect name returned", "aName", bp.getName()); - } - - /** - * java.security.BasicPermission#BasicPermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.security.BasicPermission(java.lang.String, - // java.lang.String) - assertEquals("Incorrect name returned", "aName", bp2.getName()); - } - - /** - * java.security.BasicPermission#equals(java.lang.Object) - */ - public void test_equalsLjava_lang_Object() { - // Test for method boolean - // java.security.BasicPermission.equals(java.lang.Object) - assertTrue("a) Equal objects returned non-equal", bp.equals(bp2)); - assertTrue("b) Equal objects returned non-equal", bp2.equals(bp)); - assertTrue("a) Unequal objects returned equal", !bp.equals(bp3)); - assertTrue("b) Unequal objects returned equal", !bp4.equals(bp5)); - } - - /** - * java.security.BasicPermission#getActions() - */ - public void test_getActions() { - // Test for method java.lang.String - // java.security.BasicPermission.getActions() - assertTrue("a) Incorrect actions returned, wanted the empty String", bp - .getActions().equals("")); - assertTrue("b) Incorrect actions returned, wanted the empty String", - bp2.getActions().equals("")); - } - - /** - * java.security.BasicPermission#hashCode() - */ - public void test_hashCode() { - // Test for method int java.security.BasicPermission.hashCode() - assertTrue("Equal objects should return same hash", - bp.hashCode() == bp2.hashCode()); - } - - /** - * java.security.BasicPermission#implies(java.security.Permission) - */ - public void test_impliesLjava_security_Permission() { - // Test for method boolean - // java.security.BasicPermission.implies(java.security.Permission) - assertTrue("Equal objects should imply each other", bp.implies(bp2)); - assertTrue("a) should not imply", !bp.implies(bp3)); - assertTrue("b) should not imply", !bp4.implies(bp5)); - assertTrue("a) should imply", bp3.implies(bp5)); - assertTrue("b) should imply", bp5.implies(bp4)); - - } - - /** - * java.security.BasicPermission#newPermissionCollection() - */ - public void test_newPermissionCollection() { - // Test for method java.security.PermissionCollection - // java.security.BasicPermission.newPermissionCollection() - PermissionCollection bpc = bp.newPermissionCollection(); - bpc.add(bp5); - bpc.add(bp); - assertTrue("Should imply", bpc.implies(bp4)); - assertTrue("Should not imply", !bpc.implies(bp3)); - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java deleted file mode 100644 index 34549df..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.net.URL; -import java.security.CodeSigner; -import java.security.CodeSource; -import java.security.Timestamp; -import java.security.cert.CertPath; -import java.security.cert.Certificate; -import java.util.Arrays; -import java.util.Date; - -import org.apache.harmony.security.tests.support.TestCertUtils; - - -public class CodeSource2Test extends junit.framework.TestCase { - - /** - * @throws Exception - * java.security.CodeSource#CodeSource(java.net.URL, - * java.security.cert.Certificate[]) - */ - public void test_ConstructorLjava_net_URL$Ljava_security_cert_Certificate() - throws Exception { - // Test for method java.security.CodeSource(java.net.URL, - // java.security.cert.Certificate []) - new CodeSource(new java.net.URL("file:///test"), (Certificate[]) null); - } - - /** - * @throws Exception - * java.security.CodeSource#CodeSource(java.net.URL, - * java.security.CodeSigner[]) - */ - public void test_ConstructorLjava_net_URL$Ljava_security_CodeSigner() { - // Test for method java.security.CodeSource(java.net.URL, - // java.security.cert.CodeSigner []) - try { - new CodeSource(new URL("file:///test"), (CodeSigner[]) null); - } catch (Exception e) { - fail("Unexpected Exception"); - } - - try { - new CodeSource(null, (CodeSigner[]) null); - } catch (Exception e) { - fail("Unexpected Exception"); - } - - CertPath cpath = TestCertUtils.genCertPath(3, 0); - Date now = new Date(); - - Timestamp ts = new Timestamp(now, cpath); - CodeSigner cs = new CodeSigner(cpath, ts); - try { - CodeSource codeSource = new CodeSource(new URL("file:///test"), new CodeSigner[] { cs }); - assertNotNull(codeSource.getCertificates()); - assertNotNull(codeSource.getCodeSigners()); - assertTrue(Arrays.equals(new CodeSigner[] { cs }, codeSource.getCodeSigners())); - assertEquals(new URL("file:///test"), codeSource.getLocation()); - } catch (Exception e) { - fail("Unexpected Exception"); - } - } - - /** - * java.security.CodeSource#equals(java.lang.Object) - */ - public void test_equalsLjava_lang_Object() throws Exception { - // Test for method boolean - // java.security.CodeSource.equals(java.lang.Object) - CodeSource cs1 = new CodeSource(new java.net.URL("file:///test"), - (Certificate[]) null); - CodeSource cs2 = new CodeSource(new java.net.URL("file:///test"), - (Certificate[]) null); - assertTrue("Identical objects were not equal()!", cs1.equals(cs2)); - } - - /** - * java.security.CodeSource#hashCode() - */ - public void test_hashCode() throws Exception { - URL url = new java.net.URL("file:///test"); - CodeSource cs = new CodeSource(url, (Certificate[]) null); - assertEquals("Did not get expected hashCode!", cs.hashCode(), url - .hashCode()); - } - - /** - * java.security.CodeSource#getCertificates() - */ - public void test_getCertificates() throws Exception { - CodeSource cs = new CodeSource(new java.net.URL("file:///test"), - (Certificate[]) null); - assertNull("Should have gotten null certificate list.", cs - .getCertificates()); - } - - /** - * java.security.CodeSource#getLocation() - */ - public void test_getLocation() throws Exception { - // Test for method java.net.URL java.security.CodeSource.getLocation() - CodeSource cs = new CodeSource(new java.net.URL("file:///test"), - (Certificate[]) null); - assertEquals("Did not get expected location!", "file:/test", cs - .getLocation().toString()); - assertNotNull("Host should not be null", cs.getLocation().getHost()); - } - - /** - * java.security.CodeSource#implies(java.security.CodeSource) - */ - public void test_impliesLjava_security_CodeSource() throws Exception { - // Test for method boolean - // java.security.CodeSource.implies(java.security.CodeSource) - CodeSource cs1 = new CodeSource(new URL("file:/d:/somedir"), - (Certificate[]) null); - CodeSource cs2 = new CodeSource(new URL("file:/d:/somedir/"), - (Certificate[]) null); - assertTrue("Does not add /", cs1.implies(cs2)); - - cs1 = new CodeSource(new URL("file", null, -1, "/d:/somedir/"), - (Certificate[]) null); - cs2 = new CodeSource(new URL("file:/d:/somedir/"), (Certificate[]) null); - assertTrue("null host should imply host", cs1.implies(cs2)); - assertFalse("host should not imply null host", cs2.implies(cs1)); - } - -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java deleted file mode 100644 index 3b41943..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java +++ /dev/null @@ -1,590 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexander V. Astapchuk -* @version $Revision$ -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.io.File; -import java.net.URL; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.UnknownHostException; -import java.security.CodeSigner; -import java.security.CodeSource; -import java.security.cert.CertPath; -import java.security.cert.Certificate; - -import org.apache.harmony.security.tests.support.TestCertUtils; - -import junit.framework.TestCase; - -/** - * Unit test for CodeSource. - * - */ -public class CodeSourceTest extends TestCase { - private java.security.cert.Certificate[] chain = null; - - /* Below are various URLs used during the testing */ - private static URL urlSite; - - private static URL urlDir; // must NOT end with '/' - - private static URL urlDirOtherSite; // same as urlDir, but another site - - private static URL urlDir_port80, urlDir_port81; - - /* must be exactly the same as urlDir, but with slash added */ - private static URL urlDirWithSlash; - - //private static URL urlDirFtp; - private static URL urlDir_FileProtocol; - - private static URL urlDirIP; - - private static URL urlFile, urlFileWithAdditionalDirs, urlFileDirOtherDir; - - private static URL urlFileDirMinus; - - private static URL urlFileDirStar; - - private static URL urlRef1, urlRef2; - - private boolean init = false; - - private void init() { - if (!init) { - try { - String siteName = "www.intel.com"; - InetAddress addr = InetAddress.getByName(siteName); - String siteIP = addr.getHostAddress(); - - urlSite = new URL("http://"+siteName+""); - urlDir = new URL("http://"+siteName+"/drl_test"); - urlDirOtherSite = new URL("http://www.any-other-site-which-is-not-siteName.com/drl_test"); - - urlDir_port80 = new URL("http://"+siteName+":80/drl_test"); - urlDir_port81 = new URL("http://"+siteName+":81/drl_test"); - urlDirWithSlash = new URL(urlDir + "/"); - - //urlDirFtp = new URL("ftp://www.intel.com/drl_test"); - urlDir_FileProtocol = new URL("file://"+siteName+"/drl_test"); - - urlDirIP = new URL("http://"+siteIP+"/drl_test"); - - urlFile = new URL("http://"+siteName+"/drl_test/empty.jar"); - urlFileWithAdditionalDirs = new URL( - "http://"+siteName+"/drl_test/what/ever/here/empty.jar"); - - urlFileDirMinus = new URL("http://"+siteName+"/drl_test/-"); - urlFileDirStar = new URL("http://"+siteName+"/drl_test/*"); - urlFileDirOtherDir = new URL("http://"+siteName+"/_test_drl_/*"); - - urlRef1 = new URL("http://"+siteName+"/drl_test/index.html#ref1"); - urlRef2 = new URL("http://"+siteName+"/drl_test/index.html#ref2"); - } catch (MalformedURLException ex) { - throw new Error(ex); - } catch (UnknownHostException ex) { - throw new Error(ex); - } finally { - init = true; - } - } - } - - protected void setUp() throws Exception { - super.setUp(); - init(); - chain = TestCertUtils.getCertChain(); - } - - /** - * Tests hashCode().<br> - * javadoc says nothing, so test DRL-specific implementation. - */ - public void testHashCode() { - // when nothing is specified, then hashCode obviously must be 0. - assertTrue(new CodeSource(null, (Certificate[]) null).hashCode() == 0); - // only URL.hashCode is taken into account... - assertTrue(new CodeSource(urlSite, (Certificate[]) null).hashCode() == urlSite - .hashCode()); - // ... and certs[] does not affect it - assertTrue(new CodeSource(urlSite, chain).hashCode() == urlSite - .hashCode()); - } - - /** - * Tests CodeSource(URL, Certificate[]). - */ - public void testCodeSourceURLCertificateArray() { - new CodeSource(null, (Certificate[]) null); - new CodeSource(urlSite, (Certificate[]) null); - new CodeSource(null, chain); - new CodeSource(urlSite, chain); - } - - /** - * Tests CodeSource(URL, CodeSigner[]). - */ - public void testCodeSourceURLCodeSignerArray() { - if (!has_15_features()) { - return; - } - new CodeSource(null, (CodeSigner[]) null); - - } - - /** - * equals(Object) must return <code>false</code> for null - */ - public void testEqualsObject_00() { - CodeSource thiz = new CodeSource(urlSite, (Certificate[]) null); - assertFalse(thiz.equals(null)); - - } - - /** - * equals(Object) must return <code>true</code> for the same object - */ - public void testEqualsObject_01() { - CodeSource thiz = new CodeSource(urlSite, (Certificate[]) null); - assertTrue(thiz.equals(thiz)); - } - - /** - * Test for equals(Object)<br> - * The signer certificate chain must contain the same set of certificates, but - * the order of the certificates is not taken into account. - */ - public void testEqualsObject_02() { - Certificate cert0 = new TestCertUtils.TestCertificate(); - Certificate cert1 = new TestCertUtils.TestCertificate(); - Certificate[] certs0 = new Certificate[] { cert0, cert1 }; - Certificate[] certs1 = new Certificate[] { cert1, cert0 }; - CodeSource thiz = new CodeSource(urlSite, certs0); - CodeSource that = new CodeSource(urlSite, certs1); - assertTrue(thiz.equals(that)); - } - - /** - * Test for equals(Object)<br> - * Checks that both 'null' and not-null URLs are taken into account - properly. - */ - public void testEqualsObject_04() { - CodeSource thiz = new CodeSource(urlSite, (Certificate[]) null); - CodeSource that = new CodeSource(null, (Certificate[]) null); - assertFalse(thiz.equals(that)); - assertFalse(that.equals(thiz)); - - that = new CodeSource(urlFile, (Certificate[]) null); - assertFalse(thiz.equals(that)); - assertFalse(that.equals(thiz)); - } - - /** - * Tests CodeSource.getCertificates(). - */ - public void testGetCertificates_00() { - assertNull(new CodeSource(null, (Certificate[]) null).getCertificates()); - java.security.cert.Certificate[] got = new CodeSource(null, chain) - .getCertificates(); - // The returned array must be clone()-d ... - assertNotSame(got, chain); - // ... but must represent the same set of certificates - assertTrue(checkEqual(got, chain)); - } - - /** - * Tests whether the getCertificates() returns certificates obtained from - * the signers. - */ - public void testGetCertificates_01() { - if (!has_15_features()) { - return; - } - CertPath cpath = TestCertUtils.getCertPath(); - Certificate[] certs = (Certificate[]) cpath.getCertificates().toArray(); - CodeSigner[] signers = { new CodeSigner(cpath, null) }; - CodeSource cs = new CodeSource(null, signers); - Certificate[] got = cs.getCertificates(); - // The set of certificates must be exactly the same, - // but the order is not specified - assertTrue(presented(certs, got)); - assertTrue(presented(got, certs)); - } - - /** - * Checks whether two arrays of certificates represent the same same set of - * certificates - in the same order. - * @param one first array - * @param two second array - * @return <code>true</code> if both arrays represent the same set of - * certificates, - * <code>false</code> otherwise. - */ - private static boolean checkEqual(java.security.cert.Certificate[] one, - java.security.cert.Certificate[] two) { - - if (one == null) { - return two == null; - } - - if (two == null) { - return false; - } - - if (one.length != two.length) { - return false; - } - - for (int i = 0; i < one.length; i++) { - if (one[i] == null) { - if (two[i] != null) { - return false; - } - } else { - if (!one[i].equals(two[i])) { - return false; - } - } - } - return true; - } - - /** - * Performs a test whether the <code>what</code> certificates are all - * presented in <code>where</code> certificates. - * - * @param what - first array of Certificates - * @param where - second array of Certificates - * @return <code>true</code> if each and every certificate from 'what' - * (including null) is presented in 'where' <code>false</code> otherwise - */ - private static boolean presented(Certificate[] what, Certificate[] where) { - boolean whereHasNull = false; - for (int i = 0; i < what.length; i++) { - if (what[i] == null) { - if (whereHasNull) { - continue; - } - for (int j = 0; j < where.length; j++) { - if (where[j] == null) { - whereHasNull = true; - break; - } - } - if (!whereHasNull) { - return false; - } - } else { - boolean found = false; - for (int j = 0; j < where.length; j++) { - if (what[i].equals(where[j])) { - found = true; - break; - } - } - if (!found) { - return false; - } - } - - } - return true; - } - - /** - * Tests CodeSource.getCodeSigners(). - */ - public void testGetCodeSigners_00() { - if (!has_15_features()) { - return; - } - CodeSigner[] signers = { new CodeSigner(TestCertUtils.getCertPath(), - null) }; - CodeSource cs = new CodeSource(null, signers); - CodeSigner[] got = cs.getCodeSigners(); - assertNotNull(got); - assertTrue(signers.length == got.length); - // not sure whether they must be in the same order - for (int i = 0; i < signers.length; i++) { - CodeSigner s = signers[i]; - boolean found = false; - for (int j = 0; j < got.length; j++) { - if (got[j] == s) { - found = true; - break; - } - } - assertTrue(found); - } - } - - /** - * Tests CodeSource.getCodeSigners() for null. - */ - public void testGetCoderSignersNull() throws Exception{ - assertNull(new CodeSource(new URL("http://url"), (Certificate[])null).getCodeSigners()); - } - - /** - * Tests CodeSource.getLocation() - */ - public void testGetLocation() { - assertTrue(new CodeSource(urlSite, (Certificate[]) null).getLocation() == urlSite); - assertTrue(new CodeSource(urlSite, chain).getLocation() == urlSite); - assertNull(new CodeSource(null, (Certificate[]) null).getLocation()); - assertNull(new CodeSource(null, chain).getLocation()); - } - - /** - * Tests CodeSource.toString() - */ - public void testToString() { - // Javadoc keeps silence about String's format, - // just make sure it can be invoked. - new CodeSource(urlSite, chain).toString(); - new CodeSource(null, chain).toString(); - new CodeSource(null, (Certificate[]) null).toString(); - } - - /** - * Tests whether we are running with the 1.5 features.<br> - * The test is preformed by looking for (via reflection) the CodeSource's - * constructor {@link CodeSource#CodeSource(URL, CodeSigner[])}. - * @return <code>true</code> if 1.5 feature is presented, <code>false</code> - * otherwise. - */ - private static boolean has_15_features() { - Class klass = CodeSource.class; - Class[] ctorArgs = { URL.class, new CodeSigner[] {}.getClass() }; - try { - klass.getConstructor(ctorArgs); - } catch (NoSuchMethodException ex) { - // NoSuchMethod == Not RI.v1.5 and not DRL - return false; - } - return true; - } - - /** - * must not imply null CodeSource - */ - public void testImplies_00() { - CodeSource cs0 = new CodeSource(null, (Certificate[]) null); - assertFalse(cs0.implies(null)); - } - - /** - * CodeSource with location=null && Certificate[] == null implies any other - * CodeSource - */ - public void testImplies_01() throws Exception { - CodeSource thizCS = new CodeSource(urlSite, (Certificate[]) null); - CodeSource thatCS = new CodeSource(null, (Certificate[]) null); - assertTrue(thatCS.implies(thizCS)); - assertTrue(thatCS.implies(thatCS)); - - assertFalse(thizCS.implies(thatCS)); - } - - public void testImplies_02() throws Exception { - CodeSource thizCS = new CodeSource(urlSite, (Certificate[]) null); - CodeSource thatCS = new CodeSource(thizCS.getLocation(), - (Certificate[]) null); - assertTrue(thizCS.implies(thatCS)); - assertTrue(thatCS.implies(thizCS)); - - } - - /* - * FIXME - * commented out for temporary, as there is no FTP:// protocol supported yet. - * to be uncommented back. - public void testImplies_03() throws Exception { - CodeSource thizCS = new CodeSource(urlDir, (Certificate[]) null); - CodeSource thatCS = new CodeSource(urlDirFtp, (Certificate[]) null); - assertFalse(thizCS.implies(thatCS)); - assertFalse(thatCS.implies(thizCS)); - } - */ - public void testImplies_03_tmp() throws Exception { - CodeSource thizCS = new CodeSource(urlDir, (Certificate[]) null); - CodeSource thatCS = new CodeSource(urlDir_FileProtocol, - (Certificate[]) null); - assertFalse(thizCS.implies(thatCS)); - assertFalse(thatCS.implies(thizCS)); - } - - public void testImplies_04() throws Exception { - CodeSource thizCS = new CodeSource(urlDir, (Certificate[]) null); - CodeSource thatCS = new CodeSource(urlDirIP, (Certificate[]) null); - - assertTrue(thizCS.implies(thatCS)); - assertTrue(thatCS.implies(thizCS)); - - // - // Check for another site - force to create SocketPermission - // - thatCS = new CodeSource(urlDirOtherSite, (Certificate[]) null); - assertFalse(thizCS.implies(thatCS)); - - // - // also check for getHost() == null - // - thizCS = new CodeSource(new URL("http", null, "file1"), - (Certificate[]) null); - thatCS = new CodeSource(new URL("http", "another.host.com", "file1"), - (Certificate[]) null); - // well, yes, this is accordint to the spec... - assertTrue(thizCS.implies(thatCS)); - assertFalse(thatCS.implies(thizCS)); - } - - public void testImplies_05() throws Exception { - CodeSource thizCS = new CodeSource(urlDir_port80, (Certificate[]) null); - CodeSource thatCS = new CodeSource(urlDir, (Certificate[]) null); - - assertTrue(thizCS.implies(thatCS)); - assertTrue(thatCS.implies(thizCS)); - - thizCS = new CodeSource(urlDir, (Certificate[]) null); - thatCS = new CodeSource(urlDir_port81, (Certificate[]) null); - //assert*True* because thizCS has 'port=-1' - assertTrue(thizCS.implies(thatCS)); - - thizCS = new CodeSource(urlDir_port81, (Certificate[]) null); - thatCS = new CodeSource(urlDir, (Certificate[]) null); - assertFalse(thizCS.implies(thatCS)); - // - thizCS = new CodeSource(urlDir_port80, (Certificate[]) null); - thatCS = new CodeSource(urlDir_port81, (Certificate[]) null); - assertFalse(thizCS.implies(thatCS)); - } - - public void testImplies_06() throws Exception { - CodeSource thizCS = new CodeSource(urlFile, (Certificate[]) null); - CodeSource thatCS = new CodeSource(urlFile, (Certificate[]) null); - assertTrue(thizCS.implies(thatCS)); - } - - public void testImplies_07() throws Exception { - CodeSource thiz = new CodeSource(urlFileDirMinus, (Certificate[]) null); - CodeSource that = new CodeSource(urlFile, (Certificate[]) null); - assertTrue(thiz.implies(that)); - - that = new CodeSource(urlFileWithAdditionalDirs, (Certificate[]) null); - assertTrue(thiz.implies(that)); - - that = new CodeSource(urlFileDirOtherDir, (Certificate[]) null); - assertFalse(thiz.implies(that)); - } - - public void testImplies_08() throws Exception { - CodeSource thiz = new CodeSource(urlFileDirStar, (Certificate[]) null); - CodeSource that = new CodeSource(urlFile, (Certificate[]) null); - assertTrue(thiz.implies(that)); - that = new CodeSource(urlFileWithAdditionalDirs, (Certificate[]) null); - assertFalse(thiz.implies(that)); - // - that = new CodeSource(urlFileDirOtherDir, (Certificate[]) null); - assertFalse(thiz.implies(that)); - // must not have any further '/' - that = new CodeSource(new URL(urlFile.toString() + "/"), - (Certificate[]) null); - assertFalse(thiz.implies(that)); - } - - public void testImplies_09() throws Exception { - CodeSource thizCS = new CodeSource(urlDir, (Certificate[]) null); - CodeSource thatCS = new CodeSource(urlDirWithSlash, - (Certificate[]) null); - assertTrue(thizCS.implies(thatCS)); - assertFalse(thatCS.implies(thizCS)); - } - - public void testImplies_0A() throws Exception { - CodeSource thizCS = new CodeSource(urlRef1, (Certificate[]) null); - CodeSource thatCS = new CodeSource(urlRef1, (Certificate[]) null); - assertTrue(thizCS.implies(thatCS)); - - thizCS = new CodeSource(urlRef1, (Certificate[]) null); - thatCS = new CodeSource(urlRef2, (Certificate[]) null); - assertFalse(thizCS.implies(thatCS)); - - } - - /** - * If this certificates are not null, then all of this certificates should - * be presented in certificates of that codesource. - */ - public void testImplies_0B() { - - Certificate c0 = new TestCertUtils.TestCertificate("00"); - Certificate c1 = new TestCertUtils.TestCertificate("01"); - Certificate c2 = new TestCertUtils.TestCertificate("02"); - Certificate[] thizCerts = { c0, c1 }; - Certificate[] thatCerts = { c1, c0, c2 }; - - CodeSource thiz = new CodeSource(urlSite, thizCerts); - CodeSource that = new CodeSource(urlSite, thatCerts); - // two CodeSource-s with different set of certificates - assertTrue(thiz.implies(that)); - - // - that = new CodeSource(urlSite, (Certificate[]) null); - // 'thiz' has set of certs, while 'that' has no certs. URL-s are the - // same. - assertFalse(thiz.implies(that)); - assertTrue(that.implies(thiz)); - } - - /** - * Testing with special URLs like 'localhost', 'file://' scheme ... - * These special URLs have a special processing in implies(), - * so they need to be covered and performance need to be checked - */ - public void testImplies_0C() throws Exception { - URL url0 = new URL("http://localhost/someDir"); - URL url1 = new URL("http://localhost/someOtherDir"); - - CodeSource thizCS = new CodeSource(url0, (Certificate[]) null); - CodeSource thatCS = new CodeSource(url1, (Certificate[]) null); - assertFalse(thizCS.implies(thatCS)); - assertFalse(thatCS.implies(thizCS)); - } - - /** - * Testing with special URLs like 'localhost', 'file://' scheme ... - * These special URLs have a special processing in implies(), - * so they need to be covered and performance need to be checked - */ - public void testImplies_0D() throws Exception { - URL url0 = new URL("file:///" + System.getProperty("java.io.tmpdir") - + File.separator + "someDir"); - URL url1 = new URL("file:///" + System.getProperty("java.io.tmpdir") - + File.separator + "someOtherDir"); - CodeSource thizCS = new CodeSource(url0, (Certificate[]) null); - CodeSource thatCS = new CodeSource(url1, (Certificate[]) null); - assertFalse(thizCS.implies(thatCS)); - assertFalse(thatCS.implies(thizCS)); - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/Permission2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/Permission2Test.java deleted file mode 100644 index 12952e5..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/Permission2Test.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.SecurityPermission; - -public class Permission2Test extends junit.framework.TestCase { - static class ConcretePermission extends Permission { - public ConcretePermission() { - super("noname"); - } - - public boolean equals(Object obj) { - return true; - } - - public String getActions() { - return "none"; - } - - public int hashCode() { - return 1; - } - - public boolean implies(Permission p) { - return true; - } - } - - /** - * java.security.Permission#Permission(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // test method java.security.permission.Permission(string) - try { - SecurityPermission permi = new SecurityPermission( - "Testing the permission abstract class"); - String name = permi.getName(); - assertEquals("Permission Constructor failed", - "Testing the permission abstract class", name); - } catch (Exception e) { - fail("Unexpected excpetion"); - } - - try { - SecurityPermission permi = new SecurityPermission(null); - fail("NullPointerException was not thrown for NULL parameter"); - } catch (NullPointerException e) { - //expected - } - - try { - SecurityPermission permi = new SecurityPermission(""); - fail("IllegalArgumentException was not thrown for empty parameter"); - } catch (IllegalArgumentException e) { - //expected - } - } - - /** - * java.security.Permission#checkGuard(java.lang.Object) - */ - public void test_checkGuardLjava_lang_Object() { - // test method java.security.permission.checkGuard(object) - SecurityPermission permi = new SecurityPermission( - "Testing the permission abstract class"); - String name = permi.getName(); - try { - permi.checkGuard(name); - } catch (SecurityException e) { - fail("security not granted when it is suppose to be : " + e); - } - } - - /** - * java.security.Permission#getName() - */ - public void test_getName() { - // test method java.security.permission.getName() - SecurityPermission permi = new SecurityPermission("testing getName()"); - String name = permi.getName(); - assertEquals("getName failed to obtain the correct name", - "testing getName()", name); - - SecurityPermission permi2 = new SecurityPermission("93048Helloworld"); - assertEquals("getName failed to obtain correct name", - "93048Helloworld", permi2.getName()); - } - - /** - * java.security.Permission#newPermissionCollection() - */ - public void test_newPermissionCollection() { - // test method java.security.permission.newPermissionCollection - Permission permi = new ConcretePermission(); - PermissionCollection permiCollect = permi.newPermissionCollection(); - assertNull("newPermissionCollector of the abstract class " - + "permission did not return a null instance " - + "of permissionCollection", permiCollect); - } - - /** - * java.security.Permission#toString() - */ - public void test_toString() { - // test method java.security.permission.toString - // test for permission with no action - SecurityPermission permi = new SecurityPermission("testing toString"); - String toString = permi.toString(); - assertNotNull("toString should have returned a string of elements", - toString); - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PermissionTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/PermissionTest.java deleted file mode 100644 index e0f280a..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PermissionTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexey V. Varlamov -* @version $Revision$ -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.security.Permission; -import java.security.SecurityPermission; - -import junit.framework.TestCase; - -/** - * Tests for <code>Permission</code> - */ -public class PermissionTest extends TestCase { - // Bare extension to instantiate abstract Permission class - static final class RealPermission extends Permission { - - public RealPermission(String name) { - super(name); - } - - public boolean equals(Object obj) { - return false; - } - - public String getActions() { - return null; - } - - public int hashCode() { - return 0; - } - - public boolean implies(Permission permission) { - return false; - } - } - - /** - * Test that a permission object is created with the specified name and is - * properly converted to String - */ - public void testCtor() { - String name = "testCtor123^%$#&^ &^$"; - Permission test = new RealPermission(name); - assertEquals(name, test.getName()); - assertEquals("(" + test.getClass().getName() + " " + name + ")", test - .toString()); - } - - /** newPermissionCollection() should return null */ - public void testCollection() { - assertNull(new RealPermission("123").newPermissionCollection()); - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java deleted file mode 100644 index 2f04ab2..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.io.File; -import java.io.FilePermission; -import java.security.AllPermission; -import java.security.Permission; -import java.security.Permissions; -import java.util.Enumeration; - -public class Permissions2Test extends junit.framework.TestCase { - FilePermission readAllFiles = new FilePermission("<<ALL FILES>>", "read"); - - FilePermission alsoReadAllFiles = new FilePermission("<<ALL FILES>>", - "read"); - - FilePermission allInCurrent = new FilePermission("*", - "read, write, execute,delete"); - - FilePermission readInCurrent = new FilePermission("*", "read"); - - FilePermission readInFile = new FilePermission("aFile.file", "read"); - - /** - * java.security.Permissions#Permissions() - */ - public void test_Constructor() { - // Test for method java.security.Permissions() - new Permissions(); - } - - /** - * java.security.Permissions#add(java.security.Permission) - */ - public void test_addLjava_security_Permission() { - // Test for method void - // java.security.Permissions.add(java.security.Permission) - char s = File.separatorChar; - FilePermission perm[] = new FilePermission[7]; - perm[0] = readAllFiles; - perm[1] = allInCurrent; - perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*", - "read,write"); - perm[3] = new FilePermission(s + "tmp" + s + "test" + s - + "collection.file", "read"); - perm[4] = alsoReadAllFiles; - perm[5] = readInFile; - perm[6] = new FilePermission("hello.file", "write"); - Permissions perms = new Permissions(); - for (int i = 0; i < perm.length; i++) { - perms.add(perm[i]); - } - - Enumeration e = perms.elements(); - FilePermission perm2[] = new FilePermission[10]; - int i = 0; - while (e.hasMoreElements()) { - perm2[i] = (FilePermission) e.nextElement(); - i++; - } - assertEquals("Permissions.elements did not return the correct number " - + "of permission - called in add() test ", i, perm.length); - - - perms.setReadOnly(); - - try { - perms.add(new AllPermission()); - fail("expected SecurityException"); - } catch (SecurityException ex) { - // ok - } - } - - /** - * java.security.Permissions#elements() - */ - public void test_elements() { - // Test for method java.util.Enumeration - // java.security.Permissions.elements() - char s = File.separatorChar; - FilePermission perm[] = new FilePermission[7]; - perm[0] = readAllFiles; - perm[1] = allInCurrent; - perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*", - "read,write"); - perm[3] = new FilePermission(s + "tmp" + s + "test" + s - + "collection.file", "read"); - perm[4] = alsoReadAllFiles; - perm[5] = readInFile; - perm[6] = new FilePermission("hello.file", "write"); - Permissions perms = new Permissions(); - for (int i = 0; i < perm.length; i++) { - perms.add(perm[i]); - } - Enumeration e = perms.elements(); - FilePermission perm2[] = new FilePermission[10]; - int i = 0; - while (e.hasMoreElements()) { - perm2[i] = (FilePermission) e.nextElement(); - i++; - } - assertEquals("Permissions.elements did not return the correct " - + "number of permission - called in element() test", i, - perm.length); - } - - /** - * java.security.Permissions#implies(java.security.Permission) - */ - public void test_impliesLjava_security_Permission() { - // Test for method boolean - // java.security.Permissions.implies(java.security.Permission) - char s = File.separatorChar; - FilePermission perm[] = new FilePermission[7]; - perm[0] = new FilePermission("test1.file", "write"); - perm[1] = allInCurrent; - perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*", - "read,write"); - perm[3] = new FilePermission(s + "tmp" + s + "test" + s - + "collection.file", "read"); - perm[4] = new FilePermission(s + "windows" + "*", "delete"); - perm[5] = readInFile; - perm[6] = new FilePermission("hello.file", "write"); - Permissions perms = new Permissions(); - for (int i = 0; i < perm.length; i++) { - perms.add(perm[i]); - } - assertTrue("Returned true for non-subset of files", !perms - .implies(new FilePermission("<<ALL FILES>>", "execute"))); - assertTrue("Returned true for non-subset of action", !perms - .implies(new FilePermission(s + "tmp" + s + "test" + s + "*", - "execute"))); - assertTrue("Returned false for subset of actions", perms - .implies(new FilePermission("*", "write"))); - assertTrue("Returned false for subset of files", perms - .implies(new FilePermission(s + "tmp" + s + "test" + s - + "test.file", "read"))); - assertTrue("Returned false for subset of files and actions", perms - .implies(new FilePermission(s + "tmp" + s + "test" + s - + "test2.file", "write"))); - } - - class TestSecurityManager extends SecurityManager { - @Override - public void checkPermission(Permission permission) { - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java deleted file mode 100644 index f086b6b..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexey V. Varlamov -* @version $Revision$ -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.security.AllPermission; -import java.security.BasicPermission; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Permissions; -import java.security.SecurityPermission; -import java.security.UnresolvedPermission; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Enumeration; -import java.util.NoSuchElementException; - - -import junit.framework.TestCase; - -/** - * Tests for <code>Permissions</code> - * - */ -public class PermissionsTest extends TestCase { - /** - * Can add any type of permissions. Cannot add if collection is read-only. - */ - public void testAdd() { - Permissions ps = new Permissions(); - Permission ap = new AllPermission(); - Permission bp = new BasicPermission("jhb23jhg5") { - }; - Permission sp0 = new SecurityPermission("abc"); - Permission sp1 = new SecurityPermission("a.b.c"); - Permission sp2 = new SecurityPermission("a.b.*"); - Permission sp3 = new SecurityPermission("a.*"); - Permission up1 = new UnresolvedPermission("131234", null, null, null); - Permission up2 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456", - "26r ytf", new java.security.cert.Certificate[0]); - Permission[] arr = new Permission[] { - up1, up2, ap, bp, sp0, sp1, sp2, sp3, }; - for (int i = 0; i < arr.length; i++) { - ps.add(arr[i]); - } - - //test add duplicate - ps.add(up1); - ps.add(sp0); - - ps.setReadOnly(); - try { - ps.add(up1); - fail("read-only flag is ignored"); - } catch (SecurityException ok) { - } - } - - /** - * Should return non-null empty enumeration for empty collection. For - * non-empty collection, should always return enumeration over unique - * elements. - */ - public void testElements() { - Permissions ps = new Permissions(); - Permission ap = new AllPermission(); - Permission bp = new BasicPermission("jhb23jhg5") { - - public PermissionCollection newPermissionCollection() { - return null; - } - }; - Permission sp = new SecurityPermission("abc"); - Permission up1 = new UnresolvedPermission("131234", null, null, null); - Permission up2 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456", - "26r ytf", new java.security.cert.Certificate[0]); - - Enumeration<Permission> en = ps.elements(); - assertNotNull(en); - assertFalse(en.hasMoreElements()); - - ps.add(up1); - en = ps.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(up1.equals(en.nextElement())); - assertFalse(en.hasMoreElements()); - - ps.add(up1); - en = ps.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(up1.equals(en.nextElement())); - //assertFalse(en.hasMoreElements()); - - Permission[] arr = new Permission[] { - ap, bp, sp, up1, up2 }; - for (int i = 0; i < arr.length; i++) { - ps.add(arr[i]); - } - en = ps.elements(); - Collection<Permission> els = new ArrayList<Permission>(); - while (en.hasMoreElements()) { - els.add(en.nextElement()); - } - //assertEquals(5, els.size()); - assertTrue(els.containsAll(Arrays.asList(arr))); - } - - - /** - * input parameter is null - */ - public void testNull(){ - Permissions ps = new Permissions(); - try { - ps.elements().nextElement(); - fail("should throw NoSuchElementException"); - } catch (NoSuchElementException e) {} - try { - ps.implies(null); - fail("should throw NPE"); - } catch (NullPointerException e){ - } - - try { - ps.add(null); - fail("should throw NullPointerException"); - } catch (NullPointerException e){} - - } - - } diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PolicyTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/PolicyTest.java deleted file mode 100644 index a708ddb..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PolicyTest.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * 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. - */ - -/** - * @author Alexey V. Varlamov - * @version $Revision$ - */ - -package org.apache.harmony.security.tests.java.security; - -import junit.framework.TestCase; - -import org.apache.harmony.security.tests.support.SecurityChecker; -import org.apache.harmony.security.tests.support.TestUtils; - -import java.io.File; -import java.io.FilePermission; -import java.net.MalformedURLException; -import java.net.URL; -import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Permissions; -import java.security.Policy; -import java.security.ProtectionDomain; -import java.security.Security; -import java.security.SecurityPermission; -import java.security.cert.Certificate; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashSet; - -/** - * Tests for <code>Policy</code> - */ -public class PolicyTest extends TestCase { - - public static final String JAVA_SECURITY_POLICY = "java.security.policy"; - - @Override protected void tearDown() throws Exception { - super.tearDown(); - } - - /** - * constructor Policy() - */ - @SuppressWarnings("cast") - public void test_constructor() { - TestProvider tp; - CodeSource cs = new CodeSource(null, (Certificate[]) null); - try { - tp = new TestProvider(); - assertTrue(tp instanceof Policy); - } catch (Exception e) { - fail("Unexpected exception " + e.getMessage()); - } - - try { - tp = new TestProvider(); - - tp.getPermissions(cs); - tp.refresh(); - } catch (Exception e) { - fail("Unexpected exception was thrown for abstract methods"); - } - } - - public static class TestProvider extends Policy { - - PermissionCollection pc; - - public PermissionCollection getPermissions(CodeSource cs) { - return pc; - } - - public void refresh() { - } - } - - /** - * Tests that getPermissions() does proper permission evaluation. - */ - public void testGetPermissions() { - SecurityPermission sp = new SecurityPermission("abc"); - SecurityPermission sp2 = new SecurityPermission("fbdf"); - PermissionCollection spc = sp.newPermissionCollection(); - spc.add(sp2); - ProtectionDomain pd = new ProtectionDomain(null, null); - ProtectionDomain pd2 = new ProtectionDomain(null, spc); - TestProvider policy = new TestProvider(); - policy.pc = sp.newPermissionCollection(); - - // case1: empty policy, no static permissions in PD - PermissionCollection pc4pd = policy.getPermissions(pd); - assertNotNull(pc4pd); - Enumeration<Permission> en = pc4pd.elements(); - assertFalse(en.hasMoreElements()); - - // case2: empty policy, some static permissions in PD - pc4pd = policy.getPermissions(pd2); - assertNotNull(pc4pd); - // no check for static permissions - - // case3: non-empty policy, no static permissions in PD - policy.pc.add(sp); - pc4pd = policy.getPermissions(pd); - assertNotNull(pc4pd); - Collection<Permission> c = new HashSet<Permission>(); - for (en = pc4pd.elements(); en.hasMoreElements(); c.add(en - .nextElement())) { - } - - assertTrue(c.contains(sp)); - - // case4: non-empty policy, some static permissions in PD - pc4pd = policy.getPermissions(pd2); - assertNotNull(pc4pd); - c = new HashSet<Permission>(); - for (en = pc4pd.elements(); en.hasMoreElements(); c.add(en - .nextElement())) { - } - - assertTrue(c.contains(sp)); - // no check for static permissions - } - - /** - * java.security.Policy#getPolicy() - * java.security.Policy#setPolicy() - */ - public void testResetingPolicyToDefault() { - - Policy oldPolicy = Policy.getPolicy(); - assertNotNull("Got a null system security policy", oldPolicy); - - try { - - Policy.setPolicy(null); // passing null resets policy - Policy newPolicy = Policy.getPolicy(); - - assertNotNull(newPolicy); - assertNotSame(oldPolicy, newPolicy); - - assertEquals("Policy class name", Security - .getProperty("policy.provider"), newPolicy.getClass() - .getName()); - } finally { - Policy.setPolicy(oldPolicy); - } - } - - /** - * java.security.Policy#implies(ProtectionDomain, Permission) - */ - public void test_implies() { - Policy policy = Policy.getPolicy(); - char s = File.separatorChar; - - URL url = null; - try { - url = new URL("http://localhost"); - } catch (MalformedURLException ex) { - throw new Error(ex); - } - CodeSource cs = new CodeSource(url, - (java.security.cert.Certificate[]) null); - - FilePermission perm[] = new FilePermission[7]; - perm[0] = new FilePermission("test1.file", "write"); - perm[1] = new FilePermission("test1.file", - "read, write, execute,delete"); - perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*", - "read,write"); - perm[3] = new FilePermission(s + "tmp" + s + "test" + s - + "collection.file", "read"); - perm[4] = new FilePermission(s + "windows" + "*", "delete"); - perm[5] = new FilePermission("aFile.file", "read"); - perm[6] = new FilePermission("hello.file", "write"); - Permissions perms = new Permissions(); - for (int i = 0; i < perm.length; i++) { - perms.add(perm[i]); - } - ProtectionDomain pd = new ProtectionDomain(cs, perms); - - assertTrue(policy.implies(pd, perm[0])); - assertTrue(policy.implies(pd, perm[1])); - assertTrue(policy.implies(pd, perm[2])); - assertTrue(policy.implies(pd, perm[3])); - assertTrue(policy.implies(pd, perm[4])); - assertTrue(policy.implies(pd, perm[5])); - assertTrue(policy.implies(pd, perm[6])); - assertTrue(policy.implies(pd, - new FilePermission("test1.file", "delete"))); - assertTrue(policy.implies(pd, - new FilePermission(s + "tmp" + s + "test" + s + "test1.file", "read"))); - - assertFalse(policy.implies(pd, new FilePermission("aFile.file", - "delete"))); - assertFalse(policy.implies(pd, new FilePermission("hello.file", - "delete"))); - assertFalse(policy.implies(pd, new FilePermission(s + "tmp" + s - + "test" + s + "collection.file", "delete"))); - assertFalse(policy.implies(pd, new FilePermission(s + "tmp" + s - + "test" + s + "*", "delete"))); - assertFalse(policy.implies(pd, new FilePermission("hello.file", - "execute"))); - - try { - assertFalse(policy.implies(pd, null)); - } catch (NullPointerException e) { - // expected - } - - try { - assertFalse(policy.implies(null, new FilePermission("test1.file", "delete"))); - } catch (NullPointerException e) { - fail("Unexpected NullPointerException"); - } - - try { - assertFalse(policy.implies(null, null)); - } catch (NullPointerException e) { - // ok - } - } - - /** - * Test property expansion in policy files - */ - public void testPropertyExpansion() throws Exception { - - // Regression for HARMONY-1963 and HARMONY-2910 - - String policyFile = getClass().getClassLoader().getResource( - "PolicyTest.txt").toString(); - String oldJavaPolicy = System.getProperty(JAVA_SECURITY_POLICY); - Policy oldPolicy = Policy.getPolicy(); - - try { - System.setProperty(JAVA_SECURITY_POLICY, policyFile); - - // test: absolute paths - assertCodeBasePropertyExpansion("/11111/*", "/11111/-"); - assertCodeBasePropertyExpansion("/22222/../22222/*", "/22222/-"); - assertCodeBasePropertyExpansion("/33333/*", "/33333/../33333/-"); - assertCodeBasePropertyExpansion("/44444/../44444/-", "/44444/*"); - assertCodeBasePropertyExpansion("/55555/../55555/-", "/55555/../55555/-"); - assertCodeBasePropertyExpansion("/666 66 66/-", "/666 66 66/-"); - - // test: relative paths - assertCodeBasePropertyExpansion("11111/*", "11111/-"); - assertCodeBasePropertyExpansion("22222/../22222/*", "22222/-"); - assertCodeBasePropertyExpansion("33333/*", "33333/../33333/-"); - assertCodeBasePropertyExpansion("44444/../44444/-", "44444/*"); - assertCodeBasePropertyExpansion("55555/../55555/-", "55555/../55555/-"); - assertCodeBasePropertyExpansion("666 66 66/-", "666 66 66/-"); - } finally { - TestUtils.setSystemProperty(JAVA_SECURITY_POLICY, oldJavaPolicy); - Policy.setPolicy(oldPolicy); - } - } - - /** - * Asserts codeBase property expansion in policy file - * - * @param codeSourceURL - - * code source for policy object - * @param codeBaseURL - - * system propery value for expansion in policy file - */ - private void assertCodeBasePropertyExpansion(String codeSourceURL, - String codeBaseURL) throws Exception { - - Policy.setPolicy(null); // reset policy - System.setProperty("test.bin.dir", codeBaseURL); - - Policy p = Policy.getPolicy(); - CodeSource codeSource = new CodeSource( - new URL("file:" + codeSourceURL), - (java.security.cert.Certificate[]) null); - - PermissionCollection pCollection = p.getPermissions(codeSource); - Enumeration<Permission> elements = pCollection.elements(); - - SecurityPermission perm = new SecurityPermission( - "codeBaseForPolicyTest"); - - while (elements.hasMoreElements()) { - if (elements.nextElement().equals(perm)) { - return; // passed - } - } - fail("Failed to find SecurityPermission for codeSource=" - + codeSourceURL + ", codeBase=" + codeBaseURL); - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionException2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionException2Test.java deleted file mode 100644 index c931777..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionException2Test.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.io.IOException; -import java.security.PrivilegedActionException; - -public class PrivilegedActionException2Test extends junit.framework.TestCase { - - private static Throwable tCause = new Throwable("Test cause"); - - /** - * java.security.PrivilegedActionException#PrivilegedActionException(java.lang.Exception) - */ - public void test_ConstructorLjava_lang_Exception() { - Exception e = new Exception("test exception"); - PrivilegedActionException pe = new PrivilegedActionException(e); - assertEquals("Did not encapsulate test exception!", e, pe - .getException()); - - // try it with a null exception - pe = new PrivilegedActionException(null); - assertNull("Did not encapsulate null test exception properly!", pe - .getException()); - } - - /** - * java.security.PrivilegedActionException#getException() - */ - public void test_getException() { - Exception e = new IOException("test IOException"); - PrivilegedActionException pe = new PrivilegedActionException(e); - assertEquals("Did not encapsulate test IOException!", e, pe - .getException()); - } - - /** - * java.security.PrivilegedActionException#getCause() - */ - public void test_getCause() { - Exception ex = new Exception("Test message", tCause); - PrivilegedActionException pe = new PrivilegedActionException(ex); - - try { - Throwable res = pe.getCause(); - if (!res.equals(ex)) { - fail("Method getCause() returned incorrect value"); - } - } catch (Exception e) { - fail("Unexpected exception"); - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java deleted file mode 100644 index 67bef5f..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexander V. Astapchuk -* @version $Revision$ -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.security.PrivilegedActionException; - -import junit.framework.TestCase; - -/** - * Unit test for java.security.PrivilegedActionException. - * - */ -public class PrivilegedActionExceptionTest extends TestCase { - /** - * Tests PrivilegedActionException(Exception) - */ - public void testPrivilegedActionException() { - new PrivilegedActionException(null); - Exception ex = new Exception(); - new PrivilegedActionException(ex); - } - - /** - * Tests PrivilegedActionException.getException() - */ - public void testGetException() { - assertNull(new PrivilegedActionException(null).getException()); - Exception ex = new Exception(); - assertSame(new PrivilegedActionException(ex).getException(), ex); - } - - /** - * Tests PrivilegedActionException.toString() - */ - public void testToString() { - assertNotNull(new PrivilegedActionException(null).toString()); - assertNotNull(new PrivilegedActionException(new Exception()).toString()); - } - -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedExceptionActionTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedExceptionActionTest.java deleted file mode 100644 index 597ee47..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedExceptionActionTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.apache.harmony.security.tests.java.security; - -import junit.framework.TestCase; - -import java.io.IOException; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -public class PrivilegedExceptionActionTest extends TestCase { - - protected void setUp() throws Exception { - super.setUp(); - } - - private class MyPrivilegedExceptionAction implements - PrivilegedExceptionAction<String> { - private boolean called = false; - - public String run() throws Exception { - called = true; - return "ok"; - } - } - - private class MyPrivilegedExceptionAction2 implements - PrivilegedExceptionAction<String> { - - private boolean called = false; - private Exception toThrow = null; - - public MyPrivilegedExceptionAction2(Exception toThrow) { - this.toThrow = toThrow; - } - - public String run() throws Exception { - called = true; - if (toThrow == null) { - return "ok"; - } else { - throw toThrow; - } - } - } - - public void testRun() { - MyPrivilegedExceptionAction action1 = new MyPrivilegedExceptionAction(); - try { - String result = AccessController.doPrivileged(action1); - assertEquals("unexpected result", "ok", result); - assertTrue("method not called", action1.called); - } catch (PrivilegedActionException e) { - fail("unexpected exception : " + e); - } - - Exception[] exceptions = {new NullPointerException(), new IOException(), null}; - for (int i = 0; i < exceptions.length; i++) { - Exception exception = exceptions[i]; - MyPrivilegedExceptionAction2 action2 = new MyPrivilegedExceptionAction2(exception); - try { - String result = AccessController.doPrivileged(action2); - assertTrue("method not called", action1.called); - if (exception == null) - { - assertEquals("unexpected result", "ok", result); - } - else { - fail("privileged action exception expected"); - } - } catch (PrivilegedActionException e) { - assertTrue("method not called", action2.called); - assertSame("expected exception not thrown", exception, e.getCause()); - // ok - } catch (RuntimeException e) { - assertSame("expected exception not thrown", exception, e); - } - } - } - - -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java deleted file mode 100644 index cdea5c5..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java +++ /dev/null @@ -1,272 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexander V. Astapchuk -* @version $Revision$ -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.net.URL; -import java.net.MalformedURLException; -import java.net.URLClassLoader; -import java.security.AllPermission; -import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Permissions; -import java.security.Policy; -import java.security.Principal; -import java.security.ProtectionDomain; - -import junit.framework.TestCase; - -/** - * Unit tests for java.security.ProtectionDomain. - * - */ -public class ProtectionDomainTest extends TestCase { - - private final AllPermission allperm = new AllPermission(); - - private URL url = null; - - private CodeSource cs = null; - - private PermissionCollection perms = null; - - private ClassLoader classldr = null; - - private Principal[] principals = null; // changed in setUp() - - /* - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - try { - url = new URL("http://localhost"); - } catch (MalformedURLException ex) { - throw new Error(ex); - } - cs = new CodeSource(url, (java.security.cert.Certificate[]) null); - perms = allperm.newPermissionCollection(); - perms.add(allperm); - classldr = URLClassLoader.newInstance(new URL[] { url }); - principals = new Principal[] { new TestPrincipal("0"), - new TestPrincipal("1"), new TestPrincipal("2"), - new TestPrincipal("3"), new TestPrincipal("4"), }; - } - - /** - * Class under test for void ProtectionDomain(CodeSource, - * PermissionCollection) - */ - public void testProtectionDomainCodeSourcePermissionCollection_00() { - new ProtectionDomain(null, null); - new ProtectionDomain(cs, null); - - new ProtectionDomain(cs, perms); - } - - /** - * the ctor must set the PermissionCollection read-only - */ - public void testProtectionDomainCodeSourcePermissionCollection_01() { - assertFalse(perms.isReadOnly()); - new ProtectionDomain(null, perms); - assertTrue(perms.isReadOnly()); - } - - /** - * Test for ProtectionDomain(CodeSource, PermissionCollection, ClassLoader, Principal[]) - */ - public void testProtectionDomainCodeSourcePermissionCollectionClassLoaderPrincipalArray() { - new ProtectionDomain(null, null, null, null); - - new ProtectionDomain(cs, null, null, null); - new ProtectionDomain(null, perms, null, null); - new ProtectionDomain(null, null, classldr, null); - new ProtectionDomain(null, null, null, principals); - - new ProtectionDomain(cs, perms, classldr, principals); - } - - /** - * Tests for ProtectionDomain.getClassLoader() - */ - public void testGetClassLoader() { - assertNull(new ProtectionDomain(null, null).getClassLoader()); - assertSame(new ProtectionDomain(null, null, classldr, null) - .getClassLoader(), classldr); - } - - /** - * Tests for ProtectionDomain.getCodeSource() - */ - public void testGetCodeSource() { - assertNull(new ProtectionDomain(null, null).getCodeSource()); - assertSame(new ProtectionDomain(cs, null).getCodeSource(), cs); - } - - /** - * Tests for ProtectionDomain.getPermissions() - */ - public void testGetPermissions() { - assertNull(new ProtectionDomain(null, null).getPermissions()); - assertSame(new ProtectionDomain(null, perms).getPermissions(), perms); - } - - /** - * getPrincipals() always returns non null array - */ - public void testGetPrincipals_00() { - assertNotNull(new ProtectionDomain(null, null).getPrincipals()); - } - - /** - * getPrincipals() returns new array each time it's called - */ - public void testGetPrincipals_01() { - ProtectionDomain pd = new ProtectionDomain(null, null, null, principals); - Principal[] got = pd.getPrincipals(); - assertNotNull(got); - assertNotSame(got, principals); - assertNotSame(got, pd.getPrincipals()); - assertTrue(got.length == principals.length); - } - - /** - * ProtectionDomain with null Permissions must not imply() permissions. - */ - public void testImplies_00() { - assertFalse(new ProtectionDomain(null, null).implies(allperm)); - } - - /** - * ProtectionDomain with PermissionCollection which contains AllPermission - * must imply() AllPermission. - */ - public void testImplies_01() { - assertTrue(new ProtectionDomain(null, perms).implies(allperm)); - } - - /** - * ProtectionDomain created with a static set of permissions must not query - * policy. - */ - public void testImplies_02() { - TestPolicy policy = new TestPolicy(); - // null set of permissions [must] force the PD to use Policy - for - // dynamic permissions - ProtectionDomain pd = new ProtectionDomain(cs, null); - policy.setTrackPD(pd); - try { - Policy.setPolicy(policy); - pd.implies(allperm); - } finally { - Policy.setPolicy(null); - } - assertFalse(policy.getPdTracked()); - } - - /** - * ProtectionDomain created with dynamic set of permissions must query - * policy. - */ - public void testImplies_03() { - TestPolicy policy = new TestPolicy(); - ProtectionDomain pd = new ProtectionDomain(cs, null, ClassLoader - .getSystemClassLoader(), principals); - policy.setTrackPD(pd); - try { - Policy.setPolicy(policy); - pd.implies(allperm); - } finally { - Policy.setPolicy(null); - } - assertTrue(policy.getPdTracked()); - } - - /** - * Simply checks that it's working somehow - */ - public void testToString() { - String res; - res = new ProtectionDomain(null, null).toString(); - assertTrue(res.contains("ProtectionDomain")); - res = new ProtectionDomain(cs, perms).toString(); - assertTrue(res.contains("ProtectionDomain")); - res = new ProtectionDomain(null, null, null, null).toString(); - assertTrue(res.contains("ProtectionDomain")); - res = new ProtectionDomain(cs, perms, classldr, principals).toString(); - assertTrue(res.contains("ProtectionDomain")); - } - - /** - * Test principal used during the testing. Does nothing. - */ - - private static class TestPrincipal implements Principal { - private String name; - - TestPrincipal(String name) { - this.name = name; - } - - public String getName() { - return "TestPrincipal: " + name; - } - } - - private static class TestPolicy extends Policy { - ProtectionDomain trackPD = null; - - boolean pdTracked = false; - - ProtectionDomain setTrackPD(ProtectionDomain pd) { - ProtectionDomain tmp = trackPD; - trackPD = pd; - pdTracked = false; - return tmp; - } - - boolean getPdTracked() { - return pdTracked; - } - - public PermissionCollection getPermissions(CodeSource cs) { - return new Permissions(); - } - - // public PermissionCollection getPermissions(ProtectionDomain domain) { - // return super.getPermissions(domain); - // } - public boolean implies(ProtectionDomain domain, Permission permission) { - if (trackPD != null && trackPD == domain) { - pdTracked = true; - } - return super.implies(domain, permission); - } - - public void refresh() { - // do nothing - } - } - -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java deleted file mode 100644 index f47e2d4..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.security.SecurityPermission; - -public class SecurityPermission2Test extends junit.framework.TestCase { - - /** - * java.security.SecurityPermission#SecurityPermission(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // Test for method java.security.SecurityPermission(java.lang.String) - assertEquals("create securityPermission constructor(string) failed", - "SecurityPermission(string)", new SecurityPermission("SecurityPermission(string)").getName() - ); - - } - - /** - * java.security.SecurityPermission#SecurityPermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.security.SecurityPermission(java.lang.String, - // java.lang.String) - SecurityPermission sp = new SecurityPermission("security.file", "write"); - assertEquals("creat securityPermission constructor(string,string) failed", - "security.file", sp.getName()); - - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java deleted file mode 100644 index 99bf0ac..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexey V. Varlamov -* @version $Revision$ -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.security.SecurityPermission; - -import junit.framework.TestCase; - -/** - * Tests for <code>SecurityPermission</code> - * - */ -public class SecurityPermissionTest extends TestCase { - /** - * Check all constructors: an object is created with the specified valid name. - * If name equal null then NPE should be thrown. - * If name is empty then IAE should be thrown. - * Action is ignored. - */ - public void testCtor() - { - String name = "basic123*$%#"; - SecurityPermission test = new SecurityPermission(name); - assertEquals(name, test.getName()); - assertEquals("", test.getActions()); - test = new SecurityPermission(name, "#$!#12435"); - assertEquals(name, test.getName()); - assertEquals("", test.getActions()); - try{ - new SecurityPermission(null); - fail("NPE is not thrown"); - } - catch (NullPointerException ok){} - - try{ - new SecurityPermission(null, "ds235"); - fail("NPE is not thrown"); - } - catch (NullPointerException ok){} - - try{ - new SecurityPermission(""); - fail("IAE is not thrown"); - } - catch (IllegalArgumentException ok){} - try{ - new SecurityPermission("", "ertre 3454"); - fail("IAE is not thrown"); - } - catch (IllegalArgumentException ok){} - } -} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java deleted file mode 100644 index df1c8e4..0000000 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java +++ /dev/null @@ -1,352 +0,0 @@ -/* - * 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.harmony.security.tests.java.security; - -import java.io.Serializable; -import java.security.AllPermission; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.PublicKey; -import java.security.SecurityPermission; -import java.security.SignatureException; -import java.security.UnresolvedPermission; -import java.security.cert.Certificate; -import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.util.Arrays; -import java.util.Enumeration; -import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; -import org.apache.harmony.testframework.serialization.SerializationTest; - -import tests.util.SerializationTester; - -import org.apache.harmony.testframework.serialization.SerializationTest; -import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; - -import tests.util.SerializationTester; - -import junit.framework.TestCase; - -/** - * Tests for <code>UnresolvedPermission</code> class fields and methods - * - */ -public class UnresolvedPermissionTest extends TestCase { - - /** - * Creates an Object with given name, type, action, certificates. Empty or - * null type is not allowed - exception should be thrown. - */ - public void testCtor() { - String type = "laskjhlsdk 2345346"; - String name = "^%#UHVKU^%V 887y"; - String action = "JHB ^%(*&T klj3h4"; - UnresolvedPermission up = new UnresolvedPermission(type, name, action, - null); - assertEquals(type, up.getName()); - assertEquals("", up.getActions()); - assertEquals("(unresolved " + type + " " + name + " " + action + ")", - up.toString()); - - up = new UnresolvedPermission(type, null, null, null); - assertEquals(type, up.getName()); - assertEquals("", up.getActions()); - assertEquals("(unresolved " + type + " null null)", up.toString()); - - up = new UnresolvedPermission(type, "", "", - new java.security.cert.Certificate[0]); - assertEquals(type, up.getName()); - assertEquals("", up.getActions()); - assertEquals("(unresolved " + type + " )", up.toString()); - - try { - new UnresolvedPermission(null, name, action, null); - fail("No expected NullPointerException"); - } catch (NullPointerException ok) { - } - - // Regression for HARMONY-733 - up = new UnresolvedPermission("", "name", "action", null); - assertEquals("", up.getName()); - } - - /** - * UnresolvedPermission never implies any other permission. - */ - public void testImplies() { - UnresolvedPermission up = new UnresolvedPermission( - "java.security.SecurityPermission", "a.b.c", null, null); - assertFalse(up.implies(up)); - assertFalse(up.implies(new AllPermission())); - assertFalse(up.implies(new SecurityPermission("a.b.c"))); - } - public void testSerialization() throws Exception { - UnresolvedPermission up = new UnresolvedPermission( - "java.security.SecurityPermission", "a.b.c", "actions", null); - assertEquals("java.security.SecurityPermission", up.getUnresolvedType()); - assertEquals("a.b.c", up.getUnresolvedName()); - assertEquals("actions", up.getUnresolvedActions()); - assertNull(up.getUnresolvedCerts()); - - UnresolvedPermission deserializedUp = (UnresolvedPermission) SerializationTester - .getDeserilizedObject(up); - assertEquals("java.security.SecurityPermission", deserializedUp - .getUnresolvedType()); - assertEquals("a.b.c", deserializedUp.getUnresolvedName()); - assertEquals("actions", deserializedUp.getUnresolvedActions()); - assertNull(deserializedUp.getUnresolvedCerts()); - } - public void testSerialization_Compatibility() throws Exception { - UnresolvedPermission up = new UnresolvedPermission( - "java.security.SecurityPermission", "a.b.c", "actions", null); - assertEquals("java.security.SecurityPermission", up.getUnresolvedType()); - assertEquals("a.b.c", up.getUnresolvedName()); - assertEquals("actions", up.getUnresolvedActions()); - assertNull(up.getUnresolvedCerts()); - - SerializationTest.verifyGolden(this, up, new SerializableAssert() { - public void assertDeserialized(Serializable orig, Serializable ser) { - UnresolvedPermission deserializedUp = (UnresolvedPermission) ser; - assertEquals("java.security.SecurityPermission", deserializedUp - .getUnresolvedType()); - assertEquals("a.b.c", deserializedUp.getUnresolvedName()); - assertEquals("actions", deserializedUp.getUnresolvedActions()); - assertNull(deserializedUp.getUnresolvedCerts()); - } - }); - } - public void testEquals() { - UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up2 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up3 = new UnresolvedPermission("type3", "name3", - "action3", null); - - UnresolvedPermission up4 = null; - - assertTrue(up1.equals(up1)); - assertTrue(up2.equals(up2)); - assertTrue(up3.equals(up3)); - - assertTrue(!up1.equals(null)); - assertTrue(!up2.equals(null)); - assertTrue(!up3.equals(null)); - - assertTrue(up1.equals(up2)); - assertTrue(!up1.equals(up3)); - - assertTrue(up2.equals(up1)); - assertTrue(!up2.equals(up3)); - - assertTrue(!up3.equals(up1)); - assertTrue(!up3.equals(up2)); - - try { - assertTrue(up4.equals(up1)); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - - } - - public void testGetActions() { - UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up2 = null; - - assertEquals("", up1.getActions()); - try { - up2.getActions(); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - } - - public void testGetUnresolvedActions() { - UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", - "action1 @#$%^&*", null); - UnresolvedPermission up2 = null; - - assertEquals("action1 @#$%^&*", up1.getUnresolvedActions()); - try { - up2.getUnresolvedActions(); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - } - - public void testGetUnresolvedCerts() { - Certificate[] certificate = new java.security.cert.Certificate[] { - new Certificate(null) { - - @Override - public byte[] getEncoded() - throws CertificateEncodingException { - // TODO Auto-generated method stub - return null; - } - - @Override - public PublicKey getPublicKey() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String toString() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void verify(PublicKey key) - throws CertificateException, - NoSuchAlgorithmException, InvalidKeyException, - NoSuchProviderException, SignatureException { - // TODO Auto-generated method stub - - } - - @Override - public void verify(PublicKey key, String sigProvider) - throws CertificateException, - NoSuchAlgorithmException, InvalidKeyException, - NoSuchProviderException, SignatureException { - // TODO Auto-generated method stub - - } - - } - }; - UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", - "action1 @#$%^&*", null); - UnresolvedPermission up2 = null; - UnresolvedPermission up3 = new UnresolvedPermission("type3", "name3", - "action3", certificate); - - assertNull(up1.getUnresolvedCerts()); - assertTrue(Arrays.equals(certificate, up3.getUnresolvedCerts())); - - try { - up2.getUnresolvedCerts(); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - } - - public void testGetUnresolvedName() { - UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1!@#$%^&&* )(", - "action1 @#$%^&*", null); - UnresolvedPermission up2 = null; - - assertEquals("name1!@#$%^&&* )(", up1.getUnresolvedName()); - try { - up2.getUnresolvedName(); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - } - - public void testGetUnresolvedType() { - UnresolvedPermission up1 = new UnresolvedPermission("type1@#$%^&* )(", "name1", - "action1", null); - UnresolvedPermission up2 = null; - - assertEquals("type1@#$%^&* )(", up1.getUnresolvedType()); - try { - up2.getUnresolvedType(); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - } - - public void testHashCode() { - UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up2 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up3 = new UnresolvedPermission("type3", "name3", - "action3", null); - - UnresolvedPermission up4 = null; - - assertTrue(up1.hashCode() == up2.hashCode()); - assertTrue(up1.hashCode() != up3.hashCode()); - assertTrue(up2.hashCode() != up3.hashCode()); - - try { - up4.hashCode(); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - } - - public void testNewPermissionCollection() { - UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up2 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up3 = null; - - PermissionCollection pc = up1.newPermissionCollection(); - assertTrue(!pc.isReadOnly()); - pc.add(up1); - pc.add(up2); - Enumeration<Permission> permissions = pc.elements(); - assertNotNull(permissions); - - assertTrue("Should imply", !pc.implies(up1)); - assertTrue("Should not imply", !pc.implies(up3)); - - try { - up3.newPermissionCollection(); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - - } - - public void testToString() { - UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up2 = new UnresolvedPermission("type1", "name1", - "action1", null); - UnresolvedPermission up3 = null; - assertTrue(up1.toString().contains("")); - assertTrue(up2.toString().contains("")); - try { - up3.toString(); - fail("NullPointerException expected"); - }catch (NullPointerException e) { - // expected - } - } - -} diff --git a/luni/src/test/java/tests/api/java/lang/reflect/ReflectPermissionTest.java b/luni/src/test/java/tests/api/java/lang/reflect/ReflectPermissionTest.java deleted file mode 100644 index c5f7f7f..0000000 --- a/luni/src/test/java/tests/api/java/lang/reflect/ReflectPermissionTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 tests.api.java.lang.reflect; - -import java.lang.reflect.ReflectPermission; - -public class ReflectPermissionTest extends junit.framework.TestCase { - - /** - * java.lang.reflect.ReflectPermission#ReflectPermission(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // Test for method java.lang.reflect.ReflectPermission(java.lang.String) - String permString = new ReflectPermission("Blah").toString(); - assertTrue("Incorrect permission constructed", permString.indexOf( - "java.lang.reflect.ReflectPermission Blah") >= 0); - } - - /** - * java.lang.reflect.ReflectPermission#ReflectPermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.lang.reflect.ReflectPermission(java.lang.String, - // java.lang.String) - assertTrue("Incorrect permission constructed", new ReflectPermission( - "Blah", "suppressAccessChecks").toString().indexOf( - "java.lang.reflect.ReflectPermission Blah") >= 0); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - } -} diff --git a/luni/src/test/java/tests/api/java/util/PropertyPermissionTest.java b/luni/src/test/java/tests/api/java/util/PropertyPermissionTest.java deleted file mode 100644 index 64b8529..0000000 --- a/luni/src/test/java/tests/api/java/util/PropertyPermissionTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * 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 tests.api.java.util; - -import java.io.Serializable; -import java.util.Enumeration; -import java.util.PropertyPermission; - -import org.apache.harmony.testframework.serialization.SerializationTest; -import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; - -public class PropertyPermissionTest extends junit.framework.TestCase { - - static PropertyPermission javaPP = new PropertyPermission("java.*", "read"); - - static PropertyPermission userPP = new PropertyPermission("user.name", - "read,write"); - - /** - * java.util.PropertyPermission#PropertyPermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.util.PropertyPermission(java.lang.String, - // java.lang.String) - assertTrue("Used to test", true); - } - - /** - * java.util.PropertyPermission#equals(java.lang.Object) - */ - public void test_equalsLjava_lang_Object() { - // Test for method boolean - // java.util.PropertyPermission.equals(java.lang.Object) - PropertyPermission equalToJavaPP = new PropertyPermission("java.*", - "read"); - PropertyPermission notEqualToJavaPP = new PropertyPermission("java.*", - "read, write"); - PropertyPermission alsoNotEqualToJavaPP = new PropertyPermission( - "java.home", "read"); - - assertTrue("Equal returned false for equal objects", javaPP - .equals(equalToJavaPP)); - assertTrue("Equal returned true for objects with different names", - !javaPP.equals(notEqualToJavaPP)); - assertTrue( - "Equal returned true for objects with different permissions", - !javaPP.equals(alsoNotEqualToJavaPP)); - } - - /** - * java.util.PropertyPermission#getActions() - */ - public void test_getActions() { - // Test for method java.lang.String - // java.util.PropertyPermission.getActions() - assertEquals("getActions did not return proper action", "read", javaPP - .getActions()); - assertEquals("getActions did not return proper canonical representation of actions", - "read,write", userPP.getActions()); - } - - /** - * java.util.PropertyPermission#hashCode() - */ - public void test_hashCode() { - // Test for method int java.util.PropertyPermission.hashCode() - assertTrue("javaPP returned wrong hashCode", - javaPP.hashCode() == javaPP.getName().hashCode()); - assertTrue("userPP returned wrong hashCode", - userPP.hashCode() == userPP.getName().hashCode()); - } - - /** - * java.util.PropertyPermission#implies(java.security.Permission) - */ - public void test_impliesLjava_security_Permission() { - // Test for method boolean - // java.util.PropertyPermission.implies(java.security.Permission) - PropertyPermission impliedByJavaPP = new PropertyPermission( - "java.home", "read"); - PropertyPermission notImpliedByJavaPP = new PropertyPermission( - "java.home", "read,write"); - PropertyPermission impliedByUserPP = new PropertyPermission( - "user.name", "read,write"); - PropertyPermission alsoImpliedByUserPP = new PropertyPermission( - "user.name", "write"); - assertTrue("Returned false for implied permission (subset of .*)", - javaPP.implies(impliedByJavaPP)); - assertTrue("Returned true for unimplied permission", !javaPP - .implies(notImpliedByJavaPP)); - assertTrue("Returned false for implied permission (equal)", userPP - .implies(impliedByUserPP)); - assertTrue("Returned false for implied permission (subset of actions)", - userPP.implies(alsoImpliedByUserPP)); - } - - /** - * java.util.PropertyPermission#newPermissionCollection() - */ - public void test_newPermissionCollection() { - // Test for method java.security.PermissionCollection - // java.util.PropertyPermission.newPermissionCollection() - java.security.PermissionCollection pc = javaPP - .newPermissionCollection(); - pc.add(javaPP); - Enumeration elementEnum = pc.elements(); - assertTrue("Invalid PermissionCollection returned", elementEnum - .nextElement().equals(javaPP)); - } - - /** - * java.util.PropertyPermission#readObject(ObjectInputStream) - * java.util.PropertyPermission#writeObject(ObjectOutputStream) - */ - public void test_serialization() throws Exception{ - PropertyPermission pp = new PropertyPermission("test", "read"); - SerializationTest.verifySelf(pp, comparator); - SerializationTest.verifyGolden(this, pp, comparator); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - } - - private static final SerializableAssert comparator = new SerializableAssert() { - - public void assertDeserialized(Serializable initial, Serializable deserialized) { - PropertyPermission initialPP = (PropertyPermission) initial; - PropertyPermission deseriaPP = (PropertyPermission) deserialized; - assertEquals("should be equal", initialPP, deseriaPP); - } - - }; -} diff --git a/luni/src/test/java/tests/api/javax/net/ssl/SSLPermissionTest.java b/luni/src/test/java/tests/api/javax/net/ssl/SSLPermissionTest.java deleted file mode 100644 index 313eace..0000000 --- a/luni/src/test/java/tests/api/javax/net/ssl/SSLPermissionTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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 tests.api.javax.net.ssl; - -import javax.net.ssl.SSLPermission; -import junit.framework.TestCase; - - -/** - * Tests for <code>SSLPermission</code> class constructors. - * - */ -public class SSLPermissionTest extends TestCase { - - /* - * Class under test for void SSLPermission(String) - */ - public void test_ConstructorLjava_lang_String() { - try { - SSLPermission p = new SSLPermission("name"); - assertEquals("Incorrect permission name", "name", p.getName()); - try { - p = new SSLPermission(null); - } catch (NullPointerException npe) { - //expected - } - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /* - * Class under test for void SSLPermission(String, String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - try { - SSLPermission p = new SSLPermission("name", "value"); - assertEquals("Incorrect permission name", "name", p.getName()); - assertEquals("Incorrect default permission actions", - "", p.getActions()); - try { - p = new SSLPermission(null, "value"); - } catch (NullPointerException npe) { - //expected - } - try { - p = new SSLPermission("name", null); - } catch (NullPointerException npe) { - //expected - } - try { - p = new SSLPermission(null, null); - } catch (NullPointerException npe) { - //expected - } - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } -} diff --git a/luni/src/test/java/tests/api/javax/security/auth/AuthPermissionTest.java b/luni/src/test/java/tests/api/javax/security/auth/AuthPermissionTest.java deleted file mode 100644 index c951700..0000000 --- a/luni/src/test/java/tests/api/javax/security/auth/AuthPermissionTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 tests.api.javax.security.auth; - -import junit.framework.TestCase; - -import javax.security.auth.AuthPermission; - - -/** - * Tests for <code>AuthPermission</code> class constructors and methods. - * - */ -public class AuthPermissionTest extends TestCase { - - /** - * javax.security.auth.AuthPermission#AuthPermission(String name) - */ - public void test_Constructor_01() { - String[] strParam = {"", null}; - - try { - AuthPermission ap = new AuthPermission("AuthPermissionName"); - assertNotNull("Null object returned", ap); - assertEquals("AuthPermissionName", ap.getName()); - } catch (Exception e) { - fail("Unexpected exception: " + e); - } - - for (int i = 0; i < strParam.length; i++) { - try { - AuthPermission ap = new AuthPermission(strParam[i]); - } catch (Exception e) { - } - } - } - - /** - * javax.security.auth.AuthPermission#AuthPermission(String name, String actions) - */ - public void test_Constructor_02() { - String[] strParam = {"", null}; - String[] actionParam = {"", null, "ActionName"}; - - try { - AuthPermission ap = new AuthPermission("AuthPermissionName", null); - assertNotNull("Null object returned", ap); - assertEquals("AuthPermissionName", ap.getName()); - assertEquals("", ap.getActions()); - } catch (Exception e) { - fail("Unexpected exception: " + e); - } - - for (int i = 0; i < strParam.length; i++) { - try { - AuthPermission ap = new AuthPermission(strParam[i], null); - } catch (Exception e) { - } - } - - for (int i = 0; i < actionParam.length; i++) { - try { - AuthPermission ap = new AuthPermission("AuthPermissionName", actionParam[i]); - assertNotNull("Null object returned", ap); - assertEquals("", ap.getActions()); - } catch (Exception e) { - fail("Unexpected exception: " + e); - } - } - } -} diff --git a/luni/src/test/java/tests/api/javax/security/auth/PrivateCredentialPermissionTest.java b/luni/src/test/java/tests/api/javax/security/auth/PrivateCredentialPermissionTest.java deleted file mode 100644 index 6426a26..0000000 --- a/luni/src/test/java/tests/api/javax/security/auth/PrivateCredentialPermissionTest.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * 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 tests.api.javax.security.auth; - -import java.security.Permission; - -import junit.framework.TestCase; - -import javax.security.auth.PrivateCredentialPermission; - - -/** - * Tests for <code>PrivateCredentialPermission</code> class constructors and methods. - * - */ -public class PrivateCredentialPermissionTest extends TestCase { - - private final static String cred_class1 = "a.b.Credential"; - private final static String cred_class2 = "a.b.Credential1"; - private final static String name1 = cred_class1 + " a.b.Principal \"*\""; - private final static String name2 = cred_class1 + " a.c.Principal \"*\""; - private final static String name4 = cred_class2 + " a.c.Principal \"*\""; - private final static String pc1 = "a.b.Principal"; - private final static String pn1 = "*"; - private final static String pc2 = "a.c.Principal"; - private final static String pn2 = "abc"; - - private final static String name3 = cred_class1 + " " + pc1 + " \"" + pn1 + "\" " + pc2 + " \"" + pn2 + "\""; - - /** - * javax.security.auth.PrivateCredentialPermission#PrivateCredentialPermission(String name, String actions) - */ - public void test_Constructor_01() { - PrivateCredentialPermission ap = new PrivateCredentialPermission(name1, "read"); - - String actions[] = { "write", "", null }; - - for(int i = 0; i < actions.length; i++) { - try { - ap = new PrivateCredentialPermission(name1, "write"); - fail("expected IllegalArgumentException if action is not \"read\""); - } catch (IllegalArgumentException e) { - // expected - } - } - - String names[] = { null, - "", - "a.b.Credential a.c.Principal *\"", - "a.b.Credential_a.c.Principal_\"*\"", - "a.b.Credential a.c.Principal_\"*\"", - "a.b.Credential * \"a\"" - }; - - for(int i = 0; i < names.length; i++) { - try { - ap = new PrivateCredentialPermission(names[i], "read"); - fail("expected IllegalArgumentException for malformed \"name\" argument (" + names[i] +")"); - } catch (IllegalArgumentException e) { - // expected - } catch (NullPointerException npe) { - if (names[i] != null) - throw npe; - else - ; // expected if name is null - } - } - } - - /** - * javax.security.auth.PrivateCredentialPermission#getActions() - */ - public void test_getActions() { - PrivateCredentialPermission ap = new PrivateCredentialPermission(name1, "read"); - assertEquals("getActions() must alway return \"read\"", "read", ap.getActions()); - } - - /** - * javax.security.auth.PrivateCredentialPermission#implies() - */ - public void test_implies() { - PrivateCredentialPermission p1 = new PrivateCredentialPermission("* P1 \"abc\"", "read"); - PrivateCredentialPermission p2 = new PrivateCredentialPermission("a.b.Credential P1 \"abc\"", "read"); - PrivateCredentialPermission p3 = new PrivateCredentialPermission("C1 P1 \"abc\"", "read"); - PrivateCredentialPermission p4 = new PrivateCredentialPermission("C1 P1 \"abc\" P2 \"abcd\"", "read"); - PrivateCredentialPermission p5 = new PrivateCredentialPermission("C1 P1 \"*\"", "read"); - PrivateCredentialPermission p6 = new PrivateCredentialPermission("a.b.Credential * \"*\"", "read"); - PrivateCredentialPermission p7 = new PrivateCredentialPermission("a.b.Credential P2 \"abc\"", "read"); - PrivateCredentialPermission p8 = new PrivateCredentialPermission("a.b.Credential1 P2 \"abc\"", "read"); - PrivateCredentialPermission p9 = new PrivateCredentialPermission("a.b.Credential1 P2 \"*\"", "read"); - - PrivateCredentialPermission[][] arr = { { p1, p2 }, - { p2, p1 }, - { p3, p4 }, - { p5, p3 }, - { p6, p2 }, - { p2, p7 }, - { p7, p8 }, - { p8, p9 }}; - - boolean[] r = { true, false, true, true, true, false, false, false }; - for(int i = 0; i < arr.length; i++) - assertEquals("implies() returned wrong result (" + i + ")", r[i], arr[i][0].implies(arr[i][1])); - } - - /** - * javax.security.auth.PrivateCredentialPermission#getCredentialClass() - */ - public void test_getCredentialClass() { - PrivateCredentialPermission ap = new PrivateCredentialPermission(name1, "read"); - assertEquals("getCredentialClass() returned wrong name", cred_class1, ap.getCredentialClass()); - } - - /** - * javax.security.auth.PrivateCredentialPermission#getPrincipals() - */ - public void test_getPrincipals() { - - PrivateCredentialPermission ap = new PrivateCredentialPermission(name3, "read"); - String[][] p = ap.getPrincipals(); - - assertEquals("wrong number of principals", 2, p.length); - - assertEquals("wrong principal class 0", pc1, p[0][0]); - assertEquals("wrong principal name 0", pn1, p[0][1]); - - assertEquals("wrong principal class 1", pc2, p[1][0]); - assertEquals("wrong principal name 1", pn2, p[1][1]); - } - - /** - * javax.security.auth.PrivateCredentialPermission#equals() - */ - public void test_equals() { - PrivateCredentialPermission p1 = new PrivateCredentialPermission(name3, "read"); - PrivateCredentialPermission p2 = new PrivateCredentialPermission(name3, "read"); - PrivateCredentialPermission p3 = new PrivateCredentialPermission(name1, "read"); - PrivateCredentialPermission p4 = new PrivateCredentialPermission(name1, "read"); - PrivateCredentialPermission p5 = new PrivateCredentialPermission(name2, "read"); - PrivateCredentialPermission p6 = new PrivateCredentialPermission(name4, "read"); - - PrivateCredentialPermission arr[][] = { { p1, p2 }, - { p3, p4 }, - { p4, p5 }, - { p1, p3 }, - { p4, p6 } }; - boolean r[] = { true, true, false, false, false }; - - for(int i = 0; i < arr.length; i++) { - assertEquals("equals() returned wrong result", r[i], arr[i][0].equals(arr[i][1])); - } - - try { - assertFalse(p1.equals(null)); - } catch(NullPointerException npe) { - - } - } - - /** - * javax.security.auth.PrivateCredentialPermission#hashCode() - */ - public void test_hashCode() { - PrivateCredentialPermission p1 = new PrivateCredentialPermission(name1, "read"); - PrivateCredentialPermission p2 = new PrivateCredentialPermission(name1, "read"); - int arr[][] = new int[10][]; - for(int i = 0; i < 10; i++) { - int h1 = p1.hashCode(); - - System.gc(); - - // force some memory allocations - arr[i] = new int[50000]; - - assertEquals("hashCode() must consistently return the same integer", h1, p1.hashCode()); - assertEquals("hashCode() must be the same for equal PrivateCredentialPermission objects", p1.hashCode(), p2.hashCode()); - } - - - PrivateCredentialPermission p3 = new PrivateCredentialPermission(name4, "read"); - assertFalse("hashCode() must not be the same for non-equal PrivateCredentialPermission objects", p1.hashCode() == p3.hashCode()); - } - - /** - * javax.security.auth.PrivateCredentialPermission#newPermissionCollection() - */ - public void test_newPermissionCollection() { - PrivateCredentialPermission ap = new PrivateCredentialPermission(name1, "read"); - assertNull("newPermissionCollection must always return null", ap.newPermissionCollection()); - } - -} - diff --git a/luni/src/test/java/tests/java/security/AllPermissionTest.java b/luni/src/test/java/tests/java/security/AllPermissionTest.java deleted file mode 100644 index 32056d8..0000000 --- a/luni/src/test/java/tests/java/security/AllPermissionTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexey V. Varlamov -* @version $Revision$ -*/ - -package tests.java.security; - -import java.security.AllPermission; -import java.security.BasicPermission; -import java.security.PermissionCollection; -import java.security.UnresolvedPermission; - -import junit.framework.TestCase; -/** - * Tests for <code>AllPermission</code> - * - */ -public class AllPermissionTest extends TestCase { - - /** - * Test all constructors: an object is created, name and actions are ignored - */ - public void testCtor() - { - AllPermission a1 = new AllPermission(); - assertEquals("<all permissions>", a1.getName()); - assertEquals("<all actions>", a1.getActions()); - - a1 = new AllPermission("sdfsdfwe&^$", "*&IUGJKHVB764"); - assertEquals("<all permissions>", a1.getName()); - assertEquals("<all actions>", a1.getActions()); - - a1 = new AllPermission(null, ""); - assertEquals("<all permissions>", a1.getName()); - assertEquals("<all actions>", a1.getActions()); - } - - /** Any of AllPermission instances are equal and have the same hash code */ - public void testEquals() - { - AllPermission a1 = new AllPermission(); - AllPermission a2 = new AllPermission(); - assertTrue(a1.equals(a2)); - assertTrue(a1.hashCode() == a2.hashCode()); - assertFalse(a1.equals(null)); - assertFalse(a1.equals(new BasicPermission("hgf"){})); - } - - /** AllPermission implies any other permission */ - public void testImplies() - { - AllPermission a1 = new AllPermission(); - assertTrue(a1.implies(new AllPermission())); - assertTrue(a1.implies(new BasicPermission("2323"){})); - assertTrue(a1.implies(new UnresolvedPermission("2323", "", "", null))); - } - - /** newPermissionCollection() returns a new AllPermissionCollection on every invocation. */ - public void testCollection() - { - AllPermission a1 = new AllPermission(); - PermissionCollection pc1 = a1.newPermissionCollection(); - PermissionCollection pc2 = a1.newPermissionCollection(); -// assertTrue((pc1 instanceof AllPermissionCollection) && (pc2 instanceof AllPermissionCollection)); - assertNotSame(pc1, pc2); - } -} diff --git a/luni/src/test/java/tests/java/security/BasicPermissionTest.java b/luni/src/test/java/tests/java/security/BasicPermissionTest.java deleted file mode 100644 index 703a947..0000000 --- a/luni/src/test/java/tests/java/security/BasicPermissionTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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. - */ - -/** -* @author Alexey V. Varlamov -* @version $Revision$ -*/ - -package tests.java.security; - -import java.security.BasicPermission; -import java.security.PermissionCollection; - -import junit.framework.TestCase; - -/** - * Tests for <code>BasicPermission</code> - * - */ -public class BasicPermissionTest extends TestCase { - /** - * Check all constructors: an object is created with the specified valid name. - * If name equal null then NPE should be thrown. - * If name is empty then IAE should be thrown. - * Action is ignored. - */ - public void testCtor() - { - String name = "basic123*$%#"; - BasicPermission test = new BasicPermission(name){}; - assertEquals(name, test.getName()); - assertEquals("", test.getActions()); - test = new BasicPermission(name, "#$!#12435"){}; - assertEquals(name, test.getName()); - assertEquals("", test.getActions()); - try{ - new BasicPermission(null){}; - fail("NPE is not thrown"); - } - catch (NullPointerException ok){} - - try{ - new BasicPermission(null, "ds235"){}; - fail("NPE is not thrown"); - } - catch (NullPointerException ok){} - - try{ - new BasicPermission(""){}; - fail("IAE is not thrown"); - } - catch (IllegalArgumentException ok){} - try{ - new BasicPermission("", "ertre 3454"){}; - fail("IAE is not thrown"); - } - catch (IllegalArgumentException ok){} - } - - private final class BasicPermissionImpl extends BasicPermission - { - public BasicPermissionImpl(String name) - { - super(name); - } - } - - /** - * two BasicPermissions are equal if name and class are equal; - * equal permissions should have the same hash code - */ - public void testEquals() - { - BasicPermission b1 = new BasicPermissionImpl("abc"); - BasicPermission b2 = null; - assertTrue(b1.equals(b1)); - assertFalse(b1.equals(null)); - assertFalse(b1.equals(new Object())); - assertFalse(b1.equals("abc")); - assertTrue(b1.equals(b2 = new BasicPermissionImpl("abc"))); - assertTrue(b1.hashCode() == b2.hashCode()); - assertFalse(b1.equals(new BasicPermission("abc"){})); - assertFalse(b1.equals(new BasicPermissionImpl("abc.*"))); - } - - /** - * implies() should return true if a permission is equal to or is implied - * by wildcarded permission, false otherwise. - */ - public void testImplies() - { - BasicPermission b1 = new BasicPermissionImpl("a.b.c"); - assertTrue(b1.implies(b1)); - assertTrue(b1.implies(new BasicPermissionImpl("a.b.c"))); - assertFalse(b1.implies(new BasicPermissionImpl("a.b.c.*"))); - assertFalse(b1.implies(new BasicPermission("a.b.c"){})); - assertTrue(new BasicPermissionImpl("a.b.*").implies(b1)); - assertTrue(new BasicPermissionImpl("a.*").implies(b1)); - assertTrue(new BasicPermissionImpl("*").implies(b1)); - assertFalse(new BasicPermissionImpl("a.b*").implies(b1)); - assertFalse(new BasicPermissionImpl("a.b.c.*").implies(b1)); - assertTrue(new BasicPermissionImpl("1.*").implies(new BasicPermissionImpl("1.234.*"))); - assertTrue(new BasicPermissionImpl("*").implies(new BasicPermissionImpl("*"))); - } - - /** - * newPermissionCollection() should return new BasicPermissionCollection on every invocation - */ - public void testCollection() - { - BasicPermission b1 = new BasicPermissionImpl("a.b.c"); - PermissionCollection pc1 = b1.newPermissionCollection(); - PermissionCollection pc2 = b1.newPermissionCollection(); -// assertTrue((pc1 instanceof BasicPermissionCollection) && (pc2 instanceof BasicPermissionCollection)); - assertNotSame(pc1, pc2); - } -} diff --git a/luni/src/test/java/tests/security/AccessControllerTest.java b/luni/src/test/java/tests/security/AccessControllerTest.java deleted file mode 100644 index e031b5e..0000000 --- a/luni/src/test/java/tests/security/AccessControllerTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed 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 tests.security; - -import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.BasicPermission; -import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.PrivilegedAction; -import java.security.ProtectionDomain; - -import junit.framework.TestCase; - -public class AccessControllerTest extends TestCase { - - private static void setProtectionDomain(Class<?> c, ProtectionDomain pd){ - Field fields[] = Class.class.getDeclaredFields(); - for(Field f : fields){ - if("pd".equals(f.getName())){ - f.setAccessible(true); - try { - f.set(c, pd); - } catch (IllegalArgumentException e) { - fail("Protection domain could not be set"); - } catch (IllegalAccessException e) { - fail("Protection domain could not be set"); - } - break; - } - } - } - - SecurityManager old; - TestPermission p; - CodeSource codeSource; - PermissionCollection c0, c1, c2; - - @Override - protected void setUp() throws Exception { - old = System.getSecurityManager(); - codeSource = null; - p = new TestPermission(); - c0 = p.newPermissionCollection(); - c1 = p.newPermissionCollection(); - c2 = p.newPermissionCollection(); - super.setUp(); - } - - public void test_do_privileged2() { - // add TestPermission to T0, T1, T2 - c0.add(p); - c1.add(p); - c2.add(p); - setProtectionDomain(T0.class, new ProtectionDomain(codeSource, c0)); - setProtectionDomain(T1.class, new ProtectionDomain(codeSource, c1)); - setProtectionDomain(T2.class, new ProtectionDomain(codeSource, c2)); - } - - static class T0 { - static String f0(){ - return T1.f1(); - } - static String f0_priv(){ - return T1.f1_priv(); - } - } - - static class T1 { - static String f1(){ - return T2.f2(); - } - static String f1_priv(){ - return AccessController.doPrivileged( - new PrivilegedAction<String>(){ - public String run() { - return T2.f2(); - } - } - ); - } - } - - static class T2 { - static String f2(){ - SecurityManager s = System.getSecurityManager(); - assertNotNull(s); - s.checkPermission(new TestPermission()); - return "ok"; - } - } - - static class TestPermission extends BasicPermission { - private static final long serialVersionUID = 1L; - - public TestPermission(){ super("TestPermission"); } - - @Override - public boolean implies(Permission permission) { - return permission instanceof TestPermission; - } - } - -} diff --git a/luni/src/test/resources/PolicyTest.txt b/luni/src/test/resources/PolicyTest.txt deleted file mode 100644 index b765919..0000000 --- a/luni/src/test/resources/PolicyTest.txt +++ /dev/null @@ -1,3 +0,0 @@ -grant codeBase "file:${test.bin.dir}" { - permission java.security.SecurityPermission "codeBaseForPolicyTest"; -}; diff --git a/luni/src/test/resources/serialization/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.golden.ser b/luni/src/test/resources/serialization/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.golden.ser Binary files differdeleted file mode 100644 index f4cdced..0000000 --- a/luni/src/test/resources/serialization/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.golden.ser +++ /dev/null diff --git a/luni/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser b/luni/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser Binary files differdeleted file mode 100755 index 931ee3f..0000000 --- a/luni/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser +++ /dev/null diff --git a/luni/src/test/resources/serialization/tests/api/java/util/PropertyPermissionTest.golden.ser b/luni/src/test/resources/serialization/tests/api/java/util/PropertyPermissionTest.golden.ser Binary files differdeleted file mode 100644 index ffa3060..0000000 --- a/luni/src/test/resources/serialization/tests/api/java/util/PropertyPermissionTest.golden.ser +++ /dev/null |