diff options
author | Brian Carlstrom <bdc@google.com> | 2011-06-22 10:58:53 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2011-06-22 10:58:53 -0700 |
commit | 5b53d279675709a4beb54974c72e257c1262da2c (patch) | |
tree | c27be4c52b6782844ccdd5dae0e88884d23b073b | |
parent | ea551a82e41d6b0318af79de5db12416dfa7479c (diff) | |
parent | 660d4da8ff5dcb1f0bd2dcec2d18dc9f0ed901c0 (diff) | |
download | apache-harmony-jb-dev.tar.gz |
Merge remote branch 'goog/dalvik-dev' into dalvik-dev-to-masterandroid-sdk-adt_r20android-sdk-adt_r16.0.1android-sdk-4.0.3_r1android-sdk-4.0.3-tools_r1android-cts-verifier-4.0_r1android-cts-verifier-4.0.3_r1android-cts-4.1_r4android-cts-4.1_r2android-cts-4.1_r1android-cts-4.0_r1android-cts-4.0.3_r2android-cts-4.0.3_r1android-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1android-4.0.4_r2.1android-4.0.4_r2android-4.0.4_r1.2android-4.0.4_r1.1android-4.0.4_r1android-4.0.3_r1.1android-4.0.3_r1android-4.0.2_r1android-4.0.1_r1.2android-4.0.1_r1.1android-4.0.1_r1tools_r20jb-releasejb-mr0-releasejb-devics-plus-aospics-mr1-releaseics-mr1ics-mr0-releaseics-mr0ics-factoryrom-2-release
203 files changed, 463 insertions, 10458 deletions
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/Pack200Test.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/Pack200Test.java deleted file mode 100644 index a3b5b19..0000000 --- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/Pack200Test.java +++ /dev/null @@ -1,37 +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.archive.tests.java.util.jar; - -import java.util.jar.Pack200; -import java.util.jar.Pack200.Packer; -import java.util.jar.Pack200.Unpacker; - -import junit.framework.TestCase; - -public class Pack200Test extends TestCase { - - public void testPacker() { - Packer packer = Pack200.newPacker(); - assertEquals("org.apache.harmony.pack200.Pack200PackerAdapter", packer.getClass().getName()); - } - - public void testUnpacker() { - Unpacker unpacker = Pack200.newUnpacker(); - assertEquals("org.apache.harmony.unpack200.Pack200UnpackerAdapter", unpacker.getClass().getName()); - } - -} diff --git a/auth/src/test/java/common/javax/security/auth/AuthPermissionTest.java b/auth/src/test/java/common/javax/security/auth/AuthPermissionTest.java deleted file mode 100644 index a261b0b..0000000 --- a/auth/src/test/java/common/javax/security/auth/AuthPermissionTest.java +++ /dev/null @@ -1,95 +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 Maxim V. Makarov -*/ - -package javax.security.auth; - -import junit.framework.TestCase; - -/** - * Tests AuthPermission class - */ -public class AuthPermissionTest extends TestCase { - - private AuthPermission ap; - private AuthPermission ap1; - - - @Override - protected void setUp() throws Exception { - ap = new AuthPermission("name"); - ap1 = new AuthPermission("createLoginContext"); - } - - /** - * Constructor for AuthPermissionTest. - * - * @param name - */ - public AuthPermissionTest(String name) { - super(name); - } - - /** - * The target name "createLoginContext" is deprecated - * and it should be replaced by "createLoginContext.*" - */ - public void testConstructor_01() { - assertEquals("createLoginContext.*",ap1.getName()); - } - - /** - * Checks that target name is correct - */ - public void testConstructor_02() { - assertEquals("name",ap.getName()); - } - - /** - * Target name should not be null - */ - public void testConstructor_03() { - try { - ap = new AuthPermission(null); - fail("no expected NPE"); - } catch (NullPointerException e) {} - } - - /** - * Action should be ignored - */ - public void testConstructor_04() { - try { - ap = new AuthPermission("name", null); - ap = new AuthPermission("name", "read"); - } catch (NullPointerException e) { - fail("action is not ignored"); - } - } - - /** - * the target name "createLoginContext.{name}" is correct - */ - public void testConstructor_05() { - ap1 = new AuthPermission("createLoginContext.name"); - assertEquals("createLoginContext.name",ap1.getName()); - } - -} diff --git a/auth/src/test/java/common/javax/security/auth/PolicyTest.java b/auth/src/test/java/common/javax/security/auth/PolicyTest.java deleted file mode 100644 index b0b9c32..0000000 --- a/auth/src/test/java/common/javax/security/auth/PolicyTest.java +++ /dev/null @@ -1,303 +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 -*/ - -package javax.security.auth; - -import java.io.FilePermission; -import java.net.URL; -import java.security.AllPermission; -import java.security.CodeSigner; -import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Security; -import java.security.cert.Certificate; -import java.util.Enumeration; -import junit.framework.TestCase; -import org.apache.harmony.auth.tests.support.TestUtils; -import tests.support.resource.Support_Resources; - -/** - * Tests Policy class - */ -@SuppressWarnings("deprecation") -public class PolicyTest extends TestCase { - - public static class TestProvider extends Policy { - @Override - public PermissionCollection getPermissions(Subject subject, CodeSource cs) { - return null; - } - - @Override - public void refresh() { - } - } - - public static class FakePolicy { - // This is not policy class - } - /** - * Tests loading of a default provider, both valid and invalid class - * references. - */ - public void testGetPolicy_LoadDefaultProvider() { - Policy oldPolicy = null; - try { - oldPolicy = Policy.getPolicy(); - } catch (Throwable ignore) { - } - String POLICY_PROVIDER = "auth.policy.provider"; - String oldProvider = Security.getProperty(POLICY_PROVIDER); - try { - Security.setProperty(POLICY_PROVIDER, TestProvider.class.getName()); - Policy.setPolicy(null); - Policy p = Policy.getPolicy(); - assertNotNull(p); - assertEquals(TestProvider.class.getName(), p.getClass().getName()); - - // absent class - Security.setProperty(POLICY_PROVIDER, "a.b.c.D"); - Policy.setPolicy(null); - try { - p = Policy.getPolicy(); - fail("No SecurityException on failed provider"); - } catch (SecurityException ok) { - } - - // not a policy class - Security.setProperty(POLICY_PROVIDER, FakePolicy.class.getName()); - Policy.setPolicy(null); - try { - p = Policy.getPolicy(); - fail("No expected SecurityException"); - } catch (SecurityException ok) { - } - } finally { - TestUtils.setSystemProperty(POLICY_PROVIDER, oldProvider); - Policy.setPolicy(oldPolicy); - } - } - - // - // - // - // - // - - static String inputFile1 = Support_Resources - .getAbsoluteResourcePath("auth_policy1.txt"); - - static String inputFile2 = Support_Resources - .getAbsoluteResourcePath("auth_policy2.txt"); - - private static final String POLICY_PROP = "java.security.auth.policy"; - - public void test_GetPermissions() throws Exception { - - PermissionCollection c; - Permission per; - Subject subject; - - CodeSource source; - - String oldProp = System.getProperty(POLICY_PROP); - try { - System.setProperty(POLICY_PROP, inputFile1); - - Policy p = Policy.getPolicy(); - p.refresh(); - - // - // Both parameters are null - // - - c = p.getPermissions(null, null); - assertFalse("Read only for empty", c.isReadOnly()); - assertFalse("Elements for empty", c.elements().hasMoreElements()); - - // - // Subject parameter is provided (CodeBase is not important) - // - // Principal javax.security.auth.MyPrincipal "duke" - // - - // no principals at all - subject = new Subject(); - c = p.getPermissions(subject, null); - assertFalse("Elements: ", c.elements().hasMoreElements()); - - // different name "kuke" not "duke" - subject.getPrincipals().add(new MyPrincipal("kuke")); - c = p.getPermissions(subject, null); - assertFalse("Elements: ", c.elements().hasMoreElements()); - - // different class with required principal's name - subject.getPrincipals().add(new OtherPrincipal("duke")); - c = p.getPermissions(subject, null); - assertFalse("Elements: ", c.elements().hasMoreElements()); - - // subclass with required principal's name - subject.getPrincipals().add(new FakePrincipal("duke")); - c = p.getPermissions(subject, null); - assertFalse("Elements: ", c.elements().hasMoreElements()); - - // add required principal's name - subject.getPrincipals().add(new MyPrincipal("duke")); - - Enumeration<Permission> e = p.getPermissions(subject, null).elements(); - - per = e.nextElement(); - assertFalse("Elements: ", e.hasMoreElements()); - assertEquals("Permission: ", per, new FilePermission("/home/duke", - "read, write")); - - // check: CodeBase is not important - source = new CodeSource(new URL("http://dummy.xxx"), - (Certificate[]) null); - c = p.getPermissions(subject, source); - assertTrue("Elements: ", c.elements().hasMoreElements()); - - source = new CodeSource(new URL("http://dummy.xxx"), - (CodeSigner[]) null); - c = p.getPermissions(subject, source); - assertTrue("Elements: ", c.elements().hasMoreElements()); - - // - // Subject and CodeBase parameter are provided - // - // Principal javax.security.auth.MyPrincipal "dummy" - // CodeBase "http://dummy.xxx" - // - source = new CodeSource(new URL("http://dummy.xxx"), - (Certificate[]) null); - subject = new Subject(); - subject.getPrincipals().add(new MyPrincipal("dummy")); - - e = p.getPermissions(subject, source).elements(); - per = e.nextElement(); - assertFalse("Elements: ", e.hasMoreElements()); - assertEquals("Permission: ", per, new RuntimePermission( - "createClassLoader")); - - // reset subject : no principals at all - subject = new Subject(); - c = p.getPermissions(subject, source); - assertFalse("Elements: ", c.elements().hasMoreElements()); - - // different name "kuke" not "dummy" - subject.getPrincipals().add(new MyPrincipal("kuke")); - c = p.getPermissions(subject, null); - assertFalse("Elements: ", c.elements().hasMoreElements()); - - // different class with required principal's name - subject.getPrincipals().add(new OtherPrincipal("dummy")); - c = p.getPermissions(subject, null); - assertFalse("Elements: ", c.elements().hasMoreElements()); - - // - // Principal javax.security.auth.MyPrincipal "my" - // Principal javax.security.auth.OtherPrincipal "other" - // - subject = new Subject(); - subject.getPrincipals().add(new MyPrincipal("my")); - c = p.getPermissions(subject, null); - assertFalse("Elements: ", c.elements().hasMoreElements()); - - subject.getPrincipals().add(new OtherPrincipal("other")); - e = p.getPermissions(subject, null).elements(); - per = e.nextElement(); - assertFalse("Elements: ", e.hasMoreElements()); - assertEquals("Permission: ", per, new AllPermission()); - - // - // Principal javax.security.auth.MyPrincipal "bunny" - // - subject = new Subject(); - subject.getPrincipals().add(new MyPrincipal("bunny")); - - e = p.getPermissions(subject, null).elements(); - - Permission[] get = new Permission[2]; - get[0] = e.nextElement(); - get[1] = e.nextElement(); - assertFalse("Elements: ", e.hasMoreElements()); - - Permission[] set = new Permission[2]; - set[0] = new FilePermission("/home/bunny", "read, write"); - set[1] = new RuntimePermission("stopThread"); - - if (get[0].equals(set[0])) { - assertEquals("Permission: ", set[1], get[1]); - } else { - assertEquals("Permission: ", set[0], get[1]); - assertEquals("Permission: ", set[1], get[0]); - } - - } finally { - TestUtils.setSystemProperty(POLICY_PROP, oldProp); - } - } - - public void test_Refresh() { - - Permission per; - Subject subject; - Enumeration<?> e; - - String oldProp = System.getProperty(POLICY_PROP); - try { - // - // first policy file to be read - // - System.setProperty(POLICY_PROP, inputFile1); - - Policy p = Policy.getPolicy(); - p.refresh(); - - subject = new Subject(); - subject.getPrincipals().add(new MyPrincipal("duke")); - - e = p.getPermissions(subject, null).elements(); - - per = (Permission) e.nextElement(); - assertFalse("Elements: ", e.hasMoreElements()); - assertEquals("Permission: ", per, new FilePermission("/home/duke", - "read, write")); - - // - // second policy file to be read - // - System.setProperty(POLICY_PROP, inputFile2); - - p.refresh(); - - e = p.getPermissions(subject, null).elements(); - - per = (Permission) e.nextElement(); - assertFalse("Elements: ", e.hasMoreElements()); - assertEquals("Permission: ", per, new RuntimePermission( - "createClassLoader")); - } finally { - TestUtils.setSystemProperty(POLICY_PROP, oldProp); - } - } -} diff --git a/auth/src/test/java/common/javax/security/auth/PrivateCredentialPermissionTest.java b/auth/src/test/java/common/javax/security/auth/PrivateCredentialPermissionTest.java deleted file mode 100644 index 9845ec5..0000000 --- a/auth/src/test/java/common/javax/security/auth/PrivateCredentialPermissionTest.java +++ /dev/null @@ -1,919 +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 Maxim V. Makarov -*/ - -package javax.security.auth; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.security.Principal; -import java.util.HashSet; - -import junit.framework.TestCase; - - -/** - * Tests PrivateCredentialPermission class implementation. - */ -public class PrivateCredentialPermissionTest extends TestCase { - - private PrivateCredentialPermission p_that; - - private PrivateCredentialPermission p_this; - - String s_that; - - String s_this; - - /** - * Constructor for PrivateCredentialPermissionTest. - * - * @param name - */ - public PrivateCredentialPermissionTest(String name) { - super(name); - } - - /** - * [C1 P1 "duke"] implies [C1 P1 "duke" P2 "nuke"]. - */ - public final void testImplies_01() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.b.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.implies(p_that)); - assertTrue(p_this.implies(p_this)); - } - - /** - * [C1 P1 "nuke"] implies [C1 P1 "duke" P2 "nuke"]. - */ - public final void testImplies_02() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.c.Principal \"nuke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.implies(p_that)); - - } - - /** - * [* P1 "duke"] implies [C1 P1 "duke"] - */ - public final void testImplies_03() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "* a.b.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.implies(p_that)); - - } - - /** - * [C1P1 "duke"] implies [C1 P1 "*"] - */ - public final void testImplies_04() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.c.Principal \"*\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.implies(p_that)); - - } - - /** - * [C1 P1 "duke" P2 "nuke"] implies [C1 * "*"] - */ - public final void testImplies_05() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential * \"*\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.implies(p_that)); - - } - - /** - * [C1 P1 "duke" P2 "nuke"] implies [C1 P1 "duke" P2 "nuke" P3 "duke"] - */ - public final void testImplies_06() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\" a.d.Principal \"duke\""; - s_this = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.implies(p_that)); - - } - - /** - * [C2 P1 "duke" ] does not imply [C1 P1 "duke" P2 "nuke" ] - */ - public final void testImplies_07() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.c.Credential a.b.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - } - - /** - * [C1 P3 "duke" ] does not imply [C1 P1 "duke" P2 "nuke" ] - */ - public final void testImplies_08() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.d.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - } - - /** - * [C1 P1 "nuke" ] does not imply [C1 P1 "duke" P3 "nuke" ] - */ - public final void testImplies_09() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.b.Principal \"nuke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - - } - - /** - * [C1 P1 "nuke" P2 "buke"] does not imply [C1 P1 "duke" P2 "nuke" ] - */ - public final void testImplies_10() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"buke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - p_this.implies(p_that); - assertFalse(p_this.implies(p_that)); - - } - - /** - * [C1 P1 "nuke" P2 "nuke" P3 "buke"] does not imply [C1 P1 "duke" P2 "nuke" P3 "kuke"] - */ - public final void testImplies_110() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\" a.d.Principal \"kuke\""; - s_this = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\" a.d.Principal \"buke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - } - - /** - * [C1 P1 "duke" P2 "buke"] does not imply [C1 P1 "*" ] - */ - public final void testImplies_11() { - s_that = "a.b.Credential a.b.Principal \"*\""; - s_this = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"buke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - - } - - /** - * [C1 P2 "*"] does not imply [C1 P1 "*" ] - */ - public final void testImplies_12() { - s_that = "a.b.Credential a.b.Principal \"*\""; - s_this = "a.b.Credential a.c.Principal \"*\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - - } - - /** - * [* P3 "duke"] does not imply [C1 P1 "duke" P2 "nuke"] - */ - public final void testImplies_13() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "* a.d.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - } - - /** - * [* P2 "buke"] does not imply [C1 P1 "duke" P2 "nuke"] - */ - public final void testImplies_14() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "* a.c.Principal \"buke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - } - - /** - * [C1 P1 "buke"] does not imply [C1 P1 "*"] - */ - public final void testImplies_15() { - s_that = "a.b.Credential a.b.Principal \"*\""; - s_this = "a.b.Credential a.b.Principal \"nuke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - } - - /** - * [C1 * "*"] does not imply [C1 P1 "duke" P2 "nuke"] - */ - public final void testImplies_16() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential * \"*\" a.b.Principal \"nuke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.implies(p_that)); - } - - /** - * [C1 a.c* "nuke"] not implies [C1 P1 "duke" a.c.P2 "nuke"] - */ - public final void testImplies_17() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.c.* \"nuke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - //try { - assertFalse(p_this.implies(p_that)); - //} catch (AssertionFailedError e){ - // fail("It seems to me this test should be pass, so \"principalClass\"" + - // " should be has a name like 'a.b.*'"); - //} - } - - /** - * A permission is not an instance of PrivateCredentialPermission - */ - public final void testImplies_18() { - AuthPermission p_this = new AuthPermission("name", "read"); - s_that = "a.b.Credential a.c.* \"nuke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - assertFalse(p_that.implies(p_this)); - assertFalse(p_that.implies(null)); - } - - /** - * Create a correct ctor - * - * @throws IllegalArgumentException - */ - public final void testPCP_01() throws IllegalArgumentException { - p_this = new PrivateCredentialPermission( - "a.b.Credential a.b.Principal \"duke\" a.b.Principal \"nuke\"", - "read"); - } - - /** - * Create a incorrect ctor without string of Principal class and Principal name, - * expected IAE - */ - public final void testPCP_02() { - try { - p_this = new PrivateCredentialPermission("a.b.Credential", "read"); - fail("new PrivateCredentialPermission('a.b.Credential', 'read') should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Create a incorrect ctor without string of Principal name, - * expected IAE - */ - public final void testPCP_03() { - try { - p_this = new PrivateCredentialPermission( - "a.b.Credential a.b.Principal", "read"); - fail("new PrivateCredentialPermission('a.b.Credential a.b.Principal', 'read') should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Create a incorrect ctor without string of Principal class, - * expected IAE - */ - public final void testPCP_04() { - try { - p_this = new PrivateCredentialPermission( - "a.b.Credential \"duke\" a.b.Principal \"nuke\"", "read"); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Create a incorrect ctor. Principal Class can not be a wildcard (*) - * value if Principal Name is not a wildcard (*) value, - * expected IAE - */ - public final void testPCP_05() { - - try { - p_this = new PrivateCredentialPermission( - "a.b.Credential * \"nuke\"", "read"); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - /** - * "Action must be "read" only, - * expected IAE - */ - public final void testPCP_06() throws IllegalArgumentException { - - try { - p_this = new PrivateCredentialPermission( - "a.b.Credential a.b.Principal \"nuke\"", "write"); - fail("Action can be \"read\" only, IllegalArgumentException should be thrown"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Principal name must be enveloped by quotes, - * expected IAE - */ - public final void testPCP_07() throws IllegalArgumentException { - - try { - p_this = new PrivateCredentialPermission( - "a.b.Credential a.b.Principal a.c.Principal", "read"); - fail("IllegalArgumentException should be thrown"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Principal name must be enveloped by quotes, - * expected IAE - */ - public final void testPCP_08() throws IllegalArgumentException { - - try { - p_this = new PrivateCredentialPermission( - "a.b.Credential a.b.Principal \"duke\" a.c.Principal", - "read"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Principal name must be enveloped by quotes, - * expected IAE - */ - public final void testPCP_09() throws IllegalArgumentException { - - try { - p_this = new PrivateCredentialPermission( - "a.b.Credential a.b.Principal duke\"", "read"); - fail("should be throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Principal name must be enveloped by quotes, - * expected IAE - */ - public final void testPCP_10() throws IllegalArgumentException { - - try { - p_this = new PrivateCredentialPermission( - "a.b.Credential a.b.Principal \"duke", "read"); - fail("should be throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Create a ctor. Code to support a principal class as a.c.* - * - * @throws IllegalArgumentException - */ - public final void testPCP_11() throws IllegalArgumentException { - p_this = new PrivateCredentialPermission( - "a.b.Credential a.b.* \"duke\"", "read"); - } - - /** - * Create a ctor. [* * "*"] - * - * @throws IllegalArgumentException - */ - public final void testPCP_12() throws IllegalArgumentException { - p_this = new PrivateCredentialPermission("* * \"*\"", "read"); - } - - /** - * a target name should not be empty - * @throws IllegalArgumentException - */ - public final void testPCP_13() throws IllegalArgumentException { - try { - p_this = new PrivateCredentialPermission(new String(), "read"); - fail("should be throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - /** - * a target name should not be null - */ - public final void testPCP_14() { - try { - new PrivateCredentialPermission(null, "read"); - fail("should be throw NullPointerException"); - } catch (NullPointerException e) { - } - } - - /** - * test empty principal/name pairs - */ - public final void testPCP_15() { - try { - p_this = new PrivateCredentialPermission("java.lang.Object", "read"); - fail("new PrivateCredentialPermission('java.lang.Object', 'read') should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - /** - * [C1 P1 "nuke" P2 "nuke"] equals [C1 P1 "duke" P2 "nuke"] - */ - public final void testEquals_01() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.equals(p_that)); - assertTrue(p_this.equals(p_this)); - assertEquals(p_this.hashCode(), p_that.hashCode()); - } - - /** - * two permissions are equal if the order of the Principals in - * the respective target names is not relevant. - */ - public final void testEquals_02() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.c.Principal \"nuke\" a.b.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.equals(p_that)); - assertEquals(p_this.hashCode(), p_that.hashCode()); - } - - /** - * two permissions are not equal even if its have the same credential class - * and a different number of principals. - */ - public final void testEquals_03() { - - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.b.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.equals(p_that)); - } - - /** - * two permissions are not equal if either of them has not the same - * credential class, principal class and principal name - */ - public final void testEquals_04() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.c.Credential a.d.Principal \"buke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.equals(p_that)); - } - - /** - * two permissions are not equal if either of them has not the same - * principal class and principal name - */ - public final void testEquals_05() { - s_that = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - s_this = "a.b.Credential a.d.Principal \"buke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.equals(p_that)); - } - - /** - * [C1 P1 "duke"] equals [C1 P1 "duke"] and - * hashCode of them equals too. - */ - public final void testEquals_06() { - s_that = "a.b.Credential a.b.Principal \"duke\""; - s_this = "a.b.Credential a.b.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.equals(p_that)); - assertTrue(p_that.equals(p_this)); - assertEquals(p_this.hashCode(), p_that.hashCode()); - } - - /** - * two permissions are not equal if either of them has not the same principal name - */ - public final void testEquals_07() { - s_that = "a.b.Credential a.b.Principal \"duke\""; - s_this = "a.b.Credential a.b.Principal \"buke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.equals(p_that)); - } - - /** - * Verifies that a permission object is equal to itself - */ - public final void testEquals_08() { - s_this = "a.b.Credential a.b.Principal \"buke\""; - p_this = new PrivateCredentialPermission(s_this, "read"); - assertTrue(p_this.equals(p_this)); - } - - /** - * [C1 P1 "duke"] does not equal NULL - */ - public final void testEquals_09() { - s_this = "a.b.Credential a.b.Principal \"buke\""; - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.equals(null)); - AuthPermission other = new AuthPermission("some"); - assertFalse(p_this.implies(other)); - } - - /** - * two permissions are not equals if either of them has not the same credential class - */ - public final void testEquals_10() { - s_that = "a.b.Credential a.b.Principal \"duke\""; - s_this = "a.c.Credential a.b.Principal \"duke\""; - p_that = new PrivateCredentialPermission(s_that, "read"); - p_this = new PrivateCredentialPermission(s_this, "read"); - assertFalse(p_this.equals(p_that)); - assertFalse(p_that.equals(p_this)); - } - - /** - * the method newPermissionCollection() always returns null, - * the method getActions() always returns "read" and - * the method getCredentialClass() returns the name of the CredentialClass. - */ - public final void testGetCredentialClassAndGetAction() { - s_this = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - p_this = new PrivateCredentialPermission(s_this, "read"); - assertEquals("read", p_this.getActions()); - assertEquals("a.b.Credential", p_this.getCredentialClass()); - assertNull(p_this.newPermissionCollection()); - } - - /** - * Returns the set of principals which to represent like array[x][y] - * Implementation specific. - */ - public final void testGetPrincipals_01() { - s_this = "a.b.Credential a.b.Principal \"duke\" a.c.Principal \"nuke\""; - p_this = new PrivateCredentialPermission(s_this, "read"); - String p[][] = p_this.getPrincipals(); - assertEquals("a.b.Principal", p[0][0]); - assertEquals("duke", p[0][1]); - assertEquals("a.c.Principal", p[1][0]); - assertEquals("nuke", p[1][1]); - } - - /** - * the same as the method testGetPrincipals_01() - */ - public final void testGetPrincipals_02() { - s_this = "a.b.Credential a.d.Principal \"buke\" a.b.Principal \"duke\" a.c.Principal \"nuke\""; - p_this = new PrivateCredentialPermission(s_this, "read"); - String p[][] = p_this.getPrincipals(); - assertEquals("a.d.Principal", p[0][0]); - assertEquals("buke", p[0][1]); - assertEquals("a.b.Principal", p[1][0]); - assertEquals("duke", p[1][1]); - assertEquals("a.c.Principal", p[2][0]); - assertEquals("nuke", p[2][1]); - } - - public final void testCtor() { - - class MyPrincipal implements Principal { - String name; - - MyPrincipal(String name) { - this.name = name; - } - - public String getName() { - return name; - } - } - - MyPrincipal mp = new MyPrincipal("duke"); - MyPrincipal mp1 = new MyPrincipal("nuke"); - HashSet<Principal> hash = new HashSet<Principal>(); - hash.add(mp); - hash.add(mp1); - - PrivateCredentialPermission p1 = new PrivateCredentialPermission( - "java.lang.Object", hash); - - PrivateCredentialPermission p2 = new PrivateCredentialPermission( - "java.lang.Object " + MyPrincipal.class.getName() + " \"duke\"", - "read"); - assertFalse(p1.implies(p2)); - assertTrue(p2.implies(p1)); - - PrivateCredentialPermission p3 = new PrivateCredentialPermission( - "java.lang.Object", new HashSet<Principal>()); - - PrivateCredentialPermission p4 = new PrivateCredentialPermission( - "java.lang.Object * \"*\"", "read"); - - assertTrue(p4.implies(p3)); - } - - public final void testDuplicates() { - - // string contains duplicate entries: b "c" - PrivateCredentialPermission p = new PrivateCredentialPermission( - "a b \"c\" b \"c\"", "read"); - - assertEquals("Size", p.getPrincipals().length, 1); - } - - public final void testImmutability() { - PrivateCredentialPermission p = new PrivateCredentialPermission( - "a b \"c\"", "read"); - - assertTrue("Array reference", p.getPrincipals() != p.getPrincipals()); - } - - public final void testWhiteSpaces() { - - String[] illegalTargetNames = new String[] { "a\nb \"c\"", // \n - delimiter - "a\tb \"c\"", // \t - delimiter - "a\rb \"c\"", // \r - delimiter - "a b\n\"c\"", // \n - delimiter - "a b\t\"c\"", // \t - delimiter - "a b\r\"c\"", // \r - delimiter - "a b \"c\"", // two spaces between credential and principal - "a b \"c\"" // two spaces between principal class and name - }; - - for (String element : illegalTargetNames) { - try { - new PrivateCredentialPermission(element, "read"); - fail("No expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - // principal name has a space - PrivateCredentialPermission p = new PrivateCredentialPermission( - "a b \"c c\"", "read"); - - assertEquals("Principal name:", "c c", p.getPrincipals()[0][1]); - } - - public final void testSerialization_Wildcard() throws Exception { - - PrivateCredentialPermission all = new PrivateCredentialPermission( - "* * \"*\"", "read"); - PrivateCredentialPermission p = new PrivateCredentialPermission( - "a b \"c\"", "read"); - - assertTrue(all.implies(p)); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ObjectOutputStream oOut = new ObjectOutputStream(out); - - oOut.writeObject(all); - oOut.flush(); - oOut.close(); - - ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - ObjectInputStream oIn = new ObjectInputStream(in); - - PrivateCredentialPermission newAll = (PrivateCredentialPermission) oIn - .readObject(); - - assertTrue("New implies", newAll.implies(p)); - assertEquals("Equals", all, newAll); - } - - public final void testSerialization_Golden() throws Exception { - - new PrivateCredentialPermission("a b \"c\" d \"e\"", "read"); - - ByteArrayInputStream in = new ByteArrayInputStream(gForm); - ObjectInputStream sIn = new ObjectInputStream(in); - - PrivateCredentialPermission p = (PrivateCredentialPermission) sIn - .readObject(); - - assertEquals("CredentialClass ", "a", p.getCredentialClass()); - - String[][] principals = p.getPrincipals(); - assertEquals("Size:", 1, principals.length); - assertEquals("PrincipalClass:", "b", principals[0][0]); - assertEquals("PrincipalName:", "c", principals[0][1]); - } - - public final void testSerialization_Self() throws Exception { - - ByteArrayInputStream in = new ByteArrayInputStream(selfForm); - ObjectInputStream sIn = new ObjectInputStream(in); - - PrivateCredentialPermission p = (PrivateCredentialPermission) sIn - .readObject(); - - assertEquals("CredentialClass ", "a", p.getCredentialClass()); - - String[][] principals = p.getPrincipals(); - assertEquals("Size:", 1, principals.length); - assertEquals("PrincipalClass:", "b", principals[0][0]); - assertEquals("PrincipalName:", "c", principals[0][1]); - } - - // Golden: PrivateCredentialPermission("a b \"c\"","read"); - // generated using public API - public static final byte[] gForm = new byte[] { (byte) 0xac, (byte) 0xed, - (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, - (byte) 0x2f, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, - (byte) 0x78, (byte) 0x2e, (byte) 0x73, (byte) 0x65, (byte) 0x63, - (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79, - (byte) 0x2e, (byte) 0x61, (byte) 0x75, (byte) 0x74, (byte) 0x68, - (byte) 0x2e, (byte) 0x50, (byte) 0x72, (byte) 0x69, (byte) 0x76, - (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x43, (byte) 0x72, - (byte) 0x65, (byte) 0x64, (byte) 0x65, (byte) 0x6e, (byte) 0x74, - (byte) 0x69, (byte) 0x61, (byte) 0x6c, (byte) 0x50, (byte) 0x65, - (byte) 0x72, (byte) 0x6d, (byte) 0x69, (byte) 0x73, (byte) 0x73, - (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x55, - (byte) 0xdc, (byte) 0x77, (byte) 0x7b, (byte) 0x50, (byte) 0x7f, - (byte) 0x4c, (byte) 0x02, (byte) 0x00, (byte) 0x03, (byte) 0x5a, - (byte) 0x00, (byte) 0x07, (byte) 0x74, (byte) 0x65, (byte) 0x73, - (byte) 0x74, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x4c, - (byte) 0x00, (byte) 0x0f, (byte) 0x63, (byte) 0x72, (byte) 0x65, - (byte) 0x64, (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x69, - (byte) 0x61, (byte) 0x6c, (byte) 0x43, (byte) 0x6c, (byte) 0x61, - (byte) 0x73, (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x12, - (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, - (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, - (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, - (byte) 0x6e, (byte) 0x67, (byte) 0x3b, (byte) 0x4c, (byte) 0x00, - (byte) 0x0a, (byte) 0x70, (byte) 0x72, (byte) 0x69, (byte) 0x6e, - (byte) 0x63, (byte) 0x69, (byte) 0x70, (byte) 0x61, (byte) 0x6c, - (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x0f, (byte) 0x4c, - (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, - (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2f, - (byte) 0x53, (byte) 0x65, (byte) 0x74, (byte) 0x3b, (byte) 0x78, - (byte) 0x72, (byte) 0x00, (byte) 0x18, (byte) 0x6a, (byte) 0x61, - (byte) 0x76, (byte) 0x61, (byte) 0x2e, (byte) 0x73, (byte) 0x65, - (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74, - (byte) 0x79, (byte) 0x2e, (byte) 0x50, (byte) 0x65, (byte) 0x72, - (byte) 0x6d, (byte) 0x69, (byte) 0x73, (byte) 0x73, (byte) 0x69, - (byte) 0x6f, (byte) 0x6e, (byte) 0xb1, (byte) 0xc6, (byte) 0xe1, - (byte) 0x3f, (byte) 0x28, (byte) 0x57, (byte) 0x51, (byte) 0x7e, - (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x4c, (byte) 0x00, - (byte) 0x04, (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65, - (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c, (byte) 0x6a, - (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, - (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53, - (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, - (byte) 0x3b, (byte) 0x78, (byte) 0x70, (byte) 0x74, (byte) 0x00, - (byte) 0x07, (byte) 0x61, (byte) 0x20, (byte) 0x62, (byte) 0x20, - (byte) 0x22, (byte) 0x63, (byte) 0x22, (byte) 0x00, (byte) 0x74, - (byte) 0x00, (byte) 0x01, (byte) 0x61, (byte) 0x70 }; - - // Self generated: PrivateCredentialPermission("a b \"c\"","read"); - // Note: Set principals = new LinkedHashSet() - // generated using public API - public static final byte[] selfForm = { (byte) 0xac, (byte) 0xed, - (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, - (byte) 0x2f, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, - (byte) 0x78, (byte) 0x2e, (byte) 0x73, (byte) 0x65, (byte) 0x63, - (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79, - (byte) 0x2e, (byte) 0x61, (byte) 0x75, (byte) 0x74, (byte) 0x68, - (byte) 0x2e, (byte) 0x50, (byte) 0x72, (byte) 0x69, (byte) 0x76, - (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x43, (byte) 0x72, - (byte) 0x65, (byte) 0x64, (byte) 0x65, (byte) 0x6e, (byte) 0x74, - (byte) 0x69, (byte) 0x61, (byte) 0x6c, (byte) 0x50, (byte) 0x65, - (byte) 0x72, (byte) 0x6d, (byte) 0x69, (byte) 0x73, (byte) 0x73, - (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x55, - (byte) 0xdc, (byte) 0x77, (byte) 0x7b, (byte) 0x50, (byte) 0x7f, - (byte) 0x4c, (byte) 0x02, (byte) 0x00, (byte) 0x03, (byte) 0x5a, - (byte) 0x00, (byte) 0x07, (byte) 0x74, (byte) 0x65, (byte) 0x73, - (byte) 0x74, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x4c, - (byte) 0x00, (byte) 0x0f, (byte) 0x63, (byte) 0x72, (byte) 0x65, - (byte) 0x64, (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x69, - (byte) 0x61, (byte) 0x6c, (byte) 0x43, (byte) 0x6c, (byte) 0x61, - (byte) 0x73, (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x12, - (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, - (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, - (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, - (byte) 0x6e, (byte) 0x67, (byte) 0x3b, (byte) 0x4c, (byte) 0x00, - (byte) 0x0a, (byte) 0x70, (byte) 0x72, (byte) 0x69, (byte) 0x6e, - (byte) 0x63, (byte) 0x69, (byte) 0x70, (byte) 0x61, (byte) 0x6c, - (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x0f, (byte) 0x4c, - (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, - (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2f, - (byte) 0x53, (byte) 0x65, (byte) 0x74, (byte) 0x3b, (byte) 0x78, - (byte) 0x72, (byte) 0x00, (byte) 0x18, (byte) 0x6a, (byte) 0x61, - (byte) 0x76, (byte) 0x61, (byte) 0x2e, (byte) 0x73, (byte) 0x65, - (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x69, (byte) 0x74, - (byte) 0x79, (byte) 0x2e, (byte) 0x50, (byte) 0x65, (byte) 0x72, - (byte) 0x6d, (byte) 0x69, (byte) 0x73, (byte) 0x73, (byte) 0x69, - (byte) 0x6f, (byte) 0x6e, (byte) 0xb1, (byte) 0xc6, (byte) 0xe1, - (byte) 0x3f, (byte) 0x28, (byte) 0x57, (byte) 0x51, (byte) 0x7e, - (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x4c, (byte) 0x00, - (byte) 0x04, (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65, - (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c, (byte) 0x6a, - (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, - (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53, - (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, - (byte) 0x3b, (byte) 0x78, (byte) 0x70, (byte) 0x74, (byte) 0x00, - (byte) 0x07, (byte) 0x61, (byte) 0x20, (byte) 0x62, (byte) 0x20, - (byte) 0x22, (byte) 0x63, (byte) 0x22, (byte) 0x00, (byte) 0x74, - (byte) 0x00, (byte) 0x01, (byte) 0x61, (byte) 0x73, (byte) 0x72, - (byte) 0x00, (byte) 0x17, (byte) 0x6a, (byte) 0x61, (byte) 0x76, - (byte) 0x61, (byte) 0x2e, (byte) 0x75, (byte) 0x74, (byte) 0x69, - (byte) 0x6c, (byte) 0x2e, (byte) 0x4c, (byte) 0x69, (byte) 0x6e, - (byte) 0x6b, (byte) 0x65, (byte) 0x64, (byte) 0x48, (byte) 0x61, - (byte) 0x73, (byte) 0x68, (byte) 0x53, (byte) 0x65, (byte) 0x74, - (byte) 0xd8, (byte) 0x6c, (byte) 0xd7, (byte) 0x5a, (byte) 0x95, - (byte) 0xdd, (byte) 0x2a, (byte) 0x1e, (byte) 0x02, (byte) 0x00, - (byte) 0x00, (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x11, - (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2e, - (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2e, - (byte) 0x48, (byte) 0x61, (byte) 0x73, (byte) 0x68, (byte) 0x53, - (byte) 0x65, (byte) 0x74, (byte) 0xba, (byte) 0x44, (byte) 0x85, - (byte) 0x95, (byte) 0x96, (byte) 0xb8, (byte) 0xb7, (byte) 0x34, - (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70, - (byte) 0x77, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x00, - (byte) 0x10, (byte) 0x3f, (byte) 0x40, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x73, - (byte) 0x72, (byte) 0x00, (byte) 0x39, (byte) 0x6a, (byte) 0x61, - (byte) 0x76, (byte) 0x61, (byte) 0x78, (byte) 0x2e, (byte) 0x73, - (byte) 0x65, (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x69, - (byte) 0x74, (byte) 0x79, (byte) 0x2e, (byte) 0x61, (byte) 0x75, - (byte) 0x74, (byte) 0x68, (byte) 0x2e, (byte) 0x50, (byte) 0x72, - (byte) 0x69, (byte) 0x76, (byte) 0x61, (byte) 0x74, (byte) 0x65, - (byte) 0x43, (byte) 0x72, (byte) 0x65, (byte) 0x64, (byte) 0x65, - (byte) 0x6e, (byte) 0x74, (byte) 0x69, (byte) 0x61, (byte) 0x6c, - (byte) 0x50, (byte) 0x65, (byte) 0x72, (byte) 0x6d, (byte) 0x69, - (byte) 0x73, (byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, - (byte) 0x24, (byte) 0x43, (byte) 0x72, (byte) 0x65, (byte) 0x64, - (byte) 0x4f, (byte) 0x77, (byte) 0x6e, (byte) 0x65, (byte) 0x72, - (byte) 0xb2, (byte) 0x2e, (byte) 0x56, (byte) 0x16, (byte) 0xb9, - (byte) 0x03, (byte) 0x74, (byte) 0x36, (byte) 0x02, (byte) 0x00, - (byte) 0x02, (byte) 0x4c, (byte) 0x00, (byte) 0x0e, (byte) 0x70, - (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x63, (byte) 0x69, - (byte) 0x70, (byte) 0x61, (byte) 0x6c, (byte) 0x43, (byte) 0x6c, - (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x74, (byte) 0x00, - (byte) 0x12, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, - (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, - (byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, - (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x3b, (byte) 0x4c, - (byte) 0x00, (byte) 0x0d, (byte) 0x70, (byte) 0x72, (byte) 0x69, - (byte) 0x6e, (byte) 0x63, (byte) 0x69, (byte) 0x70, (byte) 0x61, - (byte) 0x6c, (byte) 0x4e, (byte) 0x61, (byte) 0x6d, (byte) 0x65, - (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c, (byte) 0x6a, - (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, - (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53, - (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, - (byte) 0x3b, (byte) 0x78, (byte) 0x70, (byte) 0x74, (byte) 0x00, - (byte) 0x01, (byte) 0x62, (byte) 0x74, (byte) 0x00, (byte) 0x01, - (byte) 0x63, (byte) 0x78 }; -} diff --git a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/DelegationPermissionTest.java b/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/DelegationPermissionTest.java deleted file mode 100644 index 4a6345b..0000000 --- a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/DelegationPermissionTest.java +++ /dev/null @@ -1,219 +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 Maxim V. Makarov -*/ - -package org.apache.harmony.auth.tests.javax.security.auth.kerberos; - -import java.security.AllPermission; -import java.security.BasicPermission; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.SecurityPermission; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.NoSuchElementException; - -import javax.security.auth.kerberos.DelegationPermission; -import javax.security.auth.kerberos.ServicePermission; - -import junit.framework.TestCase; - - -/** - * Tests DelegationPermission class implementation. - */ -public class DelegationPermissionTest extends TestCase { - - /** - * testing of a correct ctor - */ - public void testCtor() { - String name1 = "\"aaa.bbb.com@CCC.COM\" \"ccc.ddd.com@DDD.COM\""; - DelegationPermission dp; - dp = new DelegationPermission(name1); - assertEquals(name1, dp.getName()); - assertEquals("",dp.getActions()); - dp = new DelegationPermission(name1, "action"); - assertEquals("",dp.getActions()); - dp = new DelegationPermission(name1, null); - assertEquals("",dp.getActions()); - } - - /** - * testing of a incorrect ctor - */ - public void testFailCtor() { - try { - new DelegationPermission(null); - fail("no expected NPE"); - } catch(NullPointerException e){ - } - try { - new DelegationPermission(""); - fail("no expected IAE"); - } catch(IllegalArgumentException e){ - } - try { - new DelegationPermission("\"aaa.bbb.com\" ccc.ddd.com"); - fail("Target name must be enveloped by quotes"); - } catch(IllegalArgumentException e){ - } - try { - new DelegationPermission("\"aaa.bbb.com\" ccc.ddd.com\""); - fail("Target name must be enveloped by quotes"); - } catch(IllegalArgumentException e){ - } - try { - new DelegationPermission("\"aaa.bbb.com\" \"ccc.ddd.com"); - fail("Target name must be enveloped by quotes"); - } catch(IllegalArgumentException e){ - } - try { - new DelegationPermission("\" \" \" \""); - //TODO: fail("Target name is empty"); - }catch(IllegalArgumentException e){ - } - try { - new DelegationPermission("\"\""); - fail("Target name is incorrect"); - } catch(IllegalArgumentException e){ - } - try { - new DelegationPermission("\"aaa.bbb.com\" \"\""); - fail("service principal is empty"); - } catch(IllegalArgumentException e){ - } - try { - new DelegationPermission("\"\" \"aaa.bbb.com\""); - fail("subordinate service principal is empty"); - } catch(IllegalArgumentException e){ - } - - } - - public void testFailCtor_2() { - try { - new DelegationPermission("\"AAA\""); - fail("target name should be specifies a pair of kerberos service principals"); - } catch (IllegalArgumentException e) { - } - } - - // testing of the equals method - @SuppressWarnings("serial") - public void testEquals() { - DelegationPermission dp1 = new DelegationPermission("\"AAA\" \"BBB\""); - DelegationPermission dp2 = new DelegationPermission("\"AAA\" \"BBB\""); - - assertTrue(dp1.equals(dp1)); - assertFalse(dp1.equals(new DelegationPermission("\"aaa\" \"bbb\""))); - assertTrue(dp2.equals(dp1)); - assertTrue(dp1.equals(dp2)); - assertTrue(dp1.hashCode() == dp2.hashCode()); - assertFalse(dp1.equals(new BasicPermission("\"AAA\""){})); - } - // testing of the implies method - public void testImplies() { - DelegationPermission dp1 = new DelegationPermission("\"AAA\" \"BBB\""); - DelegationPermission dp2 = new DelegationPermission("\"BBB\" \"AAA\""); - assertFalse(dp1.implies(dp2)); - assertFalse(dp2.implies(dp1)); - assertTrue(dp1.implies(dp1)); - assertFalse(dp1.implies(new ServicePermission("aaa", "accept"))); - assertFalse(dp1.implies(null)); - } - - // testing of the KrbDelegationPermissionCollection - - - // testing of the add collection method - public void testAddCollection() { - DelegationPermission dp = new DelegationPermission("\"AAA\" \"BBB\""); - PermissionCollection pc1 = dp.newPermissionCollection(); - PermissionCollection pc2 = dp.newPermissionCollection(); - assertNotSame(pc1, pc2); - pc1.add(new DelegationPermission("\"BBB\" \"AAA\"")); - try { - pc1.add(new SecurityPermission("aaa")); - fail("should not add non DelegationPermission"); - } catch (IllegalArgumentException e){ - } - try { - pc1.add(null); - fail("permission is null"); - } catch (IllegalArgumentException e) { - } - pc1.setReadOnly(); - try { - pc1.add(new DelegationPermission("\"CCC\" \"AAA\"")); - fail("read-only flag is ignored"); - } catch (SecurityException e) { - } - } - - public void testImpliesCollection(){ - - Permission ap = new AllPermission(); - Permission p = new DelegationPermission("\"AAA\" \"BBB\""); - PermissionCollection pc = p.newPermissionCollection(); - assertFalse(pc.implies(ap)); - assertFalse(pc.implies(p)); - pc.add(p); - assertTrue(pc.implies(p)); - assertFalse(pc.implies(null)); - DelegationPermission dp1 = new DelegationPermission("\"AAA\" \"BBB\""); - assertTrue(dp1.implies(dp1)); - DelegationPermission dp2 = new DelegationPermission("\"BBB\" \"AAA\""); - assertFalse(dp1.implies(dp2)); - assertFalse(dp1.implies(null)); - assertFalse(dp1.implies(new ServicePermission("aaa", "accept"))); - } - - public void testElements() throws Exception { - Permission p = new DelegationPermission("\"AAA\" \"BBB\""); - PermissionCollection pc = p.newPermissionCollection(); - try { - pc.elements().nextElement(); - fail("expected NoSuchElementException"); - } catch (NoSuchElementException e) { - } - Enumeration<Permission> en = pc.elements(); - assertNotNull(en); - assertFalse(en.hasMoreElements()); - Permission sp1 = new DelegationPermission("\"DDD\" \"BBB\""); - Permission sp2 = new DelegationPermission("\"CCC\" \"BBB\""); - pc.add(sp1); - en = pc.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(sp1.equals(en.nextElement())); - assertFalse(en.hasMoreElements()); - pc.add(sp2); - en = pc.elements(); - Collection<Permission> c = new ArrayList<Permission>(); - while (en.hasMoreElements()) { - c.add(en.nextElement()); - } - assertFalse(en.hasMoreElements()); - assertEquals(2, c.size()); - assertTrue(c.contains(sp1) && c.contains(sp2)); - } - - } diff --git a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/ServicePermissionTest.java b/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/ServicePermissionTest.java deleted file mode 100644 index d7e575e..0000000 --- a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/ServicePermissionTest.java +++ /dev/null @@ -1,304 +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 Maxim V. Makarov -*/ - -package org.apache.harmony.auth.tests.javax.security.auth.kerberos; - -import java.security.AllPermission; -import java.security.Permission; -import java.security.PermissionCollection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.NoSuchElementException; - -import javax.security.auth.kerberos.DelegationPermission; -import javax.security.auth.kerberos.ServicePermission; - -import junit.framework.TestCase; - -/** - * Tests ServicePermission class implementation. - */ -public class ServicePermissionTest extends TestCase { - - - /** - * @tests javax.security.auth.kerberos.ServicePermission#ServicePermission( - * java.lang.String,java.lang.String) - */ - public void testCtor() { - ServicePermission sp = new ServicePermission("krbtgt/AAA.COM@BBB.COM", "initiate"); - ServicePermission sp1 = new ServicePermission("host/AAA.COM@BBB.COM", "accept"); - assertEquals("krbtgt/AAA.COM@BBB.COM",sp.getName()); - assertEquals("initiate",sp.getActions()); - assertEquals("host/AAA.COM@BBB.COM",sp1.getName()); - assertEquals("accept",sp1.getActions()); - ServicePermission sp2 = new ServicePermission("host/AAA.COM@BBB.COM", "accept, initiate"); - assertEquals("initiate,accept", sp2.getActions()); - - try { - // Regression for HARMONY-769 - // checks exception order: action parameter is verified first - new ServicePermission(null, "initiate accept"); - fail("No expected IllegalArgumentException"); - } catch(IllegalArgumentException e){ - } - } - - public void testFailedCtor() { - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "read"); - fail("incorrect actions"); - } catch(IllegalArgumentException e){ - } - - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", ""); - fail("actions is empty"); - } catch(IllegalArgumentException e){ - } - - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", null); - fail("actions is null"); - } catch(NullPointerException e){ - } catch(IllegalArgumentException e){} - - try { - new ServicePermission(null, "accept"); - fail("permission is null"); - } catch(NullPointerException e){ - } - try { - new ServicePermission("", "accept"); - //TODO: fail("No expected IAE"); // - } catch(IllegalArgumentException e){} - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "accept, read"); - fail("Incorrect actions"); - } catch(IllegalArgumentException e){ - } - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "initiate, read"); - fail("Incorrect actions"); - } catch(IllegalArgumentException e){ - } - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "read, initiate "); - fail("Incorrect actions"); - } catch(Exception e){ - } - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "read, accept "); - fail("Incorrect actions"); - }catch(IllegalArgumentException e){ - } - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", ", accept "); - //TODO: fail("No expected IAE"); - } catch(IllegalArgumentException e){ - } - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "initiate, accept, read"); - fail("Incorrect actions"); - } catch(IllegalArgumentException e){ - } - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "initiate, read, accept"); - fail("Incorrect actions"); - } catch(IllegalArgumentException e){ - } - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "initiate, accept, accept"); - //TODO: fail("Incorrect actions"); - } catch(IllegalArgumentException e){ - } - try { - new ServicePermission("krbtgt/AAA.COM@BBB.COM", "initiate accept"); - fail("Incorrect actions"); - } catch(IllegalArgumentException e){ - } - } - - public void testEquals() { - ServicePermission sp = new ServicePermission("host/AAA.COM@BBB.COM", "accept"); - ServicePermission sp1 = new ServicePermission("host/AAA.COM@BBB.COM", "initiate"); - ServicePermission sp2 = new ServicePermission("host/AAA.COM@BBB.COM", "initiate, accept"); - assertTrue(sp.equals(sp)); - assertTrue(sp.hashCode() == sp.hashCode()); - assertFalse(sp.equals(sp1)); - assertFalse(sp.hashCode() == sp1.hashCode()); - assertFalse(sp.equals(sp2)); - assertFalse(sp1.equals(sp2)); - assertTrue(sp2.equals(sp2)); - assertFalse(sp.equals(new DelegationPermission("\"AAA\" \"BBB\"", "action"))); - assertFalse(sp.equals(null)); - } - - public void testImplies() { - ServicePermission sp1; - ServicePermission sp = new ServicePermission("host/AAA.COM@BBB.COM", "accept"); - sp1 = new ServicePermission("*", "initiate, accept"); - assertTrue(sp.implies(sp)); - assertFalse(sp.implies(sp1)); - assertTrue(sp1.implies(sp)); - assertTrue(sp1.implies(sp1)); - sp1 = new ServicePermission("*", "accept"); - assertTrue(sp1.implies(sp)); - sp1 = new ServicePermission("*", "initiate"); - assertFalse(sp1.implies(sp)); - assertFalse(sp1.implies(new ServicePermission("*", "accept, initiate"))); - assertTrue(new ServicePermission("host/AAA.COM@BBB.COM", "initiate, accept").implies(sp)); - assertTrue(new ServicePermission("host/AAA.COM@BBB.COM", "accept").implies(sp)); - assertFalse(new ServicePermission("host/AAA.COM@BBB.COM", "initiate").implies(sp)); - assertFalse(sp1.implies(null)); - } - - // tests for KrbServicePermissionCollection - - public void testAddCollection() { - ServicePermission sp = new ServicePermission("AAA", "accept"); - PermissionCollection pc = sp.newPermissionCollection(); - - try { - pc.add(new DelegationPermission("\"aaa\" \"bbb\"")); - fail("Should not add non DelegationPermission"); - } catch (IllegalArgumentException e) { - } - - try { - pc.add(null); - fail("no expected IAE"); - } catch (IllegalArgumentException e) { - } - - pc.add(new ServicePermission("AAA", "accept")); - pc.add(new ServicePermission("BBB", "accept, initiate")); - - pc.setReadOnly(); - try { - pc.add(sp); - fail("read-only flag is ignored"); - } catch (SecurityException e) { - } - } - - public void testImpliesCollection(){ - - Permission ap = new AllPermission(); - Permission p = new ServicePermission("AAA", "accept"); - PermissionCollection pc = p.newPermissionCollection(); - assertFalse(pc.implies(ap)); - assertFalse(pc.implies(p)); - pc.add(p); - assertTrue(pc.implies(p)); - assertFalse(pc.implies(null)); - assertFalse(pc.implies(new ServicePermission("BBB", "initiate"))); - assertFalse(pc.implies(new ServicePermission("CCC", "accept"))); - pc.add(new ServicePermission("*", "accept, initiate")); - assertTrue(pc.implies(new ServicePermission("*", "accept"))); - assertTrue(pc.implies(new ServicePermission("*", "initiate"))); - assertTrue(pc.implies(new ServicePermission("BBB", "initiate"))); - assertTrue(pc.implies(new ServicePermission("CCC", "accept"))); - - - } - - public void testElements() { - Permission p = new ServicePermission("AAA", "accept"); - PermissionCollection pc = p.newPermissionCollection(); - - try { - pc.elements().nextElement(); - fail("expected NoSuchElementException"); - } catch (NoSuchElementException e) { - } - - Enumeration<Permission> en = pc.elements(); - assertNotNull(en); - assertFalse(en.hasMoreElements()); - - Permission sp1 = new ServicePermission("BBB", "accept, initiate"); - Permission sp2 = new ServicePermission("CCC", "initiate"); - Permission sp3 = new ServicePermission("DDD", "accept"); - - pc.add(sp1); - en = pc.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(sp1.equals(en.nextElement())); - assertFalse(en.hasMoreElements()); - pc.add(sp2); - pc.add(sp3); - en = pc.elements(); - Collection<Permission> c = new ArrayList<Permission>(); - while (en.hasMoreElements()) - { - c.add(en.nextElement()); - } - assertFalse(en.hasMoreElements()); - assertEquals(3, c.size()); - assertTrue(c.contains(sp1) && c.contains(sp2) && c.contains(sp3)); - } - - public void testActions() { - - String[] validActions = new String[] { " accept ", // spaces - "accept,ACCEPT,accept", - "initiate,INITIATE,initiate", - "\naccept,accept,accept\n", // leading & trailing \n - "\naccept,accept,accept\n", // leading & trailing \n - "\naccept,initiate,accept\n", // leading & trailing \n - "\ninitiate\n,\raccept,initiate\n", // leading & trailing \n - "\naccept\n", // leading & trailing \n - "\naccept\n", // leading & trailing \n - "\taccept\t", // leading & trailing \t - "\taccept\t", // leading & trailing \r - "accept , initiate", // spaces - "accept\n,\ninitiate", // \n - "accept\t,\tinitiate", // \t - "accept\r,\rinitiate", // \r - "AccepT", // first & last upper case - "InitiatE", // first & last upper case - "Accept, initiatE" // first & last upper case - }; - - for (String element : validActions) { - new ServicePermission("*", element); - } - - String[] invalidActions = new String[] { "accept initiate", // space - "accept\ninitiate", // delimiter \n - "accept\tinitiate", // delimiter \t - "accept\tinitiate", // delimiter \r - "accept, ", // ',' - "accept,", // ',' - " ,accept" // ',' - }; - for (String element : invalidActions) { - try { - new ServicePermission("*", element); - fail("No expected IllegalArgumentException for action: " - + element); - } catch (IllegalArgumentException e) { - } - } - } -} diff --git a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.java b/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.java deleted file mode 100644 index 4304219..0000000 --- a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.java +++ /dev/null @@ -1,41 +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 Maxim V. Makarov -*/ - -package org.apache.harmony.auth.tests.javax.security.auth.kerberos.serialization; - -import javax.security.auth.kerberos.DelegationPermission; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - - -/** - * Serialization test for DelegationPermission class - */ -public class DelegationPermissionTest extends SerializationTest { - - @Override - protected Object[] getData() { - return new Object[] { - new DelegationPermission("\"AAA\" \"BBB\"", "action"), - new DelegationPermission("\"AAA\" \"CCC\"") }; - } -}
\ No newline at end of file diff --git a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.java b/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.java deleted file mode 100644 index cc5445a..0000000 --- a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.java +++ /dev/null @@ -1,50 +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 Maxim V. Makarov -*/ - -package org.apache.harmony.auth.tests.javax.security.auth.kerberos.serialization; - -import java.security.Permission; -import java.security.PermissionCollection; -import javax.security.auth.kerberos.DelegationPermission; -import org.apache.harmony.testframework.serialization.SerializationTest; - - - -/** - * Serialization test for KrbDelegationPermissionCollection class - */ -public class KrbDelegationPermissionCollectionTest extends SerializationTest { - - @Override - protected Object[] getData() { - Permission p1 = new DelegationPermission("\"AAA\" \"BBB\"", "action"); - Permission p2 = new DelegationPermission("\"AAA\" \"CCC\""); - Permission p3 = new DelegationPermission("\"BBB\" \"CCC\""); - PermissionCollection pc1 = p1.newPermissionCollection(); - PermissionCollection pc2 = p1.newPermissionCollection(); - pc2.add(p3); - PermissionCollection pc3 = p1.newPermissionCollection(); - pc3.add(p1); - pc3.add(p2); - pc3.add(p3); - return new Object[] { pc1, pc2, pc3 }; - } -} diff --git a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.java b/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.java deleted file mode 100644 index e2ce200..0000000 --- a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.java +++ /dev/null @@ -1,49 +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 Maxim V. Makarov -*/ - -package org.apache.harmony.auth.tests.javax.security.auth.kerberos.serialization; - -import java.security.Permission; -import java.security.PermissionCollection; -import javax.security.auth.kerberos.ServicePermission; -import org.apache.harmony.testframework.serialization.SerializationTest; - -/** - * Serialization test for KrbServicePermissionCollection class - */ -public class KrbServicePermissionCollectionTest extends SerializationTest { - - @Override - protected Object[] getData() { - Permission p1 = new ServicePermission("AAA", "accept"); - Permission p2 = new ServicePermission("BBB", "initiate"); - Permission p3 = new ServicePermission("CCC", "initiate, accept"); - PermissionCollection pc1 = p1.newPermissionCollection(); - PermissionCollection pc2 = p1.newPermissionCollection(); - pc2.add(p3); - PermissionCollection pc3 = p1.newPermissionCollection(); - pc3.add(p1); - pc3.add(p2); - pc3.add(p3); - return new Object[] { pc1, pc2, pc3 }; - } - -} diff --git a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.java b/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.java deleted file mode 100644 index ff6b515..0000000 --- a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.java +++ /dev/null @@ -1,41 +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 Maxim V. Makarov -*/ - -package org.apache.harmony.auth.tests.javax.security.auth.kerberos.serialization; - -import javax.security.auth.kerberos.ServicePermission; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - -/** - * Serialization test for ServicePermission class - */ -public class ServicePermissionTest extends SerializationTest { - - @Override - protected Object[] getData() { - return new Object[] { new ServicePermission("AAA", "accept"), - new ServicePermission("BBB", "initiate"), - new ServicePermission("CCC", "initiate, accept"), - new ServicePermission("CCC", "accept, initiate ") }; - } -}
\ No newline at end of file diff --git a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/serialization/AuthPermissionTest.java b/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/serialization/AuthPermissionTest.java deleted file mode 100644 index aa1261a..0000000 --- a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/serialization/AuthPermissionTest.java +++ /dev/null @@ -1,39 +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 Maxim V. Makarov -*/ - -package org.apache.harmony.auth.tests.javax.security.auth.serialization; - -import javax.security.auth.AuthPermission; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - -/** - * Serialization test for AuthPermission class - */ - -public class AuthPermissionTest extends SerializationTest { - - @Override - protected Object[] getData() { - return new Object[] {new AuthPermission("name", "read")}; - } -}
\ No newline at end of file diff --git a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/serialization/PrivateCredentialPermissionTest.java b/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/serialization/PrivateCredentialPermissionTest.java deleted file mode 100644 index effa17c..0000000 --- a/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/serialization/PrivateCredentialPermissionTest.java +++ /dev/null @@ -1,39 +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 Maxim V. Makarov -*/ - -package org.apache.harmony.auth.tests.javax.security.auth.serialization; - -import javax.security.auth.PrivateCredentialPermission; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - -/** - * Serialization test for PrivateCredentialPermission class - */ - -public class PrivateCredentialPermissionTest extends SerializationTest { - - @Override - protected Object[] getData() { - return new Object[] {new PrivateCredentialPermission("a.b.Cred a.c.Princ \"duke\"", "read")}; - } -}
\ No newline at end of file diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.golden.0.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index e01699c..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.golden.0.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.golden.1.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.golden.1.ser Binary files differdeleted file mode 100644 index 486a183..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/DelegationPermissionTest.golden.1.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.0.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.0.ser Binary files differdeleted file mode 100644 index 010e855..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.0.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.1.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.1.ser Binary files differdeleted file mode 100644 index 79ed054..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.1.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.2.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.2.ser Binary files differdeleted file mode 100644 index 12d7693..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbDelegationPermissionCollectionTest.golden.2.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.0.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.0.ser Binary files differdeleted file mode 100644 index 201c4b1..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.0.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.1.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.1.ser Binary files differdeleted file mode 100644 index 3457fd0..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.1.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.2.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.2.ser Binary files differdeleted file mode 100644 index ba251c3..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KrbServicePermissionCollectionTest.golden.2.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.0.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index eed9897..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.0.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.1.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.1.ser Binary files differdeleted file mode 100644 index 4a827d0..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.1.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.2.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.2.ser Binary files differdeleted file mode 100644 index ea7f1eb..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.2.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.3.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.3.ser Binary files differdeleted file mode 100644 index ea7f1eb..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ServicePermissionTest.golden.3.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/serialization/AuthPermissionTest.golden.0.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/serialization/AuthPermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index 61c29b0..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/serialization/AuthPermissionTest.golden.0.ser +++ /dev/null diff --git a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/serialization/PrivateCredentialPermissionTest.golden.0.ser b/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/serialization/PrivateCredentialPermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index f7f9c78..0000000 --- a/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/serialization/PrivateCredentialPermissionTest.golden.0.ser +++ /dev/null diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.java deleted file mode 100644 index aa8f7fa..0000000 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.java +++ /dev/null @@ -1,77 +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.logging.tests.java.util.logging; - -import java.util.logging.LoggingPermission; - -import junit.framework.TestCase; - -import org.apache.harmony.testframework.serialization.SerializationTest; - -public class LoggingPermissionTest extends TestCase { - - /** - * @tests serialization/deserialization compatibility. - */ - public void testSerializationSelf() throws Exception { - SerializationTest.verifySelf(new LoggingPermission("control", "")); - } - - /** - * @tests serialization/deserialization compatibility with RI. - */ - public void testSerializationCompatibility() throws Exception { - - SerializationTest.verifyGolden(this, new LoggingPermission("control", - "")); - } - - public void testLoggingPermission() { - try { - new LoggingPermission(null, null); - fail("should throw IllegalArgumentException"); - } catch (NullPointerException e) { - } - try { - new LoggingPermission("", null); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - try { - new LoggingPermission("bad name", null); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - try { - new LoggingPermission("Control", null); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - try { - new LoggingPermission("control", - "bad action"); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - - new LoggingPermission("control", ""); - - new LoggingPermission("control", null); - } - -} diff --git a/logging/src/test/resources/serialization/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.golden.ser b/logging/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/logging/src/test/resources/serialization/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.golden.ser +++ /dev/null diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java deleted file mode 100644 index 5b5a759..0000000 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java +++ /dev/null @@ -1,222 +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.luni.tests.java.io; - -import java.io.File; -import java.io.FilePermission; -import java.security.PermissionCollection; - -import junit.framework.TestCase; - -public class FilePermissionTest extends 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"); - - FilePermission readInSubdir = new FilePermission("-", "read"); - - /** - * @tests java.io.FilePermission#FilePermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_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()); - assertTrue( - "name given to the constructor did not correspond - constructor failed", - constructFile.getName() == "test constructor"); - - // 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 - } - } - - /** - * @tests java.io.FilePermission#getActions() - */ - public void test_getActions() { - assertEquals("getActions should have returned only read", "read", - readAllFiles.getActions()); - assertEquals("getActions should have returned all actions", - "read,write,execute,delete", allInCurrent.getActions()); - } - - /** - * @tests java.io.FilePermission#equals(java.lang.Object) - */ - public void test_equalsLjava_lang_Object() { - assertTrue( - "Should not returned false when two instance of FilePermission is equal", - readAllFiles.equals(alsoReadAllFiles)); - assertFalse( - "Should not returned true when two instance of FilePermission is not equal", - readInCurrent.equals(readInFile)); - } - - /** - * @tests java.io.FilePermission#implies(java.security.Permission) - */ - public void test_impliesLjava_security_Permission() { - assertFalse("Should not return true for non-subset of actions", readAllFiles - .implies(allInCurrent)); - assertFalse("Should not return true for non-subset of files", allInCurrent - .implies(readAllFiles)); - assertTrue("Should not return false for subset of actions", allInCurrent - .implies(readInCurrent)); - assertTrue("Should not return false for subset of files", readAllFiles - .implies(readInCurrent)); - assertTrue("Should not return false for subset of files and actions", - allInCurrent.implies(readInFile)); - assertTrue("Should not return false for equal FilePermissions", readAllFiles - .implies(alsoReadAllFiles)); - assertTrue("Should not return false for subdir self", readInSubdir.implies(readInSubdir)); - assertTrue("Should not return false for current self", readInCurrent.implies(readInCurrent)); - assertTrue("Should not return false for subdir", readInSubdir.implies(readInCurrent)); - - FilePermission fp13 = new FilePermission(File.separator, "read"); - FilePermission fp14 = new FilePermission(File.separator + "*", "read"); - assertFalse("/ should not imply /*", fp13.implies(fp14)); - fp14 = new FilePermission(File.separator + "-", "read"); - assertFalse("/ should not imply /-", fp13.implies(fp14)); - - FilePermission fp3 = new FilePermission("/bob/*".replace('/', - File.separatorChar), "read,write"); - FilePermission fp4 = new FilePermission("/bob/".replace('/', - File.separatorChar), "write"); - assertFalse("Should not return true for same dir using * and not *", fp3 - .implies(fp4)); - FilePermission fp5 = new FilePermission("/bob/file".replace('/', - File.separatorChar), "write"); - assertTrue("Should not return 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"); - assertFalse("Should not return true for same dir using not * and *", fp6 - .implies(fp7)); - assertTrue("Should not return 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("Should not return 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("Should not return false for same dir", fp10.implies(fp11)); - - FilePermission fp12 = new FilePermission("/*".replace('/', - File.separatorChar), "read,write"); - assertFalse("Should not return true for same dir using * and dir", fp12 - .implies(fp10)); - - // Regression for HARMONY-47 - char separator = File.separatorChar; - char nonSeparator = (separator == '/') ? '\\' : '/'; - - FilePermission fp1 = new FilePermission(nonSeparator + "*", "read"); - FilePermission fp2 = new FilePermission(separator + "a", "read"); - assertFalse("Assert 0: non-separator worked", fp1.implies(fp2)); - fp1 = new FilePermission(nonSeparator + "-", "read"); - assertFalse("Assert 1: non-separator worked", fp1.implies(fp2)); - } - - /** - * @tests java.io.FilePermission#newPermissionCollection() - */ - public void test_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("Should not return false for subset of files", collect - .implies(new FilePermission("*", "write"))); - assertTrue("Should not return false for subset of name and action", collect - .implies(new FilePermission(s + "tmp", "read"))); - assertTrue("Should not return false 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)); - } - - /** - * @tests java.io.FilePermission#hashCode() - */ - public void test_hashCode() { - 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/api/common/org/apache/harmony/luni/tests/java/io/SerializablePermissionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializablePermissionTest.java deleted file mode 100644 index 0589e9f..0000000 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializablePermissionTest.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 org.apache.harmony.luni.tests.java.io; - -import java.io.SerializablePermission; - -public class SerializablePermissionTest extends junit.framework.TestCase { - - /** - * @tests java.io.SerializablePermission#SerializablePermission(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // Test for method java.io.SerializablePermission(java.lang.String) - assertEquals("permission ill-formed", - "enableSubclassImplementation", new SerializablePermission( - "enableSubclassImplementation").getName()); - } - - /** - * @tests java.io.SerializablePermission#SerializablePermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.io.SerializablePermission(java.lang.String, - // java.lang.String) - assertEquals("permission ill-formed", - "enableSubclassImplementation", new SerializablePermission( - "enableSubclassImplementation", "").getName()); - } - - /** - * 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/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java index 952b403..308b0af 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java @@ -133,11 +133,6 @@ public class SerializationStressTest extends junit.framework.TestCase implements static final Set<String> SET = new HashSet<String>(Arrays.asList(new String[] { "one", "two", "three" })); - static final Permission PERM = new PropertyPermission("file.encoding", - "write"); - - static final PermissionCollection PERMCOL = PERM.newPermissionCollection(); - static final SortedSet<String> SORTSET = new TreeSet<String>(Arrays.asList(new String[] { "one", "two", "three" })); @@ -180,7 +175,6 @@ public class SerializationStressTest extends junit.framework.TestCase implements TREE.put("one", "1"); TREE.put("two", "2"); TREE.put("three", "3"); - PERMCOL.add(PERM); // To make sure they all use the same Calendar CALENDAR.setTimeZone(new SimpleTimeZone(0, "GMT")); CALENDAR.set(1999, Calendar.JUNE, 23, 15, 47, 13); diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest2.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest2.java index 362bf6f..5ee4353 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest2.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest2.java @@ -1055,66 +1055,6 @@ public class SerializationStressTest2 extends SerializationStressTest { } } - public void test_18_49_writeObject() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.lang.Object) - - Object objToSave = null; - Object objLoaded; - - try { - java.net.SocketPermission p = new java.net.SocketPermission( - "www.yahoo.com", "connect"); - objToSave = p; - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - assertTrue("SocketPermissions are not the same: " + p + "\t,\t" - + objLoaded, p.equals(objLoaded)); - - } catch (IOException e) { - fail("IOException serializing " + objToSave + " : " - + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type : " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - } - - public void test_18_50_writeObject() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.lang.Object) - - Object objToSave = null; - Object objLoaded; - - try { - java.net.SocketPermission p = new java.net.SocketPermission( - "www.yahoo.com", "ReSoLVe, ConNecT"); - objToSave = p; - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - assertTrue("SocketPermissions are not the same: " + p + "\t,\t" - + objLoaded, p.equals(objLoaded)); - - } catch (IOException e) { - fail("IOException serializing " + objToSave + " : " - + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type : " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - } - public void test_18_51_writeObject() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.lang.Object) diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest3.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest3.java index 3e71daa..f9ed99a 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest3.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest3.java @@ -1399,77 +1399,6 @@ public class SerializationStressTest3 extends SerializationStressTest { } } - public void test_18_117_writeObject() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.lang.Object) - - Object objToSave = null; - Object objLoaded; - - try { - objToSave = PERM; - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, PERM.equals(objLoaded)); - - } catch (IOException e) { - fail("IOException serializing " + objToSave + " : " - + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type : " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - } - - public void test_18_118_writeObject() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.lang.Object) - - Object objToSave = null; - Object objLoaded; - - try { - objToSave = PERMCOL; - Enumeration elementsBefore = PERMCOL.elements(); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - // Has to have worked - Enumeration elementsAfter = ((PermissionCollection) objLoaded) - .elements(); - boolean equals = true; - while (elementsBefore.hasMoreElements()) { - // To make sure elements are the same - Object oBefore = elementsBefore.nextElement(); - Object oAfter = elementsAfter.nextElement(); - equals &= oBefore.equals(oAfter); - - } - // To make sure sizes are the same - equals &= elementsBefore.hasMoreElements() == elementsAfter - .hasMoreElements(); - - assertTrue(MSG_TEST_FAILED + objToSave, equals); - - } catch (IOException e) { - fail("IOException serializing " + objToSave + " : " - + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type : " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - } - public void test_18_119_writeObject() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.lang.Object) diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest4.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest4.java index 3b6170d..947e2a1 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest4.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest4.java @@ -18,7 +18,6 @@ package org.apache.harmony.luni.tests.java.io; import java.io.File; -import java.io.FilePermission; import java.io.IOException; import java.io.Serializable; import java.lang.reflect.InvocationHandler; @@ -26,8 +25,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.net.URI; import java.net.URISyntaxException; -import java.security.AllPermission; -import java.security.PermissionCollection; import java.security.cert.Certificate; import java.text.DateFormat; import java.text.MessageFormat; @@ -87,59 +84,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } } - public void test_writeObject_PermissionCollection() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.PermissionCollection) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = null; - objToSave = new PermissionCollection() { - boolean added = false; - - public void add(java.security.Permission p1) { - added = true; - } - - public Enumeration elements() { - return (new Vector()).elements(); - } - - public boolean implies(java.security.Permission p1) { - return added; - } - - public boolean equals(Object obj) { - if (!(obj instanceof java.security.PermissionCollection)) - return false; - return implies(null) == ((PermissionCollection) obj) - .implies(null); - } - }; - - ((java.security.PermissionCollection) objToSave).add(null); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("IOException serializing " + objToSave + " : " - + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type : " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_Collections_EmptySet() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet) @@ -206,84 +150,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_BasicPermissionCollection() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.BasicPermissionCollection) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = (new RuntimePermission("test")) - .newPermissionCollection(); - ((java.security.PermissionCollection) objToSave) - .add(new RuntimePermission("test")); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - boolean equals; - Enumeration enum1 = ((java.security.PermissionCollection) objToSave) - .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) - .elements(); - - equals = true; - while (enum1.hasMoreElements() && equals) { - if (enum2.hasMoreElements()) - equals = enum1.nextElement().equals(enum2.nextElement()); - else - equals = false; - } - - if (equals) - equals = !enum2.hasMoreElements(); - assertTrue(MSG_TEST_FAILED + objToSave, equals); - } catch (IOException e) { - fail("IOException serializing " + objToSave + " : " - + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type : " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - - public void test_writeObject_UnresolvedPermission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.UnresolvedPermission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.security.UnresolvedPermission("type", "name", - "actions", null); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - boolean equals; - equals = objToSave.toString().equals(objLoaded.toString()); - assertTrue(MSG_TEST_FAILED + objToSave, equals); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_Character() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.lang.Character) @@ -431,55 +297,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_UnresolvedPermissionCollection() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.UnresolvedPermissionCollection) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = (new java.security.UnresolvedPermission("type", "name", - "actions", null)).newPermissionCollection(); - ((java.security.PermissionCollection) objToSave) - .add(new java.security.UnresolvedPermission("type", "name", - "actions", null)); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - boolean equals; - Enumeration enum1 = ((java.security.PermissionCollection) objToSave) - .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) - .elements(); - - equals = true; - while (enum1.hasMoreElements() && equals) { - if (enum2.hasMoreElements()) - equals = enum1.nextElement().toString().equals( - enum2.nextElement().toString()); - else - equals = false; - } - - if (equals) - equals = !enum2.hasMoreElements(); - assertTrue(MSG_TEST_FAILED + objToSave, equals); - } catch (IOException e) { - fail("IOException serializing " + objToSave + " : " - + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type : " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_SecureRandomSpi() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.security.SecureRandomSpi) @@ -670,36 +487,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_ReflectPermission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.lang.reflect.ReflectPermission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.lang.reflect.ReflectPermission( - "TestSerialization", "test"); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("IOException serializing " + objToSave + " : " - + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type : " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_StringBuffer() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.lang.StringBuffer) @@ -760,52 +547,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_AllPermissionCollection() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.AllPermissionCollection) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = (new java.security.AllPermission()) - .newPermissionCollection(); - ((java.security.PermissionCollection) objToSave) - .add(new java.security.AllPermission()); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - boolean equals; - Enumeration enum1 = ((java.security.PermissionCollection) objToSave) - .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) - .elements(); - - equals = true; - while (enum1.hasMoreElements() && equals) { - if (enum2.hasMoreElements()) - equals = enum1.nextElement().equals(enum2.nextElement()); - else - equals = false; - } - - if (equals) - equals = !enum2.hasMoreElements(); - assertTrue(MSG_TEST_FAILED + objToSave, equals); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_BitSet() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.BitSet) @@ -927,35 +668,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_SerializablePermission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.io.SerializablePermission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.io.SerializablePermission("TestSerialization", - "Test"); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_Properties() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.Properties) @@ -1001,38 +713,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - // TODO : requires working security implementation - // public void test_writeObject_BasicPermission() { - // // Test for method void - // // - // java.io.ObjectOutputStream.writeObject(tests.java.security.Test_BasicPermission.BasicPermissionSubclass) - // - // Object objToSave = null; - // Object objLoaded = null; - // - // try { - // objToSave = new - // tests.java.security.Test_BasicPermission.BasicPermissionSubclass( - // "TestSerialization"); - // if (DEBUG) - // System.out.println("Obj = " + objToSave); - // objLoaded = dumpAndReload(objToSave); - // - // // Has to have worked - // assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - // } catch (IOException e) { - // fail("Exception serializing " + objToSave + " : " - // + e.getMessage()); - // } catch (ClassNotFoundException e) { - // fail("ClassNotFoundException reading Object type : " + e.getMessage()); - // } catch (Error err) { - // System.out.println("Error when obj = " + objToSave); - // // err.printStackTrace(); - // throw err; - // } - // - // } - public void test_writeObject_Collections_UnmodifiableMap_UnmodifiableEntrySet() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableMap.UnmodifiableEntrySet) @@ -1273,34 +953,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_AllPermission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.AllPermission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.security.AllPermission(); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_Collections_ReverseComparator() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.Collections.ReverseComparator) @@ -1529,54 +1181,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_FilePermission_FilePermissionCollection() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.io.FilePermission.FilePermissionCollection) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = (new java.io.FilePermission("<<ALL FILES>>", "read")) - .newPermissionCollection(); - ((java.security.PermissionCollection) objToSave) - .add(new FilePermission("<<ALL FILES>>", "read")); - ((java.security.PermissionCollection) objToSave) - .add(new FilePermission("d:\\", "read")); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - boolean equals; - java.util.Enumeration enum1 = ((java.security.PermissionCollection) objToSave) - .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) - .elements(); - - equals = true; - while (enum1.hasMoreElements() && equals) { - if (enum2.hasMoreElements()) - equals = enum1.nextElement().equals(enum2.nextElement()); - else - equals = false; - } - - if (equals) - equals = !enum2.hasMoreElements(); - assertTrue(MSG_TEST_FAILED + objToSave, equals); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_SecureRandom() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.security.SecureRandom) @@ -1608,34 +1212,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_FilePermission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.io.FilePermission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.io.FilePermission("<<ALL FILES>>", "read"); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_InetAddress() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.net.InetAddress) @@ -1693,102 +1269,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_RuntimePermission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.lang.RuntimePermission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.lang.RuntimePermission("TestSerialization", - "Test"); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - - @SuppressWarnings("unchecked") - public void test_writeObject_Permissions() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.Permissions) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.security.Permissions(); - ((java.security.Permissions) objToSave).add(new AllPermission()); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - boolean equals; - Enumeration enum1 = ((java.security.PermissionCollection) objToSave) - .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) - .elements(); - java.util.Vector vec1 = new java.util.Vector(), vec2 = new java.util.Vector(); - - while (enum1.hasMoreElements()) - vec1.add(enum1.nextElement()); - while (enum2.hasMoreElements()) - vec2.add(enum2.nextElement()); - - equals = vec1.size() == vec2.size(); - if (equals) { - int length = vec1.size(); - Object[] perms1 = new Object[length], perms2 = new Object[length]; - for (int i = 0; i < length; ++i) { - perms1[i] = vec1.elementAt(i); - perms2[i] = vec2.elementAt(i); - } - - Comparator comparator = new Comparator() { - public int compare(Object o1, Object o2) { - return o1.toString().compareTo(o2.toString()); - } - - public boolean equals(Object o1, Object o2) { - return o1.toString().equals(o2.toString()); - } - }; - - Arrays.sort(perms1, comparator); - Arrays.sort(perms2, comparator); - - for (int i = 0; i < length && equals; ++i) - equals = perms1[i].equals(perms2[i]); - } - - assertTrue(MSG_TEST_FAILED + objToSave, equals); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_Date() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.Date) @@ -1846,82 +1326,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_SecurityPermission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.SecurityPermission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.security.SecurityPermission( - "TestSerialization", "Test"); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - - public void test_writeObject_SocketPermission_SocketPermissionCollection() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.net.SocketPermission.SocketPermissionCollection) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = (new java.net.SocketPermission("www.yahoo.com", - "connect")).newPermissionCollection(); - ((java.security.PermissionCollection) objToSave) - .add(new java.net.SocketPermission("www.yahoo.com", - "connect")); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - boolean equals; - Enumeration enum1 = ((java.security.PermissionCollection) objToSave) - .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) - .elements(); - - equals = true; - while (enum1.hasMoreElements() && equals) { - if (enum2.hasMoreElements()) - equals = enum1.nextElement().equals(enum2.nextElement()); - else - equals = false; - } - - if (equals) - equals = !enum2.hasMoreElements(); - assertTrue(MSG_TEST_FAILED + objToSave, equals); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_Stack() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.Stack) @@ -1992,33 +1396,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_NetPermission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.net.NetPermission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = new java.net.NetPermission("TestSerialization", "Test"); - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - } - public void test_writeObject_AttributedCharacterIterator_Attribute() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.text.AttributedCharacterIterator.Attribute) @@ -2074,38 +1451,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_CodeSource() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.CodeSource) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = null; - objToSave = new java.security.CodeSource(new java.net.URL( - "http://localhost/a.txt"), - (Certificate[])null); - - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_Collections_SynchronizedCollection() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.Collections.SynchronizedCollection) @@ -2144,54 +1489,6 @@ public class SerializationStressTest4 extends SerializationStressTest { } - public void test_writeObject_Permission() { - // Test for method void - // java.io.ObjectOutputStream.writeObject(java.security.Permission) - - Object objToSave = null; - Object objLoaded = null; - - try { - objToSave = null; - objToSave = new java.security.Permission("test") { - public boolean equals(Object p1) { - if (!(p1 instanceof java.security.Permission)) - return false; - return getName().equals( - ((java.security.Permission) p1).getName()); - } - - public int hashCode() { - return 0; - } - - public String getActions() { - return null; - } - - public boolean implies(java.security.Permission p1) { - return false; - } - }; - if (DEBUG) - System.out.println("Obj = " + objToSave); - objLoaded = dumpAndReload(objToSave); - - // Has to have worked - assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); - } catch (IOException e) { - fail("Exception serializing " + objToSave + " : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException reading Object type: " - + e.getMessage()); - } catch (Error err) { - System.out.println("Error when obj = " + objToSave); - // err.printStackTrace(); - throw err; - } - - } - public void test_writeObject_Random() { // Test for method void // java.io.ObjectOutputStream.writeObject(java.util.Random) diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java index 61dab9a..0b4d84f 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java @@ -234,7 +234,7 @@ public class PackageTest extends junit.framework.TestCase { } catch (NullPointerException compatible) { /* * RI throws NPE instead of NFE... - */ + */ } try { @@ -290,7 +290,7 @@ public class PackageTest extends junit.framework.TestCase { assertTrue("Package toString returns wrong string", p.toString() .length() > 0); } - + public void test_SealedPackage_forName() throws Exception { Support_Resources.copyFile(resources, "Package", "hyts_c.jar"); Support_Resources.copyFile(resources, "Package", "hyts_d.jar"); @@ -318,7 +318,7 @@ public class PackageTest extends junit.framework.TestCase { // setup for next test Support_Resources.copyFile(resources, "p", ""); InputStream in = uclClassLoader.getResourceAsStream("p/D.class"); - Support_Resources.copyLocalFileto(new File(resources.toString(), + Support_Resources.copyLocalFileTo(new File(resources.toString(), "p/D.class"), in); // load from a sealed jar, then the directory diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/RuntimePermissionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/RuntimePermissionTest.java deleted file mode 100644 index ebe3a40..0000000 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/RuntimePermissionTest.java +++ /dev/null @@ -1,44 +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.luni.tests.java.lang; - -public class RuntimePermissionTest extends junit.framework.TestCase { - - /** - * @tests java.lang.RuntimePermission#RuntimePermission(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // Test for method java.lang.RuntimePermission(java.lang.String) - RuntimePermission r = new RuntimePermission("createClassLoader"); - assertEquals("Returned incorrect name", - "createClassLoader", r.getName()); - - } - - /** - * @tests java.lang.RuntimePermission#RuntimePermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.lang.RuntimePermission(java.lang.String, - // java.lang.String) - RuntimePermission r = new RuntimePermission("createClassLoader", null); - assertEquals("Returned incorrect name", - "createClassLoader", r.getName()); - } -} diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/ReflectPermissionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/ReflectPermissionTest.java deleted file mode 100644 index 30b3174..0000000 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/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 org.apache.harmony.luni.tests.java.lang.reflect; - -import java.lang.reflect.ReflectPermission; - -public class ReflectPermissionTest extends junit.framework.TestCase { - - /** - * @tests 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); - } - - /** - * @tests 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/api/common/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java index f244be0..6b766d9 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java @@ -54,20 +54,11 @@ public class Inet4AddressTest extends junit.framework.TestCase { } - /** - * @tests java.net.Inet4Address#isAnyLocalAddress() - */ - public void test_isAnyLocalAddress() throws Exception { - String addrName = ""; - addrName = "0.0.0.0"; - InetAddress addr = InetAddress.getByName(addrName); - assertTrue("ANY address " + addrName + " not detected.", addr - .isAnyLocalAddress()); - } + public void test_isAnyLocalAddress() throws Exception { + assertTrue(InetAddress.getByName("0.0.0.0").isAnyLocalAddress()); + assertFalse(InetAddress.getByName("127.0.0.1").isAnyLocalAddress()); + } - /** - * @tests java.net.Inet4Address#isLoopbackAddress() - */ public void test_isLoopbackAddress() throws Exception { // Create some IP V4 addresses and test if they are local... @@ -316,7 +307,7 @@ public class Inet4AddressTest extends junit.framework.TestCase { + " not identified as a org-local multicast address.", addr .isMCOrgLocal()); } - + // comparator for Inet4Address objects private static final SerializableAssert COMPARATOR = new SerializableAssert() { public void assertDeserialized(Serializable initial, diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java index df1431b..c602eec 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java @@ -36,13 +36,7 @@ import tests.support.Support_PortManager; public class MulticastSocketTest extends junit.framework.TestCase { - Thread t; - - MulticastSocket mss; - - MulticastServer server; - - boolean atLeastTwoInterfaces = false; + private boolean atLeastTwoInterfaces = false; private NetworkInterface networkInterface1 = null; @@ -50,6 +44,24 @@ public class MulticastSocketTest extends junit.framework.TestCase { private NetworkInterface IPV6networkInterface1 = null; + private static InetAddress lookup(String s) { + try { + return InetAddress.getByName(s); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + + // These IP addresses aren't inherently "good" or "bad"; they're just used like that. + // We use the "good" addresses for our actual group, and the "bad" addresses are for + // a group that we won't actually set up. + + private static InetAddress GOOD_IPv4 = lookup("224.0.0.3"); + private static InetAddress BAD_IPv4 = lookup("224.0.0.4"); + + private static InetAddress GOOD_IPv6 = lookup("ff05::7:7"); + private static InetAddress BAD_IPv6 = lookup("ff05::7:8"); + static class MulticastServer extends Thread { public MulticastSocket ms; @@ -149,7 +161,7 @@ public class MulticastSocketTest extends junit.framework.TestCase { int groupPort = Support_PortManager.getNextPortForUDP(); // validate that we get the expected response when one was not set - mss = new MulticastSocket(groupPort); + MulticastSocket mss = new MulticastSocket(groupPort); // we expect an ANY address in this case assertTrue(mss.getInterface().isAnyLocalAddress()); @@ -166,13 +178,15 @@ public class MulticastSocketTest extends junit.framework.TestCase { mss.setNetworkInterface(networkInterface1); assertEquals("getInterface did not return interface set by setNetworkInterface", networkInterface1, NetworkInterface.getByInetAddress(mss.getInterface())); } + + mss.close(); } public void test_getNetworkInterface() throws IOException { int groupPort = Support_PortManager.getNextPortForUDP(); // validate that we get the expected response when one was not set - mss = new MulticastSocket(groupPort); + MulticastSocket mss = new MulticastSocket(groupPort); NetworkInterface theInterface = mss.getNetworkInterface(); assertTrue("network interface returned wrong network interface when not set:" + theInterface, theInterface.getInetAddresses().hasMoreElements()); @@ -189,6 +203,7 @@ public class MulticastSocketTest extends junit.framework.TestCase { assertEquals("getNetworkInterface did not return network interface set by second setNetworkInterface call", networkInterface2, mss.getNetworkInterface()); } + mss.close(); groupPort = Support_PortManager.getNextPortForUDP(); mss = new MulticastSocket(groupPort); @@ -208,10 +223,11 @@ public class MulticastSocketTest extends junit.framework.TestCase { assertEquals("getNetworkInterface did not return interface set by setInterface", networkInterface1, mss.getNetworkInterface()); } + mss.close(); } public void test_getTimeToLive() throws Exception { - mss = new MulticastSocket(); + MulticastSocket mss = new MulticastSocket(); mss.setTimeToLive(120); assertEquals("Returned incorrect 1st TTL", 120, mss.getTimeToLive()); mss.setTimeToLive(220); @@ -219,65 +235,90 @@ public class MulticastSocketTest extends junit.framework.TestCase { } public void test_getTTL() throws Exception { - mss = new MulticastSocket(); + MulticastSocket mss = new MulticastSocket(); mss.setTTL((byte) 120); assertEquals("Returned incorrect TTL", 120, mss.getTTL()); } - public void test_joinGroupLjava_net_InetAddress() throws Exception { + public void test_joinGroupLjava_net_InetAddress_IPv4() throws Exception { + test_joinGroupLjava_net_InetAddress(GOOD_IPv4); + } + + public void test_joinGroupLjava_net_InetAddress_IPv6() throws Exception { + test_joinGroupLjava_net_InetAddress(GOOD_IPv6); + } + + private void test_joinGroupLjava_net_InetAddress(InetAddress group) throws Exception { int[] ports = Support_PortManager.getNextPortsForUDP(2); int groupPort = ports[0]; - InetAddress group = InetAddress.getByName("224.0.0.3"); - server = new MulticastServer(group, groupPort); + MulticastServer server = new MulticastServer(group, groupPort); server.start(); Thread.sleep(1000); String msg = "Hello World"; - mss = new MulticastSocket(ports[1]); + MulticastSocket mss = new MulticastSocket(ports[1]); DatagramPacket sdp = new DatagramPacket(msg.getBytes(), msg.length(), group, groupPort); mss.send(sdp, (byte) 10); Thread.sleep(1000); String receivedMessage = new String(server.rdp.getData(), 0, server.rdp.getLength()); assertEquals("Group member did not recv data", msg, receivedMessage); + mss.close(); + server.stopServer(); } public void test_joinGroup_null_null() throws Exception { - mss = new MulticastSocket(0); + MulticastSocket mss = new MulticastSocket(0); try { mss.joinGroup(null, null); fail(); } catch (IllegalArgumentException expected) { } + mss.close(); } - public void test_joinGroup_non_multicast_address() throws Exception { - mss = new MulticastSocket(0); - // This isn't a multicast address. - InetAddress badAddress = InetAddress.getByName("255.255.255.255"); + public void test_joinGroup_non_multicast_address_IPv4() throws Exception { + MulticastSocket mss = new MulticastSocket(0); try { - mss.joinGroup(new InetSocketAddress(badAddress, 0), null); + mss.joinGroup(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0), null); fail(); } catch (IOException expected) { } + mss.close(); } - public void test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface() throws Exception { + public void test_joinGroup_non_multicast_address_IPv6() throws Exception { + MulticastSocket mss = new MulticastSocket(0); + try { + mss.joinGroup(new InetSocketAddress(InetAddress.getByName("::1"), 0), null); + fail(); + } catch (IOException expected) { + } + mss.close(); + } + + public void test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface_IPv4() throws Exception { + test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface(GOOD_IPv4, BAD_IPv4); + } + + public void test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface_IPv6() throws Exception { + test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface(GOOD_IPv6, BAD_IPv6); + } + + private void test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface(InetAddress group, InetAddress group2) throws Exception { int[] ports = Support_PortManager.getNextPortsForUDP(2); int groupPort = ports[0]; int serverPort = ports[1]; - InetAddress group = InetAddress.getByName("224.0.0.3"); SocketAddress groupSockAddr = new InetSocketAddress(group, groupPort); - // now validate that we can properly join a group with a null - // network interface - mss = new MulticastSocket(groupPort); + // Check that we can join a group using a null network interface. + MulticastSocket mss = new MulticastSocket(groupPort); mss.joinGroup(groupSockAddr, null); mss.setTimeToLive(2); Thread.sleep(1000); // set up the server and join the group on networkInterface1 - server = new MulticastServer(groupSockAddr, serverPort, networkInterface1); + MulticastServer server = new MulticastServer(groupSockAddr, serverPort, networkInterface1); server.start(); Thread.sleep(1000); String msg = "Hello World"; @@ -288,6 +329,7 @@ public class MulticastSocketTest extends junit.framework.TestCase { // now validate that we received the data as expected assertEquals("Group member did not recv data", msg, new String(server.rdp.getData(), 0, server.rdp.getLength())); server.stopServer(); + mss.close(); // now validate that we handled the case were we join a // different multicast address. @@ -300,7 +342,6 @@ public class MulticastSocketTest extends junit.framework.TestCase { groupPort = ports[1]; mss = new MulticastSocket(groupPort); - InetAddress group2 = InetAddress.getByName("224.0.0.4"); mss.setTimeToLive(10); msg = "Hello World - Different Group"; sdp = new DatagramPacket(msg.getBytes(), msg.length(), group2, serverPort); @@ -309,156 +350,195 @@ public class MulticastSocketTest extends junit.framework.TestCase { assertFalse("Group member received data when sent on different group: ", new String(server.rdp.getData(), 0, server.rdp.getLength()).equals(msg)); server.stopServer(); + mss.close(); + } + public void test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface() throws Exception { // if there is more than one network interface then check that // we can join on specific interfaces and that we only receive // if data is received on that interface - if (atLeastTwoInterfaces) { - // set up server on first interfaces - NetworkInterface loopbackInterface = NetworkInterface.getByInetAddress(InetAddress.getByName("127.0.0.1")); + if (!atLeastTwoInterfaces) { + return; + } + // set up server on first interfaces + NetworkInterface loopbackInterface = NetworkInterface.getByInetAddress(InetAddress.getByName("127.0.0.1")); - boolean anyLoop = networkInterface1.equals(loopbackInterface) || networkInterface2.equals(loopbackInterface); + boolean anyLoop = networkInterface1.equals(loopbackInterface) || networkInterface2.equals(loopbackInterface); + System.err.println("anyLoop="+anyLoop); - ArrayList<NetworkInterface> realInterfaces = new ArrayList<NetworkInterface>(); - Enumeration<NetworkInterface> theInterfaces = NetworkInterface.getNetworkInterfaces(); - while (theInterfaces.hasMoreElements()) { - NetworkInterface thisInterface = (NetworkInterface) theInterfaces.nextElement(); - if (thisInterface.getInetAddresses().hasMoreElements()){ - realInterfaces.add(thisInterface); - } + ArrayList<NetworkInterface> realInterfaces = new ArrayList<NetworkInterface>(); + Enumeration<NetworkInterface> theInterfaces = NetworkInterface.getNetworkInterfaces(); + while (theInterfaces.hasMoreElements()) { + NetworkInterface thisInterface = (NetworkInterface) theInterfaces.nextElement(); + if (thisInterface.getInetAddresses().hasMoreElements()){ + realInterfaces.add(thisInterface); } + } - for (int i = 0; i < realInterfaces.size(); i++) { - final int SECOND = 1; - NetworkInterface thisInterface = realInterfaces.get(i); + for (int i = 0; i < realInterfaces.size(); i++) { + NetworkInterface thisInterface = realInterfaces.get(i); - // get the first address on the interface + // get the first address on the interface - // start server which is joined to the group and has - // only asked for packets on this interface - Enumeration<InetAddress> addresses = thisInterface.getInetAddresses(); + // start server which is joined to the group and has + // only asked for packets on this interface + Enumeration<InetAddress> addresses = thisInterface.getInetAddresses(); - NetworkInterface sendingInterface = null; - if (addresses.hasMoreElements()) { - InetAddress firstAddress = (InetAddress) addresses.nextElement(); - if (firstAddress instanceof Inet4Address) { - group = InetAddress.getByName("224.0.0.4"); - if (anyLoop) { - if (networkInterface1.equals(loopbackInterface)) { - sendingInterface = networkInterface2; - } else { - sendingInterface = networkInterface1; - } + NetworkInterface sendingInterface = null; + InetAddress group = null; + if (addresses.hasMoreElements()) { + InetAddress firstAddress = (InetAddress) addresses.nextElement(); + if (firstAddress instanceof Inet4Address) { + group = InetAddress.getByName("224.0.0.4"); + if (anyLoop) { + if (networkInterface1.equals(loopbackInterface)) { + sendingInterface = networkInterface2; } else { - if(i == SECOND){ - sendingInterface = networkInterface2; - } else { - sendingInterface = networkInterface1; - } + sendingInterface = networkInterface1; } } else { - // if this interface only seems to support - // IPV6 addresses - group = InetAddress.getByName("FF01:0:0:0:0:0:2:8001"); - sendingInterface = IPV6networkInterface1; + if (i == 1){ + sendingInterface = networkInterface2; + } else { + sendingInterface = networkInterface1; + } } - } - - ports = Support_PortManager.getNextPortsForUDP(2); - serverPort = ports[0]; - groupPort = ports[1]; - groupSockAddr = new InetSocketAddress(group, serverPort); - server = new MulticastServer(groupSockAddr, serverPort, thisInterface); - server.start(); - Thread.sleep(1000); - - // Now send out a package on interface - // networkInterface 1. We should - // only see the packet if we send it on interface 1 - mss = new MulticastSocket(groupPort); - mss.setNetworkInterface(sendingInterface); - msg = "Hello World - Again" + thisInterface.getName(); - sdp = new DatagramPacket(msg.getBytes(), msg.length(), group, serverPort); - mss.send(sdp); - Thread.sleep(1000); - if (thisInterface.equals(sendingInterface)) { - assertEquals("Group member did not recv data when bound on specific interface", - msg, new String(server.rdp.getData(), 0, server.rdp.getLength())); } else { - assertFalse("Group member received data on other interface when only asked for it on one interface: ", - new String(server.rdp.getData(), 0, server.rdp.getLength()).equals(msg)); + // if this interface only seems to support IPV6 addresses + group = InetAddress.getByName("FF01:0:0:0:0:0:2:8001"); + sendingInterface = IPV6networkInterface1; } + } - server.stopServer(); + int[] ports = Support_PortManager.getNextPortsForUDP(2); + int serverPort = ports[0]; + int groupPort = ports[1]; + InetSocketAddress groupSockAddr = new InetSocketAddress(group, serverPort); + MulticastServer server = new MulticastServer(groupSockAddr, serverPort, thisInterface); + server.start(); + Thread.sleep(1000); + + // Now send out a package on interface + // networkInterface 1. We should + // only see the packet if we send it on interface 1 + MulticastSocket mss = new MulticastSocket(groupPort); + mss.setNetworkInterface(sendingInterface); + String msg = "Hello World - Again" + thisInterface.getName(); + DatagramPacket sdp = new DatagramPacket(msg.getBytes(), msg.length(), group, serverPort); + System.err.println(thisInterface + " " + group); + mss.send(sdp); + Thread.sleep(1000); + if (thisInterface.equals(sendingInterface)) { + assertEquals("Group member did not recv data when bound on specific interface", + msg, new String(server.rdp.getData(), 0, server.rdp.getLength())); + } else { + assertFalse("Group member received data on other interface when only asked for it on one interface: ", + new String(server.rdp.getData(), 0, server.rdp.getLength()).equals(msg)); } - // validate that we can join the same address on two - // different interfaces but not on the same interface - groupPort = Support_PortManager.getNextPortForUDP(); - mss = new MulticastSocket(groupPort); + server.stopServer(); + mss.close(); + } + } + + public void test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface_multiple_joins_IPv4() throws Exception { + test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface_multiple_joins(GOOD_IPv4); + } + + public void test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface_multiple_joins_IPv6() throws Exception { + test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface_multiple_joins(GOOD_IPv6); + } + + private void test_joinGroupLjava_net_SocketAddressLjava_net_NetworkInterface_multiple_joins(InetAddress group) throws Exception { + // validate that we can join the same address on two + // different interfaces but not on the same interface + int groupPort = Support_PortManager.getNextPortForUDP(); + MulticastSocket mss = new MulticastSocket(groupPort); + SocketAddress groupSockAddr = new InetSocketAddress(group, groupPort); + mss.joinGroup(groupSockAddr, networkInterface1); + mss.joinGroup(groupSockAddr, networkInterface2); + try { mss.joinGroup(groupSockAddr, networkInterface1); - mss.joinGroup(groupSockAddr, networkInterface2); - try { - mss.joinGroup(groupSockAddr, networkInterface1); - fail("Did not get expected exception when joining for second time on same interface"); - } catch (IOException e) { - } + fail("Did not get expected exception when joining for second time on same interface"); + } catch (IOException e) { } + mss.close(); + } + + public void test_leaveGroupLjava_net_InetAddress_IPv4() throws Exception { + test_leaveGroupLjava_net_InetAddress(GOOD_IPv4); } - public void test_leaveGroupLjava_net_InetAddress() throws Exception { + public void test_leaveGroupLjava_net_InetAddress_IPv6() throws Exception { + test_leaveGroupLjava_net_InetAddress(GOOD_IPv6); + } + + private void test_leaveGroupLjava_net_InetAddress(InetAddress group) throws Exception { int[] ports = Support_PortManager.getNextPortsForUDP(2); int groupPort = ports[0]; - InetAddress group = InetAddress.getByName("224.0.0.3"); String msg = "Hello World"; - mss = new MulticastSocket(ports[1]); + MulticastSocket mss = new MulticastSocket(ports[1]); DatagramPacket sdp = new DatagramPacket(msg.getBytes(), msg.length(), group, groupPort); mss.send(sdp, (byte) 10); - boolean except = false; try { - // Try to leave s group that mss is not a member of + // Try to leave a group we didn't join. mss.leaveGroup(group); - } catch (java.io.IOException e) { - // Correct - except = true; + fail(); + } catch (IOException expected) { } - assertTrue("Failed to throw exception leaving non-member group", except); + mss.close(); } - public void test_leaveGroupLjava_net_SocketAddressLjava_net_NetworkInterface() throws Exception { - String msg = null; - InetAddress group = null; - int groupPort = Support_PortManager.getNextPortForUDP(); - SocketAddress groupSockAddr = null; - SocketAddress groupSockAddr2 = null; - - Enumeration theInterfaces = NetworkInterface.getNetworkInterfaces(); - - // first validate that we handle a null group ok - mss = new MulticastSocket(groupPort); + public void test_leaveGroup_null_null() throws Exception { + MulticastSocket mss = new MulticastSocket(0); try { mss.leaveGroup(null, null); - fail("Did not get exception when group was null"); - } catch (IllegalArgumentException e) { + fail(); + } catch (IllegalArgumentException expected) { } + mss.close(); + } - // now validate we get the expected error if the address specified - // is not a multicast group + public void test_leaveGroup_non_multicast_address_IPv4() throws Exception { + MulticastSocket mss = new MulticastSocket(0); try { - group = InetAddress.getByName("255.255.255.255"); - groupSockAddr = new InetSocketAddress(group, groupPort); - mss.leaveGroup(groupSockAddr, null); - fail("Did not get exception when group is not a multicast address"); - } catch (IOException e) { + mss.leaveGroup(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0), null); + fail(); + } catch (IOException expected) { } + mss.close(); + } + + public void test_leaveGroup_non_multicast_address_IPv6() throws Exception { + MulticastSocket mss = new MulticastSocket(0); + try { + mss.leaveGroup(new InetSocketAddress(InetAddress.getByName("::1"), 0), null); + fail(); + } catch (IOException expected) { + } + mss.close(); + } + + public void test_leaveGroupLjava_net_SocketAddressLjava_net_NetworkInterface_IPv4() throws Exception { + test_leaveGroupLjava_net_SocketAddressLjava_net_NetworkInterface(GOOD_IPv4, BAD_IPv4); + } + + public void test_leaveGroupLjava_net_SocketAddressLjava_net_NetworkInterface_IPv6() throws Exception { + test_leaveGroupLjava_net_SocketAddressLjava_net_NetworkInterface(GOOD_IPv6, BAD_IPv6); + } + + private void test_leaveGroupLjava_net_SocketAddressLjava_net_NetworkInterface(InetAddress group, InetAddress group2) throws Exception { + String msg = null; + int groupPort = Support_PortManager.getNextPortForUDP(); + SocketAddress groupSockAddr = null; + SocketAddress groupSockAddr2 = null; - group = InetAddress.getByName("224.0.0.3"); groupSockAddr = new InetSocketAddress(group, groupPort); // now test that we can join and leave a group successfully groupPort = Support_PortManager.getNextPortForUDP(); - mss = new MulticastSocket(groupPort); + MulticastSocket mss = new MulticastSocket(groupPort); groupSockAddr = new InetSocketAddress(group, groupPort); mss.joinGroup(groupSockAddr, null); mss.leaveGroup(groupSockAddr, null); @@ -468,7 +548,6 @@ public class MulticastSocketTest extends junit.framework.TestCase { } catch (IOException expected) { } - InetAddress group2 = InetAddress.getByName("224.0.0.4"); groupSockAddr2 = new InetSocketAddress(group2, groupPort); mss.joinGroup(groupSockAddr, networkInterface1); try { @@ -488,18 +567,21 @@ public class MulticastSocketTest extends junit.framework.TestCase { } } - public void test_sendLjava_net_DatagramPacketB() throws Exception { - // Test for method void - // java.net.MulticastSocket.send(java.net.DatagramPacket, byte) + public void test_sendLjava_net_DatagramPacketB_IPv4() throws Exception { + test_sendLjava_net_DatagramPacketB(GOOD_IPv4); + } + + public void test_sendLjava_net_DatagramPacketB_IPv6() throws Exception { + test_sendLjava_net_DatagramPacketB(GOOD_IPv6); + } + private void test_sendLjava_net_DatagramPacketB(InetAddress group) throws Exception { String msg = "Hello World"; - InetAddress group = null; int[] ports = Support_PortManager.getNextPortsForUDP(2); int groupPort = ports[0]; - group = InetAddress.getByName("224.0.0.3"); - mss = new MulticastSocket(ports[1]); - server = new MulticastServer(group, groupPort); + MulticastSocket mss = new MulticastSocket(ports[1]); + MulticastServer server = new MulticastServer(group, groupPort); server.start(); Thread.sleep(200); DatagramPacket sdp = new DatagramPacket(msg.getBytes(), msg.length(), group, groupPort); @@ -509,14 +591,11 @@ public class MulticastSocketTest extends junit.framework.TestCase { byte[] data = server.rdp.getData(); int length = server.rdp.getLength(); assertEquals("Failed to send data. Received " + length, msg, new String(data, 0, length)); + server.stopServer(); } public void test_setInterfaceLjava_net_InetAddress() throws Exception { - // Test for method void - // java.net.MulticastSocket.setInterface(java.net.InetAddress) - // Note that the machine is not multi-homed - - mss = new MulticastSocket(); + MulticastSocket mss = new MulticastSocket(); mss.setInterface(InetAddress.getLocalHost()); InetAddress theInterface = mss.getInterface(); // under IPV6 we are not guarrenteed to get the same address back as @@ -527,50 +606,67 @@ public class MulticastSocketTest extends junit.framework.TestCase { } else { assertTrue("Failed to return correct interface IPV4 got:" + mss.getInterface() + " excpeted: " + InetAddress.getLocalHost(), mss.getInterface().equals(InetAddress.getLocalHost())); } + mss.close(); + } + + public void test_setInterface_unbound_address_IPv4() throws Exception { + test_setInterface_unbound_address(GOOD_IPv4); + } + + public void test_setInterface_unbound_address_IPv6() throws Exception { + test_setInterface_unbound_address(GOOD_IPv6); + } - // Regression test for Harmony-2410 + // Regression test for Harmony-2410 + private void test_setInterface_unbound_address(InetAddress address) throws Exception { + MulticastSocket mss = new MulticastSocket(); try { - mss = new MulticastSocket(); - mss.setInterface(InetAddress.getByName("224.0.0.5")); + mss.setInterface(address); + fail(); } catch (SocketException expected) { } + mss.close(); } - public void test_setNetworkInterfaceLjava_net_NetworkInterface() throws IOException, InterruptedException { - String msg = null; - InetAddress group = null; - int[] ports = Support_PortManager.getNextPortsForUDP(2); - int groupPort = ports[0]; - int serverPort = ports[1]; - + public void test_setNetworkInterfaceLjava_net_NetworkInterface_null() throws Exception { // validate that null interface is handled ok - mss = new MulticastSocket(groupPort); - - // this should through a socket exception to be compatible + MulticastSocket mss = new MulticastSocket(); try { mss.setNetworkInterface(null); fail("No socket exception when we set then network interface with NULL"); } catch (SocketException ex) { } + mss.close(); + } + public void test_setNetworkInterfaceLjava_net_NetworkInterface_round_trip() throws Exception { // validate that we can get and set the interface - groupPort = Support_PortManager.getNextPortForUDP(); - mss = new MulticastSocket(groupPort); + MulticastSocket mss = new MulticastSocket(); mss.setNetworkInterface(networkInterface1); - assertEquals("Interface did not seem to be set by setNeworkInterface", - networkInterface1, mss.getNetworkInterface()); + assertEquals("Interface did not seem to be set by setNeworkInterface", networkInterface1, mss.getNetworkInterface()); + mss.close(); + } - // set up the server and join the group - group = InetAddress.getByName("224.0.0.3"); + public void test_setNetworkInterfaceLjava_net_NetworkInterface_IPv4() throws Exception { + test_setNetworkInterfaceLjava_net_NetworkInterface(GOOD_IPv4); + } + public void test_setNetworkInterfaceLjava_net_NetworkInterface_IPv6() throws Exception { + test_setNetworkInterfaceLjava_net_NetworkInterface(GOOD_IPv6); + } + + private void test_setNetworkInterfaceLjava_net_NetworkInterface(InetAddress group) throws IOException, InterruptedException { + // set up the server and join the group Enumeration theInterfaces = NetworkInterface.getNetworkInterfaces(); while (theInterfaces.hasMoreElements()) { NetworkInterface thisInterface = (NetworkInterface) theInterfaces.nextElement(); if (thisInterface.getInetAddresses().hasMoreElements()) { if ((!((InetAddress) thisInterface.getInetAddresses().nextElement()).isLoopbackAddress())) { - ports = Support_PortManager.getNextPortsForUDP(2); - serverPort = ports[0]; - server = new MulticastServer(group, serverPort); + int[] ports = Support_PortManager.getNextPortsForUDP(2); + int serverPort = ports[0]; + int groupPort = ports[1]; + + MulticastServer server = new MulticastServer(group, serverPort); server.start(); // give the server some time to start up Thread.sleep(1000); @@ -579,10 +675,9 @@ public class MulticastSocketTest extends junit.framework.TestCase { // source address in the received packet // should be one of the addresses for the interface // set - groupPort = ports[1]; - mss = new MulticastSocket(groupPort); + MulticastSocket mss = new MulticastSocket(groupPort); mss.setNetworkInterface(thisInterface); - msg = thisInterface.getName(); + String msg = thisInterface.getName(); byte theBytes[] = msg.getBytes(); DatagramPacket sdp = new DatagramPacket(theBytes, theBytes.length, group, serverPort); mss.send(sdp); @@ -591,55 +686,48 @@ public class MulticastSocketTest extends junit.framework.TestCase { assertEquals("Group member did not recv data sent on a specific interface", msg, receivedMessage); // stop the server server.stopServer(); + mss.close(); } } } } public void test_setTimeToLiveI() throws Exception { - mss = new MulticastSocket(); + MulticastSocket mss = new MulticastSocket(); mss.setTimeToLive(120); assertEquals("Returned incorrect 1st TTL", 120, mss.getTimeToLive()); mss.setTimeToLive(220); assertEquals("Returned incorrect 2nd TTL", 220, mss.getTimeToLive()); + mss.close(); } public void test_setTTLB() throws Exception { - mss = new MulticastSocket(); + MulticastSocket mss = new MulticastSocket(); mss.setTTL((byte) 120); assertEquals("Failed to set TTL", 120, mss.getTTL()); + mss.close(); } public void test_ConstructorLjava_net_SocketAddress() throws Exception { MulticastSocket ms = new MulticastSocket((SocketAddress) null); - assertTrue("should not be bound", !ms.isBound() && !ms.isClosed() - && !ms.isConnected()); - ms.bind(new InetSocketAddress(InetAddress.getLocalHost(), - Support_PortManager.getNextPortForUDP())); - assertTrue("should be bound", ms.isBound() && !ms.isClosed() - && !ms.isConnected()); + assertTrue("should not be bound", !ms.isBound() && !ms.isClosed() && !ms.isConnected()); + ms.bind(new InetSocketAddress(InetAddress.getLocalHost(), Support_PortManager.getNextPortForUDP())); + assertTrue("should be bound", ms.isBound() && !ms.isClosed() && !ms.isConnected()); ms.close(); assertTrue("should be closed", ms.isClosed()); - ms = new MulticastSocket(new InetSocketAddress(InetAddress - .getLocalHost(), Support_PortManager.getNextPortForUDP())); - assertTrue("should be bound", ms.isBound() && !ms.isClosed() - && !ms.isConnected()); + ms = new MulticastSocket(new InetSocketAddress(InetAddress.getLocalHost(), Support_PortManager.getNextPortForUDP())); + assertTrue("should be bound", ms.isBound() && !ms.isClosed() && !ms.isConnected()); ms.close(); assertTrue("should be closed", ms.isClosed()); - ms = new MulticastSocket(new InetSocketAddress("localhost", - Support_PortManager.getNextPortForUDP())); - assertTrue("should be bound", ms.isBound() && !ms.isClosed() - && !ms.isConnected()); + ms = new MulticastSocket(new InetSocketAddress("localhost", Support_PortManager.getNextPortForUDP())); + assertTrue("should be bound", ms.isBound() && !ms.isClosed() && !ms.isConnected()); ms.close(); assertTrue("should be closed", ms.isClosed()); - boolean exception = false; try { - ms = new MulticastSocket(new InetSocketAddress("unresolvedname", - Support_PortManager.getNextPortForUDP())); - } catch (IOException e) { - exception = true; + ms = new MulticastSocket(new InetSocketAddress("unresolvedname", Support_PortManager.getNextPortForUDP())); + fail(); + } catch (IOException expected) { } - assertTrue("Expected IOException", exception); // regression test for Harmony-1162 InetSocketAddress addr = new InetSocketAddress("0.0.0.0", 0); @@ -666,40 +754,38 @@ public class MulticastSocketTest extends junit.framework.TestCase { assertTrue("should be closed", ms.isClosed()); } - public void test_setLoopbackModeSendReceive() throws IOException{ - InetAddress address = InetAddress.getByName("224.1.2.3"); + public void test_setLoopbackModeSendReceive_IPv4() throws Exception { + test_setLoopbackModeSendReceive(GOOD_IPv4); + } + + public void test_setLoopbackModeSendReceive_IPv6() throws Exception { + test_setLoopbackModeSendReceive(GOOD_IPv6); + } + + private void test_setLoopbackModeSendReceive(InetAddress group) throws IOException{ final int PORT = Support_PortManager.getNextPortForUDP(); final String message = "Hello, world!"; // test send receive - MulticastSocket socket = null; - try { - // open a multicast socket - socket = new MulticastSocket(PORT); - socket.setLoopbackMode(false); // false indicates doing loop back - socket.joinGroup(address); - - // send the datagram - byte[] sendData = message.getBytes(); - DatagramPacket sendDatagram = new DatagramPacket(sendData, 0, - sendData.length, new InetSocketAddress(address, PORT)); - socket.send(sendDatagram); - - // receive the datagram - byte[] recvData = new byte[100]; - DatagramPacket recvDatagram = new DatagramPacket(recvData, recvData.length); - socket.setSoTimeout(5000); // prevent eternal block in - // socket.receive() - socket.receive(recvDatagram); - String recvMessage = new String(recvData, 0, recvDatagram.getLength()); - assertEquals(message, recvMessage); - } finally { - if (socket != null) - socket.close(); - } + MulticastSocket socket = new MulticastSocket(PORT); + socket.setLoopbackMode(false); // false indicates doing loop back + socket.joinGroup(group); + + // send the datagram + byte[] sendData = message.getBytes(); + DatagramPacket sendDatagram = new DatagramPacket(sendData, 0, sendData.length, new InetSocketAddress(group, PORT)); + socket.send(sendDatagram); + + // receive the datagram + byte[] recvData = new byte[100]; + DatagramPacket recvDatagram = new DatagramPacket(recvData, recvData.length); + socket.setSoTimeout(5000); // prevent eternal block in + socket.receive(recvDatagram); + String recvMessage = new String(recvData, 0, recvDatagram.getLength()); + assertEquals(message, recvMessage); + socket.close(); } - public void test_setReuseAddressZ() throws Exception { // test case were we set it to false MulticastSocket theSocket1 = null; @@ -804,16 +890,4 @@ public class MulticastSocketTest extends junit.framework.TestCase { } } } - - @Override protected void tearDown() { - if (t != null) { - t.interrupt(); - } - if (mss != null) { - mss.close(); - } - if (server != null) { - server.stopServer(); - } - } } diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NetPermissionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NetPermissionTest.java deleted file mode 100644 index da665a7..0000000 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NetPermissionTest.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. - */ - -package org.apache.harmony.luni.tests.java.net; - -import java.net.NetPermission; - -public class NetPermissionTest extends junit.framework.TestCase { - - /** - * @tests java.net.NetPermission#NetPermission(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // Test for method java.net.NetPermission(java.lang.String) - NetPermission n = new NetPermission("requestPasswordAuthentication"); - assertEquals("Returned incorrect name", - "requestPasswordAuthentication", n.getName()); - } - - /** - * @tests java.net.NetPermission#NetPermission(java.lang.String, - * java.lang.String) - */ - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Test for method java.net.NetPermission(java.lang.String, - // java.lang.String) - NetPermission n = new NetPermission("requestPasswordAuthentication", - null); - assertEquals("Returned incorrect name", - "requestPasswordAuthentication", n.getName()); - } - - /** - * 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/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java index 64d314b..9a69613 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java @@ -478,58 +478,6 @@ public class URLConnectionTest extends junit.framework.TestCase { } /** - * @tests 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:80")); - - 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"))); - } - - /** * @tests java.net.URLConnection#getRequestProperties() */ public void test_getRequestProperties() { diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertyPermissionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertyPermissionTest.java deleted file mode 100644 index 3a305ca..0000000 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertyPermissionTest.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.luni.tests.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"); - - /** - * @tests 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); - } - - /** - * @tests 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)); - } - - /** - * @tests 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()); - } - - /** - * @tests 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()); - } - - /** - * @tests 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)); - } - - /** - * @tests 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)); - } - - /** - * @tests java.util.PropertyPermission#readObject(ObjectInputStream) - * @tests 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); - } - - 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/resources/serialization/org/apache/harmony/luni/tests/java/util/PropertyPermissionTest.golden.ser b/luni/src/test/resources/serialization/org/apache/harmony/luni/tests/java/util/PropertyPermissionTest.golden.ser Binary files differdeleted file mode 100644 index ffa3060..0000000 --- a/luni/src/test/resources/serialization/org/apache/harmony/luni/tests/java/util/PropertyPermissionTest.golden.ser +++ /dev/null diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java index 78fcd3e..9a89f7e 100644 --- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java +++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java @@ -1172,9 +1172,6 @@ public class FileChannelTest extends TestCase { } } - /** - * @tests java.nio.channels.FileChannel#read(ByteBuffer) - */ public void test_readLByteBuffer() throws Exception { writeDataToFile(fileOfReadOnlyFileChannel); @@ -1188,110 +1185,57 @@ public class FileChannelTest extends TestCase { } } - /** - * @tests java.nio.channels.FileChannel#read(ByteBuffer, long) - */ public void test_readLByteBufferJ_Null() throws Exception { - ByteBuffer readBuffer = null; - - try { - readOnlyFileChannel.read(readBuffer, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - // first throws NullPointerException - try { - readOnlyFileChannel.read(readBuffer, -1); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - // first throws NullPointerException - writeOnlyFileChannel.close(); try { - writeOnlyFileChannel.read(readBuffer, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - try { - readWriteFileChannel.read(readBuffer, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected + readOnlyFileChannel.read(null, 0); + fail(); + } catch (NullPointerException expected) { } - // first throws NullPointerException - writeOnlyFileChannel.close(); try { - writeOnlyFileChannel.read(readBuffer, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected + readWriteFileChannel.read(null, 0); + fail(); + } catch (NullPointerException expected) { } } - /** - * @tests java.nio.channels.FileChannel#read(ByteBuffer, long) - */ public void test_readLByteBufferJ_Closed() throws Exception { ByteBuffer readBuffer = ByteBuffer.allocate(CAPACITY); readOnlyFileChannel.close(); try { readOnlyFileChannel.read(readBuffer, 0); - fail("should throw ClosedChannelException"); - } catch (ClosedChannelException e) { - // expected + fail(); + } catch (ClosedChannelException expected) { } readWriteFileChannel.close(); try { readWriteFileChannel.read(readBuffer, 0); - fail("should throw ClosedChannelException"); - } catch (ClosedChannelException e) { - // expected + fail(); + } catch (ClosedChannelException expected) { } } - /** - * @tests java.nio.channels.FileChannel#read(ByteBuffer, long) - */ public void test_readLByteBufferJ_IllegalArgument() throws Exception { ByteBuffer readBuffer = ByteBuffer.allocate(CAPACITY); try { readOnlyFileChannel.read(readBuffer, -1); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected + fail(); + } catch (IllegalArgumentException expected) { } try { writeOnlyFileChannel.read(readBuffer, -1); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - readWriteFileChannel.read(readBuffer, -1); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected + fail(); + } catch (IllegalArgumentException expected) { } - // throws IllegalArgumentException first. - readWriteFileChannel.close(); try { readWriteFileChannel.read(readBuffer, -1); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected + fail(); + } catch (IllegalArgumentException expected) { } } @@ -1303,14 +1247,6 @@ public class FileChannelTest extends TestCase { fail(); } catch (NonReadableChannelException expected) { } - - writeOnlyFileChannel.close(); - try { - writeOnlyFileChannel.read(readBuffer, 0); - fail(); - } catch (ClosedChannelException expected) { - } catch (NonReadableChannelException expected) { - } } public void test_readLByteBufferJ_Emptyfile() throws Exception { @@ -2096,144 +2032,73 @@ public class FileChannelTest extends TestCase { assertTrue(Arrays.equals(test.getBytes("iso8859-1"), inputBuffer)); } - /** - * @tests java.nio.channels.FileChannel#write(ByteBuffer, long) - */ public void test_writeLByteBufferJ_Null() throws Exception { - ByteBuffer writeBuffer = null; - - try { - readOnlyFileChannel.write(writeBuffer, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - try { - writeOnlyFileChannel.write(writeBuffer, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - // first throws NullPointerException try { - readOnlyFileChannel.write(writeBuffer, -1); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected + readWriteFileChannel.write(null, 0); + fail(); + } catch (NullPointerException expected) { + } catch (NonWritableChannelException expected) { } try { - readWriteFileChannel.write(writeBuffer, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected + writeOnlyFileChannel.write(null, 0); + fail(); + } catch (NullPointerException expected) { } - // first throws NullPointerException - readWriteFileChannel.close(); try { - readWriteFileChannel.write(writeBuffer, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected + readWriteFileChannel.write(null, 0); + fail(); + } catch (NullPointerException expected) { } } - /** - * @tests java.nio.channels.FileChannel#write(ByteBuffer, long) - */ public void test_writeLByteBufferJ_Closed() throws Exception { ByteBuffer writeBuffer = ByteBuffer.allocate(CAPACITY); writeOnlyFileChannel.close(); try { writeOnlyFileChannel.write(writeBuffer, 0); - fail("should throw ClosedChannelException"); - } catch (ClosedChannelException e) { - // expected + fail(); + } catch (ClosedChannelException expected) { } readWriteFileChannel.close(); try { readWriteFileChannel.write(writeBuffer, 0); - fail("should throw ClosedChannelException"); - } catch (ClosedChannelException e) { - // expected + fail(); + } catch (ClosedChannelException expected) { } } - /** - * @tests java.nio.channels.FileChannel#write(ByteBuffer, long) - */ public void test_writeLByteBufferJ_ReadOnly() throws Exception { - ByteBuffer writeBuffer = null; - try { - readOnlyFileChannel.write(writeBuffer, 10); - fail(); - } catch (NullPointerException expected) { - } catch (NonWritableChannelException expected) { - } - - writeBuffer = ByteBuffer.allocate(CAPACITY); - try { - readOnlyFileChannel.write(writeBuffer, 10); - fail(); - } catch (NonWritableChannelException expected) { - } - - try { - readOnlyFileChannel.write(writeBuffer, -1); - fail(); - } catch (IllegalArgumentException expected) { - } catch (NonWritableChannelException expected) { - } - - // regression test for Harmony-903 - readOnlyFileChannel.close(); + ByteBuffer writeBuffer = ByteBuffer.allocate(CAPACITY); try { readOnlyFileChannel.write(writeBuffer, 10); fail(); - } catch (ClosedChannelException expected) { } catch (NonWritableChannelException expected) { } } - /** - * @tests java.nio.channels.FileChannel#write(ByteBuffer, long) - */ public void test_writeLByteBufferJ_IllegalArgument() throws Exception { ByteBuffer writeBuffer = ByteBuffer.allocate(CAPACITY); try { readOnlyFileChannel.write(writeBuffer, -1); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected + fail(); + } catch (IllegalArgumentException expected) { } try { writeOnlyFileChannel.write(writeBuffer, -1); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - readWriteFileChannel.write(writeBuffer, -1); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected + fail(); + } catch (IllegalArgumentException expected) { } - // throws IllegalArgumentException first. - readWriteFileChannel.close(); try { readWriteFileChannel.write(writeBuffer, -1); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected + fail(); + } catch (IllegalArgumentException expected) { } } diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java index 9575352..acc611d 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java @@ -4,9 +4,9 @@ * 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. @@ -69,7 +69,7 @@ public class CharsetTest extends TestCase { Charset.forName(name).isRegistered()); } } - + /** * @tests java.nio.charset.Charset#isSupported(String) */ @@ -82,59 +82,11 @@ public class CharsetTest extends TestCase { // Expected } } - - /** - * @tests java.nio.charset.Charset#defaultCharset() - */ - public void test_defaultCharset() { - String charsetName = null; - String defaultCharsetName = null; - String oldDefaultEncoding = System.getProperty("file.encoding"); - try { - // Normal behavior - charsetName = "UTF-8"; //$NON-NLS-1$ - System.setProperty("file.encoding", charsetName);//$NON-NLS-1$ - defaultCharsetName = Charset.defaultCharset().name(); - assertEquals(charsetName, defaultCharsetName); - - charsetName = "ISO-8859-1"; //$NON-NLS-1$ - System.setProperty("file.encoding", charsetName);//$NON-NLS-1$ - defaultCharsetName = Charset.defaultCharset().name(); - assertEquals(charsetName, defaultCharsetName); - - // Unsupported behavior - charsetName = "IMPOSSIBLE-8"; //$NON-NLS-1$ - System.setProperty("file.encoding", charsetName);//$NON-NLS-1$ - defaultCharsetName = Charset.defaultCharset().name(); - assertEquals("UTF-8", defaultCharsetName); - - // Null behavior - try { - Properties currentProps = System.getProperties(); - currentProps.remove("file.encoding");//$NON-NLS-1$ - Charset.defaultCharset().name(); - fail("Should throw illegal IllegalArgumentException");//$NON-NLS-1$ - } catch (IllegalArgumentException e) { - // expected - } - - // IllegalCharsetName behavior - try { - charsetName = "IMP~~OSSIBLE-8"; //$NON-NLS-1$ - System.setProperty("file.encoding", charsetName);//$NON-NLS-1$ - Charset.defaultCharset().name(); - fail("Should throw IllegalCharsetNameException");//$NON-NLS-1$ - } catch (IllegalCharsetNameException e) { - // expected - } - } finally { - System.setProperty("file.encoding", oldDefaultEncoding);//$NON-NLS-1$ - } - } - - /** - * @tests java.nio.charset.Charset#forName(java.lang.String) - */ + + public void test_defaultCharset() { + assertEquals("UTF-8", Charset.defaultCharset().name()); + } + public void test_forNameLjava_lang_String() { /* * invoke forName two times with the same canonical name, it @@ -152,7 +104,7 @@ public class CharsetTest extends TestCase { Charset cs4 = Charset.forName("US-ASCII"); assertSame(cs3, cs4); } - + /* * test cached decoder */ diff --git a/run-harmony-tests b/run-harmony-tests index 7553347..5d32489 100755 --- a/run-harmony-tests +++ b/run-harmony-tests @@ -3,18 +3,21 @@ # Make sure there's a vogar on the path, but prefer the user's one. export PATH=$PATH:~dalvik-prebuild/vogar/bin -VOGAR="vogar $VOGAR_FLAGS $*" +VOGAR="vogar $VOGAR_FLAGS" # We enumerate the test packages for vogar rather than just giving it the classes.jar # so hundreds of packages can be tested in parallel, rather than one big jar file serially. -all_test_packages=$(find external/apache-harmony/*/src/test -name "*.java" | \ +all_test_packages=$(find `dirname $0`/*/src/test -name "*.java" | \ fgrep -v junit | \ fgrep -v org/w3c/domts | \ fgrep -v support/src/test/java | \ xargs grep -h '^package ' | sed 's/^package //' | sed 's/;$//' | sort | uniq | tr "\n" " ") +# Use the list of packages supplied on the command-line, if any. +test_packages=${*:-$all_test_packages} + echo "Running tests for following test packages:" -echo $all_test_packages | tr " " "\n" +echo $test_packages | tr " " "\n" # beans: works, except IndexedPropertyDescriptorTest won't load # concurrent: needs vogar to detect code type in the target VM @@ -26,5 +29,5 @@ $VOGAR \ --vm-arg -Xmx32M \ --classpath out/host/common/obj/JAVA_LIBRARIES/apache-harmony-tests-hostdex_intermediates/javalib.jar \ --results-dir /home/dalvik-prebuild/vogar-harmony-results \ - $all_test_packages \ + $test_packages \ || true diff --git a/security/src/test/api/java.injected/java/security/AllPermissionTest.java b/security/src/test/api/java.injected/java/security/AllPermissionTest.java deleted file mode 100644 index f3a6fa3..0000000 --- a/security/src/test/api/java.injected/java/security/AllPermissionTest.java +++ /dev/null @@ -1,87 +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 -*/ - -package java.security; - -import junit.framework.TestCase; - -/** - * Tests for <code>AllPermission</code> - * - */ -public class AllPermissionTest extends TestCase { - - /** - * Constructor for AllPermissionsTest. - * @param arg0 - */ - public AllPermissionTest(String arg0) { - super(arg0); - } - - /** - * 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/security/src/test/api/java.injected/java/security/BasicPermissionTest.java b/security/src/test/api/java.injected/java/security/BasicPermissionTest.java deleted file mode 100644 index 3fbe894..0000000 --- a/security/src/test/api/java.injected/java/security/BasicPermissionTest.java +++ /dev/null @@ -1,137 +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 -*/ - -package java.security; - -import junit.framework.TestCase; - -/** - * Tests for <code>BasicPermission</code> - * - */ - -public class BasicPermissionTest extends TestCase { - - /** - * Constructor for BasicPermissionTest. - * @param arg0 - */ - public BasicPermissionTest(String arg0) { - super(arg0); - } - - /** - * 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/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java deleted file mode 100644 index 5052c26..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java +++ /dev/null @@ -1,100 +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.SecurityPermission; - -public class AllPermission2Test extends junit.framework.TestCase { - - /** - * @tests 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()); - } - - /** - * @tests 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()); - } - - /** - * @tests 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!")))); - } - - /** - * @tests 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>")); - } - - /** - * @tests 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); - } - - /** - * @tests 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()))); - } -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java deleted file mode 100644 index e173d5f..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java +++ /dev/null @@ -1,138 +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.Permission; -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.*"); - - /** - * @tests 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()); - } - - /** - * @tests 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()); - } - - /** - * @tests 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)); - } - - /** - * @tests 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("")); - } - - /** - * @tests 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()); - } - - /** - * @tests 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)); - - } - - /** - * @tests 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)); - } - - //Special treat with RuntimePermission exitVM in Java 6, which equals RuntimePermission exitVM.* - public void test_RuntimePermissionExitVM(){ - Permission permission_exitVM = new RuntimePermission("exitVM"); - Permission permission_exitVM_ALL = new RuntimePermission("exitVM.*"); - Permission permission_exitVM_0 = new RuntimePermission("exitVM.0"); - Permission permission_exitVM_a = new RuntimePermission("exitVM.a"); - assertTrue(permission_exitVM.implies(permission_exitVM_ALL)); - assertTrue(permission_exitVM.implies(permission_exitVM)); - assertTrue(permission_exitVM.implies(permission_exitVM_0)); - assertTrue(permission_exitVM.implies(permission_exitVM_a)); - assertTrue(permission_exitVM_ALL.implies(permission_exitVM)); - assertTrue(permission_exitVM_ALL.implies(permission_exitVM_0)); - assertTrue(permission_exitVM_ALL.implies(permission_exitVM_a)); - } -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java deleted file mode 100644 index 2b82c7a..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java +++ /dev/null @@ -1,102 +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.CodeSource; -import java.security.cert.Certificate; - -public class CodeSource2Test extends junit.framework.TestCase { - - /** - * @throws Exception - * @tests 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); - } - - /** - * @tests 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)); - } - - /** - * @tests 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()); - } - - /** - * @tests 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()); - } - - /** - * @tests 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()); - } - - /** - * @tests 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)); - } - -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java deleted file mode 100644 index 8bcd58c..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java +++ /dev/null @@ -1,618 +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 -*/ - -package org.apache.harmony.security.tests.java.security; -import 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.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; - - static { - 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); - } - } - - protected void setUp() throws Exception { - super.setUp(); - 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); - } - } - - public void testGetCoderSignersNull() throws Exception{ - assertNull(new CodeSource(new URL("http://url"), (Certificate[])null).getCodeSigners()); //$NON-NLS-1$ - } - - /** - * 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)); - } - - /** - * If this object's location equals codesource's location, then return true. - */ - 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)); - - } - - /** - * This object's protocol (getLocation().getProtocol()) must be equal to - * codesource's protocol. - */ - /* - * 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)); - } - - /** - * If this object's host (getLocation().getHost()) is not null, then the - * SocketPermission constructed with this object's host must imply the - * SocketPermission constructed with codesource's host. - */ - 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)); - } - - /** - * If this object's port (getLocation().getPort()) is not equal to -1 (that - * is, if a port is specified), it must equal codesource's port. - */ - 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)); - } - - /** - * If this object's file (getLocation().getFile()) doesn't equal - * codesource's file, then the following checks are made: ... - */ - public void testImplies_06() throws Exception { - CodeSource thizCS = new CodeSource(urlFile, (Certificate[]) null); - CodeSource thatCS = new CodeSource(urlFile, (Certificate[]) null); - assertTrue(thizCS.implies(thatCS)); - } - - /** - * ... If this object's file ends with "/-", then codesource's file must - * start with this object's file (exclusive the trailing "-"). - */ - 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)); - } - - /** - * ... If this object's file ends with a "/*", then codesource's file must - * start with this object's file and must not have any further "/" - * separators. - */ - 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)); - } - - /** - * ... If this object's file doesn't end with a "/", then codesource's file - * must match this object's file with a '/' appended. - */ - 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)); - } - - /** - * If this object's reference (getLocation().getRef()) is not null, it must - * equal codesource's reference. - */ - 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("user.home") - + File.separator + "someDir"); - URL url1 = new URL("file:///" + System.getProperty("user.home") - + 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/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permission2Test.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permission2Test.java deleted file mode 100644 index c9cca11..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permission2Test.java +++ /dev/null @@ -1,112 +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; - } - } - - /** - * @tests java.security.Permission#Permission(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() { - // test method java.security.permission.Permission(string) - SecurityPermission permi = new SecurityPermission( - "Testing the permission abstract class"); - String name = permi.getName(); - assertEquals("Permission Constructor failed", - "Testing the permission abstract class", name); - } - - /** - * @tests 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); - } - } - - /** - * @tests 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()); - } - - /** - * @tests 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); - } - - /** - * @tests 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); - } -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java deleted file mode 100644 index 2b9f552..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java +++ /dev/null @@ -1,105 +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 -*/ - -package org.apache.harmony.security.tests.java.security; -import java.security.*; -import java.util.*; - -import junit.framework.TestCase; - - -/** - * Tests for <code>PermissionCollection</code> - * - */ - -public class PermissionCollectionTest extends TestCase { - - /** - * Constructor for PermissionCollectionTest. - * @param arg0 - */ - public PermissionCollectionTest(String arg0) { - super(arg0); - } - - // Bare extension to instantiate abstract PermissionCollection class - private static final class RealPermissionCollection extends PermissionCollection - { - final private Collection col; - public RealPermissionCollection(Collection col) - { - this.col = col; - } - - public void add(Permission permission) {} - - public Enumeration elements() - { - return col == null ? null : Collections.enumeration(col); - } - - public boolean implies(Permission permission) - { - return false; - } - } - - /** Test read-only flag. Should be false by default and can be set once forever. */ - public void testReadOnly() - { - PermissionCollection pc = new RealPermissionCollection(null); - assertFalse("should not be read-only by default", pc.isReadOnly()); - pc.setReadOnly(); - assertTrue("explicitly set read-only", pc.isReadOnly()); - pc.setReadOnly(); - assertTrue("more calls to setReadOnly() should not harm", pc.isReadOnly()); - } - - // Regression test for "exitVM' special treatement in Java 6. - public void test_implies_exitVM() { - - RuntimePermission runtimePermission = new RuntimePermission("exitVM"); - PermissionCollection permissionCollection = runtimePermission - .newPermissionCollection(); - permissionCollection.add(runtimePermission); - assertFalse(permissionCollection.implies(new RuntimePermission( - "exitVM."))); - assertTrue(permissionCollection.implies(new RuntimePermission( - "exitVM.1"))); - assertTrue(permissionCollection.implies(new RuntimePermission( - "exitVM.teststring"))); - - runtimePermission = new RuntimePermission("exitVM.*"); - permissionCollection = runtimePermission.newPermissionCollection(); - permissionCollection.add(runtimePermission); - assertTrue(permissionCollection - .implies(new RuntimePermission("exitVM"))); - assertFalse(permissionCollection.implies(new RuntimePermission( - "exitVMteststring"))); - assertFalse(permissionCollection.implies(new RuntimePermission( - "exitVM."))); - assertTrue(permissionCollection.implies(new RuntimePermission( - "exitVM.1"))); - assertTrue(permissionCollection.implies(new RuntimePermission( - "exitVM.teststring"))); - } -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionTest.java deleted file mode 100644 index 7cca36f..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionTest.java +++ /dev/null @@ -1,81 +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 -*/ - -package org.apache.harmony.security.tests.java.security; -import java.security.*; -import junit.framework.TestCase; - -/** - * Tests for <code>Permission</code> - */ - -public class PermissionTest extends TestCase { - - /** - * Constructor for PermissionTest. - * - * @param arg0 - */ - public PermissionTest(String arg0) { - super(arg0); - } - - // 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/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java deleted file mode 100644 index 740934f..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java +++ /dev/null @@ -1,159 +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.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"); - - /** - * @tests java.security.Permissions#Permissions() - */ - public void test_Constructor() { - // Test for method java.security.Permissions() - new Permissions(); - } - - /** - * @tests 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); - } - - /** - * @tests 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); - } - - /** - * @tests 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"))); - } - - public void test_RuntimePermission_exitVM(){ - Permissions permissions = new Permissions(); - permissions.add(new RuntimePermission("exitVM")); - assertTrue(permissions.implies(new RuntimePermission("exitVM.*"))); - assertTrue(permissions.implies(new RuntimePermission("exitVM.0"))); - - permissions = new Permissions(); - permissions.add(new RuntimePermission("exitVM.*")); - assertTrue(permissions.implies(new RuntimePermission("exitVM"))); - assertTrue(permissions.implies(new RuntimePermission("exitVM.0"))); - } -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java deleted file mode 100644 index c29af58..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java +++ /dev/null @@ -1,159 +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 -*/ - -package org.apache.harmony.security.tests.java.security; -import java.security.*; -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 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 els = new ArrayList(); - 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){} - - } - - public void test_toString() { - Permissions ps = new Permissions(); - String address = getAddress(ps.toString()); - String expectedResult = "java.security.Permissions@" + address - + " (\n)\n"; - assertEquals(expectedResult, ps.toString()); - } - - private String getAddress(String s) { - int startIndex = s.indexOf('@') + 1; - int endIndex = s.indexOf(' '); - return s.substring(startIndex, endIndex); - } - - } diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicySpiTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicySpiTest.java deleted file mode 100644 index f0e3b23..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicySpiTest.java +++ /dev/null @@ -1,94 +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.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Policy; -import java.security.PolicySpi; -import java.security.ProtectionDomain; - -import junit.framework.TestCase; - -public class PolicySpiTest extends TestCase { - - class MockPolicySpi extends PolicySpi { - - @Override - protected boolean engineImplies(ProtectionDomain domain, - Permission permission) { - return false; - } - - public PermissionCollection testEngineGetPermissionsCodeSource() { - return super.engineGetPermissions((CodeSource) null); - } - - public PermissionCollection testEngineGetPermissionsProtectionDomain() { - return super.engineGetPermissions((ProtectionDomain) null); - } - - public void engineRefresh() { - //do nothing. - return; - } - - - } - - /** - * @tests java.security.PolicySpi#engineGetPermissions(CodeSource) - * @since 1.6 - */ - public void test_engineGetPermissions_LCodeSource() { - MockPolicySpi spi = new MockPolicySpi(); - assertSame(Policy.UNSUPPORTED_EMPTY_COLLECTION, spi - .testEngineGetPermissionsCodeSource()); - } - - /** - * @tests java.security.PolicySpi#engineGetPermissions(ProtectionDomain) - * @since 1.6 - */ - public void test_engineGetPermissions_LProtectionDomain() { - MockPolicySpi spi = new MockPolicySpi(); - assertSame(Policy.UNSUPPORTED_EMPTY_COLLECTION, spi - .testEngineGetPermissionsProtectionDomain()); - } - - /** - * @tests java.security.PolicySpi#engineRefresh() - * @since 1.6 - */ - public void test_engineRefresh() - { - MockPolicySpi spi = new MockPolicySpi(); - assertSame(Policy.UNSUPPORTED_EMPTY_COLLECTION, spi - .testEngineGetPermissionsCodeSource()); - assertSame(Policy.UNSUPPORTED_EMPTY_COLLECTION, spi - .testEngineGetPermissionsCodeSource()); - - // Nothing should be done according to java doc. - spi.engineRefresh(); - assertSame(Policy.UNSUPPORTED_EMPTY_COLLECTION, spi - .testEngineGetPermissionsCodeSource()); - assertSame(Policy.UNSUPPORTED_EMPTY_COLLECTION, spi - .testEngineGetPermissionsCodeSource()); - } - -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java deleted file mode 100644 index ae08bae..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java +++ /dev/null @@ -1,199 +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 -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.net.URL; -import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Policy; -import java.security.ProtectionDomain; -import java.security.Security; -import java.security.SecurityPermission; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashSet; - -import junit.framework.TestCase; - -import org.apache.harmony.security.tests.support.TestUtils; - -import tests.support.resource.Support_Resources; - -/** - * Tests for <code>Policy</code> - */ -public class PolicyTest extends TestCase { - - public static final String JAVA_SECURITY_POLICY = "java.security.policy"; - - 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 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 c = new HashSet(); - 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(); - for (en = pc4pd.elements();en.hasMoreElements(); c.add(en.nextElement())) { - } - - assertTrue(c.contains(sp)); - //no check for static permissions - } - - /** - * @tests java.security.Policy#getPolicy() - * @tests 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); - } - } - - /** - * Test property expansion in policy files - */ - public void testPropertyExpansion() throws Exception { - - // Regression for HARMONY-1963 and HARMONY-2910 - String policyFile = Support_Resources - .getAbsoluteResourcePath("PolicyTest.txt"); - 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/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java deleted file mode 100644 index 63e10ea..0000000 --- a/security/src/test/api/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 { - - /** - * @tests 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() - ); - - } - - /** - * @tests 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()); - - } -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java deleted file mode 100644 index afb3c03..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java +++ /dev/null @@ -1,78 +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 -*/ - -package org.apache.harmony.security.tests.java.security; -import java.security.*; -import junit.framework.TestCase; - -/** - * Tests for <code>SecurityPermission</code> - * - */ -public class SecurityPermissionTest extends TestCase { - - /** - * Constructor for SecurityPermissionTest. - * @param arg0 - */ - public SecurityPermissionTest(String arg0) { - super(arg0); - } - - /** - * 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/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java deleted file mode 100644 index ef3be24..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java +++ /dev/null @@ -1,121 +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.SecurityPermission; -import java.security.UnresolvedPermission; - -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()); - } - }); - } -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.java deleted file mode 100644 index a67299e..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.java +++ /dev/null @@ -1,44 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import java.security.AllPermission; -import java.security.PermissionCollection; -import java.util.Enumeration; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - -/** - * Serialization tests for <code>AllPermissionCollection</code> - * - */ - -public class AllPermissionCollectionTest extends SerializationTest { - - protected Object[] getData() { - PermissionCollection c1 = new AllPermission().newPermissionCollection(); - PermissionCollection c2 = new AllPermission().newPermissionCollection(); - c2.add(new AllPermission()); - return new Object[] { c1, c2 }; - } -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/AllPermissionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/AllPermissionTest.java deleted file mode 100644 index bdf4658..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/AllPermissionTest.java +++ /dev/null @@ -1,44 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import java.security.AllPermission; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - - -/** - * Serialization tests for <code>AllPermission</code> - * - */ - -public class AllPermissionTest extends SerializationTest { - - /** - * @see com.intel.drl.test.SerializationTest#getData() - */ - protected Object[] getData() { - return new Object[] {new AllPermission()}; - } - -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.java deleted file mode 100644 index bd1a145..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.java +++ /dev/null @@ -1,51 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import java.security.PermissionCollection; - -import org.apache.harmony.security.tests.support.MyBasicPermission; -import org.apache.harmony.testframework.serialization.SerializationTest; - -/** - * Serialization tests for <code>BasicPermissionCollection</code> - */ - -public class BasicPermissionCollectionTest extends SerializationTest { - - protected Object[] getData() { - - PermissionCollection c1 = new MyBasicPermission("234") - .newPermissionCollection(); - - PermissionCollection c2 = new MyBasicPermission("1.4.kjhgj.*") - .newPermissionCollection(); - c2.add(new MyBasicPermission("1.4.kjhgj.sdlvjb3o4i578")); - c2.add(new MyBasicPermission("1.4")); - - PermissionCollection c3 = new MyBasicPermission("*") - .newPermissionCollection(); - c3.add(new MyBasicPermission("1.4.kjhgj.*")); - - return new Object[] { c1, c2, c3 }; - } -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionTest.java deleted file mode 100644 index 5ea30d9..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionTest.java +++ /dev/null @@ -1,36 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import org.apache.harmony.security.tests.support.MyBasicPermission; -import org.apache.harmony.testframework.serialization.SerializationTest; - -/** - * Serialization tests for <code>BasicPermission</code> - */ - -public class BasicPermissionTest extends SerializationTest { - - protected Object[] getData() { - return new Object[] { new MyBasicPermission("kjhgj") }; - } -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.java deleted file mode 100644 index d46e837..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.java +++ /dev/null @@ -1,193 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamClass; -import java.io.ObjectStreamField; -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.security.cert.CertificateEncodingException; -import java.util.Date; - -import org.apache.harmony.security.tests.support.TestCertUtils; -import org.apache.harmony.testframework.serialization.SerializationTest; - - -/** - * Serialization test for CodeSource. - * - */ - -public class CodeSourceTest extends SerializationTest { - - protected void setUp() throws Exception { - super.setUp(); - TestCertUtils.install_test_x509_factory(); - } - - protected void tearDown() throws Exception { - TestCertUtils.uninstall_test_x509_factory(); - super.tearDown(); - } - - public void testGolden() throws Throwable { - super.testGolden(); - // do special testing to cover Exceptions in the {read/write}Data - - // - // test writeObject() - // - - {//~ - - Certificate[] certs = new Certificate[] { new InvalidX509Certificate_00() }; - CodeSource cs = new CodeSource(null, certs); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - try { - oos.writeObject(cs); - fail("must not be here"); - } - catch( IOException ex ) { - // ok - } - - }//~ - - // - // test readObject - // - {//~ - Certificate[] certs = new Certificate[] { new CertificateOfUnsupportedType() }; - CodeSource cs = new CodeSource(null, certs); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - - oos.writeObject(cs); - - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); - - try { - ois.readObject(); - fail("must not pass here"); - } - catch(ClassNotFoundException ex) { - // ok - } - }//~ - - // test readObject, force the CertFactory to throw an Exception from - // inside the generateCertificate - - {//~ - Certificate[] certs = new Certificate[] { new InvalidX509Certificate_01() }; - CodeSource cs = new CodeSource(null, certs); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - - oos.writeObject(cs); - - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); - - try { - ois.readObject(); - fail("must not pass here"); - } - catch(IOException ex) { - // ok - } - }//~ - } - - private class InvalidX509Certificate_00 extends TestCertUtils.TestX509Certificate { - InvalidX509Certificate_00() { - super(TestCertUtils.rootPrincipal, TestCertUtils.rootPrincipal); - } - public byte[] getEncoded() throws CertificateEncodingException { - // simply throw an exception - throw new CertificateEncodingException("CEE"); - } - } - - private class InvalidX509Certificate_01 extends TestCertUtils.TestX509Certificate { - InvalidX509Certificate_01() { - super(TestCertUtils.rootPrincipal, TestCertUtils.rootPrincipal); - } - public byte[] getEncoded() throws CertificateEncodingException { - // this is invalid encoding for TestX509Certificate - return new byte[] {1,2,3,4,5}; - } - } - - - private class CertificateOfUnsupportedType extends TestCertUtils.TestCertificate { - CertificateOfUnsupportedType() { - super(null, "this is indeed unsupported type of certificates. I do believe so."); - } - } - - protected Object[] getData() { - URL url; - CodeSigner[] signers = null; - CertPath cpath = TestCertUtils.getCertPath(); - Date now = new Date(); - Timestamp ts = new Timestamp(now, cpath); - - try { - url = new URL("http://localhost"); - signers = new CodeSigner[] { new CodeSigner(cpath, ts) }; - } catch (Exception ex) { - throw new Error(ex); - } - Certificate[] x509chain = new Certificate[] { - TestCertUtils.rootCA - }; - - Object[] data = new Object[] { - new CodeSource(url, (Certificate[])null), - new CodeSource(url, new Certificate[0]), - new CodeSource(url, signers), - new CodeSource(null, x509chain), - }; - return data; - } - - public void testSerilizationDescriptor() throws Exception { - - // Regression for HARMONY-2787 - ObjectStreamClass objectStreamClass = ObjectStreamClass - .lookup(CodeSource.class); - ObjectStreamField objectStreamField = objectStreamClass - .getField("location"); - assertEquals("Ljava/net/URL;", objectStreamField.getTypeString()); - } -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.java deleted file mode 100644 index 2d15b41..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.java +++ /dev/null @@ -1,40 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import org.apache.harmony.security.tests.support.MyPermissionCollection; -import org.apache.harmony.testframework.serialization.SerializationTest; - -/** - * Serialization tests for <code>PermissionCollection</code> - */ - -public class PermissionCollectionTest extends SerializationTest { - - /** - * @see com.intel.drl.test.SerializationTest#getData() - */ - protected Object[] getData() { - return new Object[] { new MyPermissionCollection(false), - new MyPermissionCollection(true) }; - } -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.java deleted file mode 100644 index 0671548..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.java +++ /dev/null @@ -1,40 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import org.apache.harmony.security.tests.support.MyPermission; -import org.apache.harmony.testframework.serialization.SerializationTest; - -/** - * Serialization tests for <code>Permission</code> - */ - -public class PermissionTest extends SerializationTest { - - /** - * @see com.intel.drl.test.SerializationTest#getData() - */ - protected Object[] getData() { - return new Object[] { new MyPermission(null), - new MyPermission("IYF&*%^sd 43") }; - } -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.java deleted file mode 100644 index 7097444..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.java +++ /dev/null @@ -1,49 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import java.security.AllPermission; -import java.security.Permissions; -import java.security.SecurityPermission; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - -/** - * Serialization tests for <code>Permissions</code> - * - */ - -public class PermissionsTest extends SerializationTest { - - /** - * Returns array containing empty and non-empty Permissions. - */ - protected Object[] getData() { - Permissions ps = new Permissions(); - - ps.add(new AllPermission()); - ps.add(new SecurityPermission("abc")); - - return new Object[] { new Permissions(), ps }; - } -} diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.java deleted file mode 100644 index 5177a0a..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.java +++ /dev/null @@ -1,43 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import java.security.SecurityPermission; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - -/** - * Serialization tests for <code>SecurityPermission</code> - * - */ - -public class SecurityPermissionTest extends SerializationTest { - - /** - * @see com.intel.drl.test.SerializationTest#getData() - */ - protected Object[] getData() { - return new Object[] { new SecurityPermission("%&#C"), - new SecurityPermission("jlkhb.3465.*", "sf"), }; - } -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.java deleted file mode 100644 index 9c691f1..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.java +++ /dev/null @@ -1,58 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.UnresolvedPermission; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashSet; - -import org.apache.harmony.testframework.serialization.SerializationTest; - - -/** - * Serialization tests for <code>UnresolvedPermissionCollection</code> - * - */ -public class UnresolvedPermissionCollectionTest extends SerializationTest { - - /** - * Return array holding 3 collections: empty, single- and multi-element. - */ - protected Object[] getData() { - Permission up1 = new UnresolvedPermission("131234", null, null, null); - Permission up2 = new UnresolvedPermission("131234", "ui23rjh", null, - null); - Permission up3 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456", - "26r ytf", new java.security.cert.Certificate[0]); - PermissionCollection pc1 = up1.newPermissionCollection(); - PermissionCollection pc2 = up1.newPermissionCollection(); - pc2.add(up3); - PermissionCollection pc3 = up1.newPermissionCollection(); - pc3.add(up1); - pc3.add(up2); - pc3.add(up3); - return new Object[] { pc1, pc2, pc3 }; - } -}
\ No newline at end of file diff --git a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.java b/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.java deleted file mode 100644 index 01565b2..0000000 --- a/security/src/test/api/java/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.java +++ /dev/null @@ -1,66 +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 -*/ - -package org.apache.harmony.security.tests.java.security.serialization; - -import java.io.ByteArrayInputStream; -import java.security.UnresolvedPermission; -import java.security.cert.Certificate; -import java.security.cert.CertificateFactory; - -import org.apache.harmony.security.tests.support.cert.TestUtils; -import org.apache.harmony.testframework.serialization.SerializationTest; - - - -/** - * Serialization tests for <code>UnresolvedPermission</code> - * - */ - -public class UnresolvedPermissionTest extends SerializationTest { - - /** - * @see com.intel.drl.test.SerializationTest#getData() - */ - protected Object[] getData() { - // test with real certificates ? - return new Object[] { - new UnresolvedPermission("type", "name", "actions", null), - new UnresolvedPermission("type", null, null, new Certificate[0]) }; - } - - public void testSerializationWithCertificates() throws Exception { - - // Regression for HARMONY-2762 - CertificateFactory certificateFactory = CertificateFactory - .getInstance("X.509"); - Certificate certificate = certificateFactory - .generateCertificate(new ByteArrayInputStream(TestUtils - .getEncodedX509Certificate())); - - UnresolvedPermission unresolvedPermission = new UnresolvedPermission( - "java.security.SecurityPermission", "a.b.c", "action", - new Certificate[] { certificate }); - SerializationTest.verifySelf(unresolvedPermission); - SerializationTest.verifyGolden(this, unresolvedPermission); - } -} diff --git a/security/src/test/api/java/tests/api/java/security/PermissionCollectionTest.java b/security/src/test/api/java/tests/api/java/security/PermissionCollectionTest.java deleted file mode 100644 index f18fede..0000000 --- a/security/src/test/api/java/tests/api/java/security/PermissionCollectionTest.java +++ /dev/null @@ -1,241 +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.security; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.net.URL; -import java.security.PermissionCollection; -import java.security.SecurityPermission; -import java.util.StringTokenizer; - -import tests.support.Support_Exec; -import tests.support.Support_GetLocal; -import tests.support.resource.Support_Resources; - -public class PermissionCollectionTest extends junit.framework.TestCase { - - // The below test is known to fail. Haven't got to the bottom of - // it yet but here is what has been determined :- - // - // * the Support_PermissionCollection application that is forked off - // near the end of this test needs to verify a signed jar (signedBKS.jar). - // This means that com.ibm.oti.util.JarUtils.verifySignature() ends up - // getting called. But at present that exists as just a lightweight/stub - // implementation which simply returns NULL. That behaviour causes a - // security exception inside java.util.jar.JarVerifier. - // - // * the above problem was fixed by rebuilding Harmony with the STUB - // IMPLEMENTATION of com.ibm.oti.util.JarUtils.verifySignature() replaced - // with one that delegates to - // org.apache.harmony.security.utils.JarUtils.verifySignature(). - // - // * unfortunately, a NPE is raised in line 103 of Harmony's JarUtils class. - // - // * the cause of that NPE has still not been determined. Could it be - // related to Harmony's current stub implementation of BigInteger ? - /** - * @tests java.security.PermissionCollection#implies(java.security.Permission) - */ - public void test_impliesLjava_security_Permission() throws Exception{ - - // Look for the tests classpath - URL classURL = this.getClass().getProtectionDomain().getCodeSource().getLocation(); - assertNotNull("Could not get this class' location", classURL); - - File policyFile = Support_GetLocal.createTempFile(".policy"); - policyFile.deleteOnExit(); - - URL signedBKS = getResourceURL("PermissionCollection/signedBKS.jar"); - String signedBKSPath = new File(signedBKS.getFile()).getCanonicalPath(); - signedBKSPath = signedBKSPath.replace('\\', '/'); - URL keystoreBKS = getResourceURL("PermissionCollection/keystore.bks"); - - // Create the policy file (and save the existing one if any) - FileOutputStream fileOut = null; - try { - fileOut = new FileOutputStream(policyFile); - String linebreak = System.getProperty("line.separator"); - StringBuilder towrite = new StringBuilder(); - towrite.append("grant {"); - towrite.append(linebreak); - towrite.append(" permission java.io.FilePermission \""); - towrite.append(signedBKSPath); - towrite.append("\", \"read\";"); - towrite.append(linebreak); - towrite.append(" permission java.lang.RuntimePermission \"getProtectionDomain\";"); - towrite.append(linebreak); - towrite.append(" permission java.security.SecurityPermission \"getPolicy\";"); - towrite.append(linebreak); - towrite.append("};"); - towrite.append(linebreak); - towrite.append(linebreak); - towrite.append("grant codeBase \""); - towrite.append(signedBKS.toExternalForm()); - towrite.append("\" signedBy \"eleanor\" {"); - towrite.append(linebreak); - towrite.append(" permission java.io.FilePermission \"test1.txt\", \"write\";"); - towrite.append(linebreak); - towrite.append(" permission mypackage.MyPermission \"essai\", signedBy \"eleanor,dylan\";"); - towrite.append(linebreak); - towrite.append("};"); - towrite.append(linebreak); - towrite.append(linebreak); - towrite.append("grant codeBase \""); - towrite.append(signedBKS.toExternalForm()); - towrite.append("\" signedBy \"eleanor\" {"); - towrite.append(linebreak); - towrite.append(" permission java.io.FilePermission \"test2.txt\", \"write\";"); - towrite.append(linebreak); - towrite.append("};"); - towrite.append(linebreak); - towrite.append(linebreak); - towrite.append("grant codeBase \""); - towrite.append(classURL.toExternalForm()); - towrite.append("\" {"); - towrite.append(linebreak); - towrite.append(" permission java.security.AllPermission;"); - towrite.append(linebreak); - towrite.append("};"); - towrite.append(linebreak); - towrite.append(linebreak); - towrite.append("keystore \""); - towrite.append(keystoreBKS.toExternalForm()); - towrite.append("\",\"BKS\";"); - towrite.append(linebreak); - fileOut.write(towrite.toString().getBytes()); - fileOut.flush(); - } finally { - if (fileOut != null) { - fileOut.close(); - } - } - - // Copy mypermissionBKS.jar to the user directory so that it can be put - // in the classpath. - File jarFile = null; - FileOutputStream fout = null; - InputStream jis = null; - try { - jis = Support_Resources.getResourceStream("PermissionCollection/mypermissionBKS.jar"); - jarFile = Support_GetLocal.createTempFile(".jar"); - jarFile.deleteOnExit(); - fout = new FileOutputStream(jarFile); - int c = jis.read(); - while (c != -1) { - fout.write(c); - c = jis.read(); - } - fout.flush(); - } finally { - if (fout != null) { - fout.close(); - } - if (jis != null) { - jis.close(); - } - } - - String classPath = new File(classURL.getFile()).getPath(); - - // Execute Support_PermissionCollection in another VM - String[] classPathArray = new String[2]; - classPathArray[0] = classPath; - classPathArray[1] = jarFile.getPath(); - String[] args = { "-Djava.security.policy=" + policyFile.toURL(), - "tests.support.Support_PermissionCollection", - signedBKS.toExternalForm() }; - - String result = Support_Exec.execJava(args, classPathArray, true); - - StringTokenizer resultTokenizer = new StringTokenizer(result, ","); - - // Check the test result from the new VM process - assertEquals("Permission should be granted for test1.txt", "true", resultTokenizer.nextToken()); - assertEquals("Signed Permission should be granted for my permission", "true", resultTokenizer.nextToken()); - assertEquals("signed Permission should be granted for text2.txt", "true", resultTokenizer.nextToken()); - assertEquals("Permission should not be granted for text3.txt", "false", resultTokenizer.nextToken()); - } - - /** - * @tests java.security.PermissionCollection#PermissionCollection() - */ - public void test_Constructor() { - // test java.security.permissionCollection.PermissionCollection() - SecurityPermission permi = new SecurityPermission( - "testing permissionCollection-isReadOnly"); - PermissionCollection permCollect = permi.newPermissionCollection(); - assertNotNull("creat permissionCollection constructor returned a null", - permCollect); - } - - /** - * @tests java.security.PermissionCollection#isReadOnly() - */ - public void test_isReadOnly() { - // test java.security.permissionCollection.isReadOnly() - SecurityPermission permi = new SecurityPermission( - "testing permissionCollection-isREadOnly"); - PermissionCollection permCollect = permi.newPermissionCollection(); - assertTrue("readOnly has not been set, but isReadOnly returned true", - !permCollect.isReadOnly()); - permCollect.setReadOnly(); - assertTrue("readOnly is set, but isReadonly returned false", - permCollect.isReadOnly()); - } - - /** - * @tests java.security.PermissionCollection#setReadOnly() - */ - public void test_setReadOnly() { - // test java.security.permissionCollection.setReadOnly() - SecurityPermission permi = new SecurityPermission( - "testing permissionCollection-setReadOnly"); - PermissionCollection permCollect = permi.newPermissionCollection(); - assertTrue("readOnly has not been set, but isReadOnly returned true", - !permCollect.isReadOnly()); - permCollect.setReadOnly(); - assertTrue("readOnly is set, but isReadonly returned false", - permCollect.isReadOnly()); - } - - /** - * @tests java.security.PermissionCollection#toString() - */ - public void test_toString() { - // test java.security.permissionCollection.toString() - SecurityPermission permi = new SecurityPermission( - "testing permissionCollection-isREadOnly"); - assertNotNull("toString should have returned a string of elements", - permi.newPermissionCollection().toString()); - assertTrue(permi.newPermissionCollection().toString().endsWith("\n")); - } - - // FIXME move me to Support_Resources - public static URL getResourceURL(String name) { - - URL url = ClassLoader.getSystemClassLoader().getResource(name); - - if (url == null) { - throw new RuntimeException("Failed to get resource url: " + name); - } - - return url; - } -}
\ No newline at end of file diff --git a/security/src/test/impl/java.injected/java/security/AllPermissionCollection_ImplTest.java b/security/src/test/impl/java.injected/java/security/AllPermissionCollection_ImplTest.java deleted file mode 100644 index a483c9f..0000000 --- a/security/src/test/impl/java.injected/java/security/AllPermissionCollection_ImplTest.java +++ /dev/null @@ -1,112 +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 -*/ - -package java.security; - -import java.util.Enumeration; -import java.util.NoSuchElementException; - -import junit.framework.TestCase; - - -/** - * Tests for <code>AllPermissionCollection</code> - * - */ - -public class AllPermissionCollection_ImplTest extends TestCase { - - /** - * Empty collection implies nothing, non-empty collection implies - * everything. - */ - public void testImplies() { - PermissionCollection pc = new AllPermissionCollection(); - Permission ap = new AllPermission(); - Permission sp = new SecurityPermission("abc"); - assertFalse(pc.implies(ap)); - assertFalse(pc.implies(sp)); - pc.add(ap); - assertTrue(pc.implies(ap)); - assertTrue(pc.implies(sp)); - } - - /** - * Can add any number of AllPermission instances, but no any other - * permissions. Cannot add if collection is read-only. - */ - public void testAdd() { - PermissionCollection pc = new AllPermissionCollection(); - Permission ap = new AllPermission(); - Permission sp = new SecurityPermission("abc"); - try { - pc.add(sp); - fail("Should not add non-AllPermission"); - } catch (IllegalArgumentException ok) { - } - pc.add(ap); - pc.add(ap); - pc.add(new AllPermission()); - - pc.setReadOnly(); - try { - pc.add(ap); - 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 1-element enumeration. - */ - public void testElements() { - PermissionCollection pc = new AllPermissionCollection(); - Permission ap = new AllPermission(); - Enumeration en = pc.elements(); - assertNotNull(en); - assertFalse(en.hasMoreElements()); - - pc.add(ap); - en = pc.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(ap.equals(en.nextElement())); - assertFalse(en.hasMoreElements()); - - ap = new AllPermission(); - pc.add(ap); - en = pc.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(ap.equals(en.nextElement())); - assertFalse(en.hasMoreElements()); - } - - /** - * If nothing to enumerate, should throw NoSuchElementException - */ - public void testElements_NoElements() { - PermissionCollection pc = new AllPermissionCollection(); - try { - pc.elements().nextElement(); - fail("should throw NoSuchElementException"); - } catch (NoSuchElementException ok) {} - } -} diff --git a/security/src/test/impl/java.injected/java/security/BasicPermissionCollection_ImplTest.java b/security/src/test/impl/java.injected/java/security/BasicPermissionCollection_ImplTest.java deleted file mode 100644 index a2ac249..0000000 --- a/security/src/test/impl/java.injected/java/security/BasicPermissionCollection_ImplTest.java +++ /dev/null @@ -1,214 +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 -*/ - -package java.security; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Enumeration; - -import junit.framework.TestCase; - - -/** - * Tests for <code>BasicPermissionCollection</code> - * - */ - -public class BasicPermissionCollection_ImplTest extends TestCase { - - /** - * Can add only BasicPermissions of the same type as the first added. Cannot - * add if collection is read-only. - */ - public void testAdd() { - PermissionCollection pc = new BasicPermissionCollection(); - Permission ap = new AllPermission(); - Permission sp1 = new SecurityPermission("a.b.c"); - Permission sp2 = new SecurityPermission("a.b.*"); - try { - pc.add(ap); - fail("Should not add non-BasicPermission"); - } catch (IllegalArgumentException ok) { - } - pc.add(sp1); - pc.add(sp2); - try { - pc.add(new BasicPermission("123") { - }); - fail("Should not add BasicPermission of different type"); - } catch (IllegalArgumentException ok) { - } - - pc.setReadOnly(); - try { - pc.add(sp1); - fail("read-only flag is ignored"); - } catch (SecurityException ok) { - } - } - - /** - * Empty collection implies nothing. Non-empty collection should imply all - * contained permissions, and should consider contained wildcards (if any). - */ - public void testImplies() { - PermissionCollection pc = new BasicPermissionCollection(); - Permission ap = new AllPermission(); - Permission up = new UnresolvedPermission("safds", null, null, null); - Permission sp1 = new SecurityPermission("a.b.c"); - Permission sp11 = new SecurityPermission("a.b."); - Permission sp2 = new SecurityPermission("a.b.*"); - Permission sp3 = new SecurityPermission("a.*"); - Permission sp4 = new SecurityPermission("*"); - - assertFalse(pc.implies(ap)); - assertFalse(pc.implies(up)); - assertFalse(pc.implies(sp1)); - - pc.add(sp3); - assertTrue(pc.implies(sp2)); - assertTrue(pc.implies(sp1)); - assertTrue(pc.implies(sp11)); - assertTrue(pc.implies(sp3)); - assertFalse(pc.implies(sp4)); - - pc.add(sp4); - assertTrue(pc.implies(sp4)); - assertFalse(pc.implies(ap)); - assertFalse(pc.implies(up)); - assertTrue(pc.implies(new SecurityPermission("skjdnkwje wefkwjef"))); - } - - /** - * Should return non-null empty enumeration for empty collection. For - * non-empty collection, should always return enumeration over unique - * elements. - */ - public void testElements() { - PermissionCollection pc = new BasicPermissionCollection(); - Permission sp1 = new SecurityPermission("a.b.c"); - Permission sp2 = new SecurityPermission("a.b.*"); - Permission sp3 = new SecurityPermission("*"); - Enumeration en = pc.elements(); - assertNotNull(en); - assertFalse(en.hasMoreElements()); - - try { - pc.add(null); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - - pc.add(sp1); - en = pc.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(sp1.equals(en.nextElement())); - assertFalse(en.hasMoreElements()); - - pc.add(sp1); - en = pc.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(sp1.equals(en.nextElement())); - assertFalse(en.hasMoreElements()); - - pc.add(sp3); - pc.add(sp2); - en = pc.elements(); - Collection els = new ArrayList(); - while (en.hasMoreElements()) { - els.add(en.nextElement()); - } - assertEquals(3, els.size()); - assertTrue(els.containsAll(Arrays.asList(new Permission[] { - sp1, sp2, sp3 }))); - } - - /** - * test on deserialization of incorrect object - */ - public void testNegDeserialization_01() throws Exception { - - SecurityPermission sp = new SecurityPermission("a.b.c"); - BasicPermissionCollection pc = new BasicPermissionCollection(); - pc.add(sp); - setField(pc, "permClass", BasicPermission.class); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(pc); - oos.flush(); - - ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream( - baos.toByteArray())); - try { - in.readObject(); - fail("should throw InvalidObjectException"); - } catch (java.io.InvalidObjectException e) { - } finally { - oos.close(); - in.close(); - } - } - - /** - * test on deserialization of incorrect object - */ - public void testNegDeserialization_02() throws Exception { - - SecurityPermission sp = new SecurityPermission("a.b.c"); - BasicPermissionCollection pc = new BasicPermissionCollection(); - pc.add(sp); - setField(pc, "allEnabled", new Boolean(true)); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(pc); - oos.flush(); - - ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream( - baos.toByteArray())); - try { - in.readObject(); - fail("should throw InvalidObjectException"); - } catch (java.io.InvalidObjectException e) { - } finally { - oos.close(); - in.close(); - } - } - - /** - * setup a private field - */ - private void setField(Object obj, String name, Object newval) - throws Exception { - Field f = obj.getClass().getDeclaredField(name); - f.setAccessible(true); - f.set(obj, newval); - } -} diff --git a/security/src/test/impl/java.injected/java/security/UnresolvedPermissionCollection_ImplTest.java b/security/src/test/impl/java.injected/java/security/UnresolvedPermissionCollection_ImplTest.java deleted file mode 100644 index 4401a07..0000000 --- a/security/src/test/impl/java.injected/java/security/UnresolvedPermissionCollection_ImplTest.java +++ /dev/null @@ -1,197 +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 -*/ - -package java.security; - -import java.util.*; - -import junit.framework.TestCase; - - -/** - * Tests for <code>UnresolvedPermissionCollection</code> class fields and methods - * - */ - -public class UnresolvedPermissionCollection_ImplTest extends TestCase { - - /** - * Can add any number of UnresolvedPermission instances, but no any other permissions. - * Cannot add if collection is read-only. - */ - public void testAdd() - { - PermissionCollection pc = new UnresolvedPermissionCollection(); - 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]); - - try { - pc.add(sp); - fail("Should not add non-UnresolvedPermission"); - } - catch (IllegalArgumentException ok) {} - - pc.add(up1); - pc.add(up1); - pc.add(up2); - - pc.setReadOnly(); - try { - pc.add(up1); - fail("read-only flag is ignored"); - } - catch (SecurityException ok) {} - } - - /** This collection never implies any permission. */ - public void testImplies() - { - Permission ap = new AllPermission(); - Permission up = new UnresolvedPermission("131234", null, null, null); - PermissionCollection pc = up.newPermissionCollection(); - - assertFalse(pc.implies(ap)); - assertFalse(pc.implies(up)); - - //pc.add(up); - //assertFalse(pc.implies(up)); - } - - /** - * Should return non-null empty enumeration for empty collection. - * For non-empty collection, should always return enumeration over unique elements. - */ - public void testElements() - { - PermissionCollection pc = new UnresolvedPermissionCollection(); - Permission up1 = new UnresolvedPermission("131234", null, null, null); - Permission up2 = new UnresolvedPermission("131234", "ui23rjh", null, null); - Permission up3 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456", "26r ytf", - new java.security.cert.Certificate[0]); - - Enumeration en = pc.elements(); - assertNotNull(en); - assertFalse(en.hasMoreElements()); - - pc.add(up1); - en = pc.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(up1.equals(en.nextElement())); - assertFalse(en.hasMoreElements()); - - //no check for duplicate elements - this is too implementation specific. - /*pc.add(up1); - en = pc.elements(); - assertTrue(en.hasMoreElements()); - assertTrue(up1.equals(en.nextElement())); - assertFalse(en.hasMoreElements());*/ - - pc.add(up2); - pc.add(up3); - en = pc.elements(); - Collection els = new ArrayList(); - while (en.hasMoreElements()) - { - els.add(en.nextElement()); - } - assertEquals(3, els.size()); - assertTrue(els.contains(up1) && els.contains(up2) && els.contains(up3)); - } - - /** - * For null collection passed, should behave correctly: - * <ul> - * <li>If nothing resolved, returns null and does not remove elements - * <li>If some permission resolved, returns proper collection and removes resolved elements - * </ul> - */ - public void testResolveCollection() - { - UnresolvedPermissionCollection upc = new UnresolvedPermissionCollection(); - Permission up = new UnresolvedPermission("java.security.AllPermission", "xcv456", "26r ytf", - new java.security.cert.Certificate[0]); - Permission ap = new AllPermission(); - Permission bp = new BasicPermission("sfwertsdg"){}; - - PermissionCollection resolved = upc.resolveCollection(ap, null); - assertNull(resolved); - - upc.add(up); - resolved = upc.resolveCollection(bp, null); - assertNull(resolved); - assertTrue(up.equals(upc.elements().nextElement())); - - resolved = upc.resolveCollection(ap, null); - assertNotNull(resolved); - assertTrue(ap.equals(resolved.elements().nextElement())); - assertFalse("resolved permission should be removed from unresolved collection", upc.elements().hasMoreElements()); - } - - /** - * For real collection passed, should behave correctly: - * <ul> - * <li>If nothing resolved, returns the collection and does not remove elements - * <li>If some permission resolved, returns the collection and removes resolved elements - * </ul> - */ - public void testResolveCollectionReturnedCollection() - { - UnresolvedPermissionCollection upc = new UnresolvedPermissionCollection(); - Permission up3 = new UnresolvedPermission("java.security.AllPermission", "xcv456", null, null); - Permission ap = new AllPermission(); - PermissionCollection apc = new AllPermissionCollection(); - - PermissionCollection resolved = upc.resolveCollection(ap, apc); - assertSame("should return the passed collection if it is not null", apc, resolved); - // retest the same for case of actually resolved permission - upc.add(up3); - resolved = upc.resolveCollection(ap, apc); - assertSame("should return the passed collection if it is not null", apc, resolved); - } - - /** - * Test for case when some permissions of the expected type were not resolved for some reason, - * while others were resolved. Returned collection should contain resolved permissions only, - * and the unresolved collection should retain unresolved ones only. - */ - public void testResolveCollectionPartial() - { - UnresolvedPermissionCollection upc = new UnresolvedPermissionCollection(); - String name = "ui23rjh"; - Permission up1 = new UnresolvedPermission("java.security.SecurityPermission", null, null, null); - Permission up2 = new UnresolvedPermission("java.security.SecurityPermission", name, null, null); - Permission sp = new SecurityPermission(name); - - upc.add(up1); - upc.add(up2); - PermissionCollection resolved = upc.resolveCollection(new SecurityPermission("34po5ijh"), null); - assertNotNull(resolved); - Enumeration els = resolved.elements(); - assertTrue(sp.equals(els.nextElement())); - assertFalse(els.hasMoreElements()); - els = upc.elements(); - assertTrue("resolved permission should be removed from unresolved collection", - up1.equals(els.nextElement())); - assertFalse(els.hasMoreElements()); - } -} diff --git a/security/src/test/impl/java.injected/java/security/UnresolvedPermissionTest.java b/security/src/test/impl/java.injected/java/security/UnresolvedPermissionTest.java deleted file mode 100644 index 705d471..0000000 --- a/security/src/test/impl/java.injected/java/security/UnresolvedPermissionTest.java +++ /dev/null @@ -1,40 +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 java.security; - -import junit.framework.TestCase; - -/** - * Tests for <code>UnresolvedPermission</code> class fields and methods - * - */ - -public class UnresolvedPermissionTest extends TestCase { - - /** - * newPermissionCollection() should return new BasicPermissionCollection on every invocation - */ - public void testCollection() - { - UnresolvedPermission up = new UnresolvedPermission("a.b.c", null, null, null); - PermissionCollection pc1 = up.newPermissionCollection(); - PermissionCollection pc2 = up.newPermissionCollection(); - assertTrue((pc1 instanceof UnresolvedPermissionCollection) && (pc2 instanceof UnresolvedPermissionCollection)); - assertNotSame(pc1, pc2); - } -} diff --git a/security/src/test/impl/java.injected/java/security/UnresolvedPermission_ImplTest.java b/security/src/test/impl/java.injected/java/security/UnresolvedPermission_ImplTest.java deleted file mode 100644 index 9fdae07..0000000 --- a/security/src/test/impl/java.injected/java/security/UnresolvedPermission_ImplTest.java +++ /dev/null @@ -1,238 +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 -*/ - -package java.security; - -import java.security.cert.Certificate; - -import junit.framework.TestCase; - -import org.apache.harmony.security.tests.support.cert.MyCertificate; - -/** - * Tests for <code>UnresolvedPermission</code> class fields and methods - * - */ - -public class UnresolvedPermission_ImplTest extends TestCase { - - /** - * This test is valid since 1.5 release only. Checks that UnresolvedPermission returns the proper - * data for target permission. For non-empty certificates array, - * returns a new array each time this method is called. - */ - public void testTargetData() - { - 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.getUnresolvedType()); - assertEquals(name, up.getUnresolvedName()); - assertEquals(action, up.getUnresolvedActions()); - assertNull(up.getUnresolvedCerts()); - } - - public void testEquals() - { - String type = "KJHGUiy 24y"; - String name = "kjhsdkfj "; - String action = "T klj3h4"; - UnresolvedPermission up = new UnresolvedPermission(type, name, action, null); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, null); - assertFalse(up.equals(null)); - assertFalse(up.equals(new Object())); - assertFalse(up.equals(new BasicPermission("df"){})); - assertTrue(up.equals(up)); - assertTrue(up.equals(up2)); - assertTrue(up.hashCode() == up2.hashCode()); - up2 = new UnresolvedPermission(type, name, action, new java.security.cert.Certificate[0]); - assertTrue(up.hashCode() == up2.hashCode()); - up2 = new UnresolvedPermission(type, name, action, new java.security.cert.Certificate[2]); - //case of trivial collections {null} - up = new UnresolvedPermission(type, name, action, new java.security.cert.Certificate[10]); - assertTrue(up.hashCode() == up2.hashCode()); - } - - /** - * resolve the unresolved permission to the permission of specified class. - */ - public void testResolve() - { - String name = "abc"; - UnresolvedPermission up = new UnresolvedPermission("java.security.SecurityPermission", name, null, null); - Permission expected = new SecurityPermission(name); - //test valid input - assertEquals(expected, up.resolve(SecurityPermission.class)); - - //test invalid class - assertNull(up.resolve(Object.class)); - - //test invalid signers - //up = new UnresolvedPermission("java.security.SecurityPermission", name, null, new java.security.cert.Certificate[1]); - //assertNull(up.resolve(SecurityPermission.class)); - - //another valid case - up = new UnresolvedPermission("java.security.AllPermission", null, null, new java.security.cert.Certificate[0]); - assertEquals(new AllPermission(name, ""), up.resolve(AllPermission.class)); - } - - public static final String type = "java.util.PropertyPermission"; - - public static final String name = "os.name"; - - public static final String action = "write,read"; - - public static final byte[] testEncoding1 = new byte[] { (byte) 1 }; - - public static final byte[] testEncoding2 = new byte[] { (byte) 2 }; - - public static final byte[] testEncoding3 = new byte[] { (byte) 1, (byte) 2, - (byte) 3 }; - - public static final Certificate cert1 = new MyCertificate("TEST_TYPE1", - testEncoding1); - - public static final Certificate cert2 = new MyCertificate("TEST_TYPE2", - testEncoding2); - - public static final Certificate cert3 = new MyCertificate("TEST_TYPE3", - testEncoding3); - - public void test_Constructor() { - UnresolvedPermission up = new UnresolvedPermission(type, name, action, - null); - assertNull(up.getUnresolvedCerts()); - - up = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[0]); - assertEquals(0, up.getUnresolvedCerts().length); - - up = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[2]); - assertEquals(2, up.getUnresolvedCerts().length); - } - - public void test_Equals_Scenario0() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - null); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - null); - assertEquals(up1, up2); - } - - public void test_Equals_Scenario1() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - null); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[0]); - assertFalse(up1.equals(up2)); - } - - public void test_Equals_Scenario2() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - null); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[2]); - assertFalse(up1.equals(up2)); - } - - public void test_Equals_Scenario3() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[0]); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[0]); - assertEquals(up1, up2); - } - - public void test_Equals_Scenario4() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[0]); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[2]); - assertFalse(up1.equals(up2)); - } - - public void test_Equals_Scenario5() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[2]); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[5]); - assertFalse(up1.equals(up2)); - } - - public void test_Equals_Scenario6() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1 }); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1 }); - assertEquals(up1, up2); - } - - public void test_Equals_Scenario7() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1, cert2 }); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1, cert2 }); - assertEquals(up1, up2); - } - - public void test_Equals_Scenario8() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1, cert2 }); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert2, cert1 }); - assertEquals(up1, up2); - } - - public void test_Equals_Scenario9() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1, cert2, cert3 }); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert2, cert1, cert3 }); - assertEquals(up1, up2); - } - - public void test_Equals_Scenario10() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[2]); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[2]); - // Non-bug difference, RI throw NPE here. - assertEquals(up1, up2); - } - - public void test_Equals_Scenario11() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1, cert2 }); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1, null, cert2 }); - assertFalse(up1.equals(up2)); - } - - public void test_Equals_Scenario12() { - UnresolvedPermission up1 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1, null, null }); - UnresolvedPermission up2 = new UnresolvedPermission(type, name, action, - new java.security.cert.Certificate[] { cert1, null, cert1 }); - assertEquals(up1, up2); - } -} diff --git a/security/src/test/impl/java.injected/org/apache/harmony/security/DefaultPolicyScannerTest.java b/security/src/test/impl/java.injected/org/apache/harmony/security/DefaultPolicyScannerTest.java deleted file mode 100644 index f11fd84..0000000 --- a/security/src/test/impl/java.injected/org/apache/harmony/security/DefaultPolicyScannerTest.java +++ /dev/null @@ -1,585 +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 -*/ - -package org.apache.harmony.security; - -import java.io.IOException; -import java.io.Reader; -import java.io.StreamTokenizer; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.apache.harmony.security.DefaultPolicyScanner; -import junit.framework.TestCase; - - -/** - * TODO Put your class description here - * - */ - -public class DefaultPolicyScannerTest extends TestCase { - - private static String IO_ERROR = "Failed intentionally"; - - private DefaultPolicyScanner scanner; - - private static StreamTokenizer getST(String sample) { - return new StreamTokenizer(new StringReader(sample)); - } - - private static StreamTokenizer getFailingST(String sample) { - return new StreamTokenizer(new StringReader(sample)) { - - public int nextToken() throws IOException { - throw new IOException(IO_ERROR); - } - }; - } - - protected void setUp() throws Exception { - super.setUp(); - scanner = new DefaultPolicyScanner(); - } - - /** - * Tests tokenization of valid policy sample with all possible elements. - */ - public void testScanStream_Complex() throws Exception { - List grants = new ArrayList(); - List keys = new ArrayList(); - Reader r = new StringReader( - "keystore \"url1\";grant{}KeyStore \"url2\", \"type2\"" - + "keystore \"url3\"\nGRANT signedby \"duke,Li\", " - + "codebase\"\", principal a.b.c \"alias\"{permission XXX \"YYY\", SignedBy \"ZZZ\" \n \t };;;"); - scanner.scanStream(r, grants, keys); - - assertEquals("3 keystores expected", 3, keys.size()); - String[] urls = new String[] { - "url1", "url2", "url3" }; - String[] types = new String[] { - null, "type2", null }; - for (int i = 0; i < 3; i++) { - DefaultPolicyScanner.KeystoreEntry key = (DefaultPolicyScanner.KeystoreEntry)keys - .get(i); - assertEquals(urls[i], key.url); - assertEquals(types[i], key.type); - } - assertEquals("2 grants expected", 2, grants.size()); - DefaultPolicyScanner.GrantEntry ge = (DefaultPolicyScanner.GrantEntry)grants - .get(0); - assertTrue(ge.codebase == null && ge.signers == null - && ge.principals == null && ge.permissions.size() == 0); - - ge = (DefaultPolicyScanner.GrantEntry)grants.get(1); - assertTrue(ge.codebase.equals("") && ge.signers.equals("duke,Li") - && ge.principals.size() == 1 && ge.permissions.size() == 1); - - DefaultPolicyScanner.PrincipalEntry pn = (DefaultPolicyScanner.PrincipalEntry)ge.principals - .iterator().next(); - assertTrue(pn.klass.equals("a.b.c") && pn.name.equals("alias")); - - DefaultPolicyScanner.PermissionEntry pe = (DefaultPolicyScanner.PermissionEntry)ge.permissions - .iterator().next(); - assertTrue(pe.klass.equals("XXX") && pe.name.equals("YYY") - && pe.actions == null && pe.signers.equals("ZZZ")); - } - - public void testScanStream_Empty() throws Exception { - scanner.scanStream(new StringReader(""), new ArrayList(), - new ArrayList()); - } - - /** - * Tests that scanStream() throws InvalidFormatException on invalid - * keywords. - */ - public void testScanStream_Invalid() throws Exception { - List grants = new ArrayList(); - List keys = new ArrayList(); - try { - scanner.scanStream(new StringReader( - "keystore \"url1\"; granted{} grant{}"), grants, keys); - fail("InvalidFormatException is not thrown"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - assertTrue(keys.size() == 1 && grants.size() == 0); - - } - - try { - scanner.scanStream(new StringReader( - "grant{} grant{} keyshop \"url1\"; keystore \"url1\";"), - grants, keys); - fail("InvalidFormatException is not thrown 2"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - assertTrue(keys.size() == 1 && grants.size() == 2); - - } - } - - /** - * Tests that scanStream() throws IOException if stream fails. - */ - public void testScanStream_IOException() throws Exception { - try { - scanner.scanStream(new Reader() { - - public void close() throws IOException { - } - - public int read(char[] cbuf, int off, int count) - throws IOException { - throw new IOException(IO_ERROR); - } - }, new ArrayList(), new ArrayList()); - fail("IOException is intercepted"); - } catch (IOException ok) { - assertEquals(IO_ERROR, ok.getMessage()); - } - } - - /** - * Tests that both handleUnexpectedToken() methods throw proper - * InvalidFormatException exception. - */ - public void testHandleUnexpectedToken() { - try { - scanner.handleUnexpectedToken(getST("")); - fail("InvalidFormatException is not thrown"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - - String message = "bla-bli-blu"; - try { - scanner.handleUnexpectedToken(getST(""), message); - fail("InvalidFormatException is not thrown 2"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - assertNotNull(ok.getMessage()); - assertTrue(ok.getMessage().indexOf(message) >= 0); - } - } - - /** - * Tests readKeystoreEntry() for tokenizing all valid syntax variants. - */ - public void testReadKeystoreEntry() throws Exception { - DefaultPolicyScanner.KeystoreEntry ke = scanner - .readKeystoreEntry(getST("\"URL1\"")); - assertEquals("URL1", ke.url); - assertNull(ke.type); - - ke = scanner.readKeystoreEntry(getST("\"URL2\",\"TYPE2\"")); - assertEquals("URL2", ke.url); - assertEquals("TYPE2", ke.type); - - ke = scanner.readKeystoreEntry(getST("\"URL3\" \"TYPE3\"")); - assertEquals("URL3", ke.url); - assertEquals("TYPE3", ke.type); - } - - /** - * Tests that readKeystoreEntry() throws IOException if stream fails. - */ - public void testReadKeystoreEntry_IOException() throws Exception { - try { - scanner.readKeystoreEntry(getFailingST("")); - fail("IOException is intercepted"); - } catch (IOException ok) { - assertEquals(IO_ERROR, ok.getMessage()); - } - } - - /** - * Tests that readKeystoreEntry() throws InvalidFormatException on invalid - * input - */ - public void testReadKeystoreEntry_Invalid() throws Exception { - try { - scanner.readKeystoreEntry(getST("")); - fail("InvalidFormatException is not thrown 1"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readKeystoreEntry(getST(" ;")); - fail("InvalidFormatException is not thrown 2"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readKeystoreEntry(getST("URL")); - fail("InvalidFormatException is not thrown 3"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - } - - /** - * Tests readPrincipalEntry() for tokenizing all valid syntax variants. - */ - public void testReadPrincipalEntry() throws Exception { - DefaultPolicyScanner.PrincipalEntry pe = scanner - .readPrincipalEntry(getST("\"name1\"")); - assertEquals("name1", pe.name); - assertNull(pe.klass); - - pe = scanner.readPrincipalEntry(getST("a.b.c.d\"name 2\"")); - assertEquals("name 2", pe.name); - assertEquals("a.b.c.d", pe.klass); - - pe = scanner.readPrincipalEntry(getST("* *")); - assertEquals(DefaultPolicyScanner.PrincipalEntry.WILDCARD, pe.name); - assertEquals(DefaultPolicyScanner.PrincipalEntry.WILDCARD, pe.klass); - - pe = scanner.readPrincipalEntry(getST("* \"name3\"")); - assertEquals("name3", pe.name); - assertEquals(DefaultPolicyScanner.PrincipalEntry.WILDCARD, pe.klass); - - pe = scanner.readPrincipalEntry(getST("clazz *")); - assertEquals(DefaultPolicyScanner.PrincipalEntry.WILDCARD, pe.name); - assertEquals("clazz", pe.klass); - - pe = scanner.readPrincipalEntry(getST("\"a, b, c, d\"")); - assertEquals("a,b,c,d", pe.name); - assertNull(pe.klass); - } - - /** - * Tests that readPrincipalEntry() throws InvalidFormatException on invalid - * input - */ - public void testReadPrincipalEntry_Invalid() throws Exception { - try { - scanner.readPrincipalEntry(getST("")); - fail("InvalidFormatException is not thrown 1"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readPrincipalEntry(getST(" ;")); - fail("InvalidFormatException is not thrown 2"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readPrincipalEntry(getST("class")); - fail("InvalidFormatException is not thrown 3"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readPrincipalEntry(getST("class name")); - fail("InvalidFormatException is not thrown 4"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readPrincipalEntry(getST("class, \"name\"")); - fail("InvalidFormatException is not thrown 5"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readPrincipalEntry(getST("* name")); - fail("InvalidFormatException is not thrown 6"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - } - - /** - * Tests that readPrincipalEntry() throws IOException if stream fails. - */ - public void testReadPrincipalEntry_IOException() throws Exception { - try { - scanner.readPrincipalEntry(getFailingST("")); - fail("IOException is intercepted"); - } catch (IOException ok) { - assertEquals(IO_ERROR, ok.getMessage()); - } - } - - /** - * Tests readPermissionEntries() for tokenizing empty list of permissions. - */ - public void testReadPermissionEntries_Empty() throws Exception { - Collection perms = scanner.readPermissionEntries(getST("}")); - assertNotNull(perms); - assertEquals(0, perms.size()); - } - - /** - * Tests readPermissionEntries() for tokenizing all valid syntax variants, - * for just one permission. - */ - public void testReadPermissionEntries_Single() throws Exception { - Collection perms = scanner - .readPermissionEntries(getST("permission a.b.c; }")); - assertEquals(1, perms.size()); - DefaultPolicyScanner.PermissionEntry pe = (DefaultPolicyScanner.PermissionEntry)perms - .iterator().next(); - assertEquals("a.b.c", pe.klass); - assertNull(pe.name); - assertNull(pe.actions); - assertNull(pe.signers); - - perms = scanner - .readPermissionEntries(getST("permission a.b.c \"name1\" }")); - assertEquals(1, perms.size()); - pe = (DefaultPolicyScanner.PermissionEntry)perms.iterator().next(); - assertEquals("a.b.c", pe.klass); - assertEquals("name1", pe.name); - assertNull(pe.actions); - assertNull(pe.signers); - - perms = scanner - .readPermissionEntries(getST("permission a.b.c \"name2\", \"action2\"}")); - assertEquals(1, perms.size()); - pe = (DefaultPolicyScanner.PermissionEntry)perms.iterator().next(); - assertEquals("a.b.c", pe.klass); - assertEquals("name2", pe.name); - assertEquals("action2", pe.actions); - assertNull(pe.signers); - - perms = scanner - .readPermissionEntries(getST("permission a.b.c \"name3\" signedby \"\"}")); - assertEquals(1, perms.size()); - pe = (DefaultPolicyScanner.PermissionEntry)perms.iterator().next(); - assertEquals("a.b.c", pe.klass); - assertEquals("name3", pe.name); - assertNull(pe.actions); - assertEquals("", pe.signers); - - perms = scanner - .readPermissionEntries(getST("permission a.b.c4 ,\"actions4\" SignedBy \"sig4\"}")); - assertEquals(1, perms.size()); - pe = (DefaultPolicyScanner.PermissionEntry)perms.iterator().next(); - assertEquals("a.b.c4", pe.klass); - assertNull(pe.name); - assertEquals("actions4", pe.actions); - assertEquals("sig4", pe.signers); - - perms = scanner - .readPermissionEntries(getST("permission a.b.c5 \"name5\",\"actions5\",signedby \"sig5\";}")); - assertEquals(1, perms.size()); - pe = (DefaultPolicyScanner.PermissionEntry)perms.iterator().next(); - assertEquals("a.b.c5", pe.klass); - assertEquals("name5", pe.name); - assertEquals("actions5", pe.actions); - assertEquals("sig5", pe.signers); - } - - /** - * Tests readPermissionEntries() for tokenizing valid syntax for a list of - * permissions. - */ - public void testReadPermissionEntries_List() throws Exception { - Collection perms = scanner - .readPermissionEntries(getST("permission a.b.c" - + " permission qwerty ,\"aaa\";" - + "permission zzz signedby \"xxx\"}")); - assertEquals(3, perms.size()); - - for (Iterator it = perms.iterator(); it.hasNext();) { - DefaultPolicyScanner.PermissionEntry pe = (DefaultPolicyScanner.PermissionEntry)it - .next(); - if ("a.b.c".equals(pe.klass)) { - assertNull(pe.name); - assertNull(pe.actions); - assertNull(pe.signers); - } else if ("qwerty".equals(pe.klass)) { - assertNull(pe.name); - assertEquals("aaa", pe.actions); - assertNull(pe.signers); - } else if ("zzz".equals(pe.klass)) { - assertNull(pe.name); - assertNull(pe.actions); - assertEquals("xxx", pe.signers); - } else { - fail("Unknown permission reported: " + pe.klass); - } - } - } - - /** - * Tests that readPermissionEntries() throws InvalidFormatException on - * invalid input - */ - public void testReadPermissionEntries_Invalid() throws Exception { - try { - scanner.readPermissionEntries(getST("permission a.b.c")); - fail("InvalidFormatException is not thrown 1"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readPermissionEntries(getST("permission;}")); - fail("InvalidFormatException is not thrown 2"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readPermissionEntries(getST("permission class name}")); - fail("InvalidFormatException is not thrown 3"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readPermissionEntries(getST("permission class ,,}")); - fail("InvalidFormatException is not thrown 4"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner - .readPermissionEntries(getST("permission class \"name\", signedby signers}")); - fail("InvalidFormatException is not thrown 5"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - } - - /** - * Tests that readPermissionEntries() throws IOException if stream fails. - */ - public void testReadPermissionEntries_IOException() throws Exception { - try { - scanner.readPermissionEntries(getFailingST("")); - fail("IOException is intercepted"); - } catch (IOException ok) { - assertEquals(IO_ERROR, ok.getMessage()); - } - } - - /** - * Tests readGrantEntry() for tokenizing all valid syntax variants. - */ - public void testReadGrantEntry_Empty() throws Exception { - DefaultPolicyScanner.GrantEntry ge = scanner.readGrantEntry(getST("")); - assertNull(ge.codebase); - assertNull(ge.codebase); - assertNull(ge.principals); - assertTrue(ge.permissions == null || ge.permissions.isEmpty()); - - ge = scanner.readGrantEntry(getST("{}")); - assertNull(ge.codebase); - assertNull(ge.codebase); - assertNull(ge.principals); - assertTrue(ge.permissions == null || ge.permissions.isEmpty()); - } - - /** - * Tests readGrantEntry() for tokenizing all valid syntax variants. - */ - public void testReadGrantEntry() throws Exception { - DefaultPolicyScanner.GrantEntry ge = scanner - .readGrantEntry(getST("codebase \"u1\" signedby \"s1\";")); - assertEquals("u1", ge.codebase); - assertEquals("s1", ge.signers); - assertNull(ge.principals); - - ge = scanner.readGrantEntry(getST("signedby \"s2\" codebase \"u2\";")); - assertEquals("u2", ge.codebase); - assertEquals("s2", ge.signers); - assertNull(ge.principals); - - ge = scanner.readGrantEntry(getST("signedby \"s2\",signedby \"s3\" " - + " codebase \"u2\",codebase \"u3\";")); - assertEquals("u3", ge.codebase); - assertEquals("s3", ge.signers); - assertNull(ge.principals); - - ge = scanner.readGrantEntry(getST("principal \"a1\" signedby \"s4\" " - + "principal \"a2\", codebase \"u4\";")); - assertEquals("u4", ge.codebase); - assertEquals("s4", ge.signers); - assertNotNull(ge.principals); - assertEquals(2, ge.principals.size()); - - ge = scanner.readGrantEntry(getST("principal * *, principal bbb \"b2\"" - + ", principal ccc \"c2\" codebase \"u5\";")); - assertEquals("u5", ge.codebase); - assertNull(ge.signers); - assertNotNull(ge.principals); - assertEquals(3, ge.principals.size()); - - ge = scanner.readGrantEntry(getST("principal * *" - + ", signedby \"s6\";")); - assertNull(ge.codebase); - assertEquals("s6", ge.signers); - assertNotNull(ge.principals); - assertEquals(1, ge.principals.size()); - } - - /** - * Tests that readGrantEntry() throws InvalidFormatException on invalid - * input - */ - public void testReadGrantEntry_Invalid() throws Exception { - try { - scanner.readGrantEntry(getST("codebase")); - fail("InvalidFormatException is not thrown 1"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readGrantEntry(getST("signedby")); - fail("InvalidFormatException is not thrown 2"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readGrantEntry(getST("signedby *")); - fail("InvalidFormatException is not thrown 3"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readGrantEntry(getST("codebase file://URL")); - fail("InvalidFormatException is not thrown 4"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - try { - scanner.readGrantEntry(getST("codebase \"a2\", signedby \"a2\", " - + "principal a \"a2\", b \"b2\" ")); - fail("InvalidFormatException is not thrown 5"); - } catch (DefaultPolicyScanner.InvalidFormatException ok) { - - } - } - - /** - * Tests that readGrantEntry() throws IOException if stream fails. - */ - public void testReadGrantEntry_IOException() throws Exception { - try { - scanner.readGrantEntry(getFailingST("")); - fail("IOException is intercepted"); - } catch (IOException ok) { - assertEquals(IO_ERROR, ok.getMessage()); - } - } -} diff --git a/security/src/test/impl/java/org/apache/harmony/security/tests/PolicyEntryTest.java b/security/src/test/impl/java/org/apache/harmony/security/tests/PolicyEntryTest.java deleted file mode 100644 index 2ece08f..0000000 --- a/security/src/test/impl/java/org/apache/harmony/security/tests/PolicyEntryTest.java +++ /dev/null @@ -1,315 +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 -*/ - -package org.apache.harmony.security.tests; - -import java.net.URL; -import java.security.cert.Certificate; -import java.security.AllPermission; -import java.security.CodeSource; -import java.security.Permission; -import java.security.Principal; -import java.security.SecurityPermission; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; - -import org.apache.harmony.security.PolicyEntry; -import org.apache.harmony.security.UnresolvedPrincipal; -import junit.framework.TestCase; - - -/** - * TODO Put your class description here - * - */ - -public class PolicyEntryTest extends TestCase { - - /** - * Tests constructor and accessors of PolicyEntry - */ - public void testCtor() { - PolicyEntry pe = new PolicyEntry(null, null, null); - assertTrue(pe.isVoid()); - assertNull(pe.getPermissions()); - - pe = new PolicyEntry(new CodeSource(null, (Certificate[])null), - new ArrayList(), new ArrayList()); - assertTrue(pe.isVoid()); - assertNull(pe.getPermissions()); - - Collection perms = Arrays.asList(new Permission[] { - new SecurityPermission("dsfg"), new AllPermission() }); - pe = new PolicyEntry(null, null, perms); - assertFalse(pe.isVoid()); - assertEquals(perms, new ArrayList(pe.getPermissions())); - } - - /** - * Null CodeSource of PolicyEntry implies any CodeSource; non-null - * CodeSource should delegate to its own imply() functionality - */ - public void testImpliesCodeSource() throws Exception { - CodeSource cs0 = new CodeSource(null, (Certificate[]) null); - - CodeSource cs10 = new CodeSource(new URL("file:"), (Certificate[]) null); - CodeSource cs11 = new CodeSource(new URL("file:/"), (Certificate[]) null); - CodeSource cs12 = new CodeSource(new URL("file://"), (Certificate[]) null); - CodeSource cs13 = new CodeSource(new URL("file:///"), (Certificate[]) null); - - CodeSource cs20 = new CodeSource(new URL("file:*"), (Certificate[]) null); - CodeSource cs21 = new CodeSource(new URL("file:/*"), (Certificate[]) null); - CodeSource cs22 = new CodeSource(new URL("file://*"), (Certificate[]) null); - CodeSource cs23 = new CodeSource(new URL("file:///*"), (Certificate[]) null); - - CodeSource cs30 = new CodeSource(new URL("file:-"), (Certificate[]) null); - CodeSource cs31 = new CodeSource(new URL("file:/-"), (Certificate[]) null); - CodeSource cs32 = new CodeSource(new URL("file://-"), (Certificate[]) null); - CodeSource cs33 = new CodeSource(new URL("file:///-"), (Certificate[]) null); - - PolicyEntry pe0 = new PolicyEntry(null, null, null); - - PolicyEntry pe10 = new PolicyEntry(cs10, null, null); - PolicyEntry pe11 = new PolicyEntry(cs11, null, null); - PolicyEntry pe12 = new PolicyEntry(cs12, null, null); - PolicyEntry pe13 = new PolicyEntry(cs13, null, null); - - PolicyEntry pe20 = new PolicyEntry(cs20, null, null); - PolicyEntry pe21 = new PolicyEntry(cs21, null, null); - PolicyEntry pe22 = new PolicyEntry(cs22, null, null); - PolicyEntry pe23 = new PolicyEntry(cs23, null, null); - - PolicyEntry pe30 = new PolicyEntry(cs30, null, null); - PolicyEntry pe31 = new PolicyEntry(cs31, null, null); - PolicyEntry pe32 = new PolicyEntry(cs32, null, null); - PolicyEntry pe33 = new PolicyEntry(cs33, null, null); - - assertTrue (pe0.impliesCodeSource(null)); - assertTrue (pe0.impliesCodeSource(cs10)); - assertTrue (pe0.impliesCodeSource(cs11)); - assertTrue (pe0.impliesCodeSource(cs12)); - assertTrue (pe0.impliesCodeSource(cs13)); - assertTrue (pe0.impliesCodeSource(cs20)); - assertTrue (pe0.impliesCodeSource(cs21)); - assertTrue (pe0.impliesCodeSource(cs22)); - assertTrue (pe0.impliesCodeSource(cs23)); - assertTrue (pe0.impliesCodeSource(cs30)); - assertTrue (pe0.impliesCodeSource(cs31)); - assertTrue (pe0.impliesCodeSource(cs32)); - assertTrue (pe0.impliesCodeSource(cs33)); - - assertFalse(pe10.impliesCodeSource(null)); - assertTrue (pe10.impliesCodeSource(cs10)); - assertFalse(pe10.impliesCodeSource(cs11)); - assertTrue (pe10.impliesCodeSource(cs12)); - assertFalse(pe10.impliesCodeSource(cs13)); - assertTrue (pe10.impliesCodeSource(cs20)); - assertFalse(pe10.impliesCodeSource(cs21)); - assertFalse(pe10.impliesCodeSource(cs22)); - assertFalse(pe10.impliesCodeSource(cs23)); - assertTrue (pe10.impliesCodeSource(cs30)); - assertFalse(pe10.impliesCodeSource(cs31)); - assertFalse(pe10.impliesCodeSource(cs32)); - assertFalse(pe10.impliesCodeSource(cs33)); - - assertFalse(pe11.impliesCodeSource(null)); - assertFalse(pe11.impliesCodeSource(cs10)); - assertTrue (pe11.impliesCodeSource(cs11)); - assertFalse(pe11.impliesCodeSource(cs12)); - assertTrue (pe11.impliesCodeSource(cs13)); - assertFalse(pe11.impliesCodeSource(cs20)); - assertFalse(pe11.impliesCodeSource(cs21)); - assertFalse(pe11.impliesCodeSource(cs22)); - assertFalse(pe11.impliesCodeSource(cs23)); - assertFalse(pe11.impliesCodeSource(cs30)); - assertFalse(pe11.impliesCodeSource(cs31)); - assertFalse(pe11.impliesCodeSource(cs32)); - assertFalse(pe11.impliesCodeSource(cs33)); - - assertFalse(pe12.impliesCodeSource(null)); - assertTrue (pe12.impliesCodeSource(cs10)); - assertFalse(pe12.impliesCodeSource(cs11)); - assertTrue (pe12.impliesCodeSource(cs12)); - assertFalse(pe12.impliesCodeSource(cs13)); - assertTrue (pe12.impliesCodeSource(cs20)); - assertFalse(pe12.impliesCodeSource(cs21)); - assertFalse(pe12.impliesCodeSource(cs22)); - assertFalse(pe12.impliesCodeSource(cs23)); - assertTrue (pe12.impliesCodeSource(cs30)); - assertFalse(pe12.impliesCodeSource(cs31)); - assertFalse(pe12.impliesCodeSource(cs32)); - assertFalse(pe12.impliesCodeSource(cs33)); - - assertFalse(pe13.impliesCodeSource(null)); - assertFalse(pe13.impliesCodeSource(cs10)); - assertTrue (pe13.impliesCodeSource(cs11)); - assertFalse(pe13.impliesCodeSource(cs12)); - assertTrue (pe13.impliesCodeSource(cs13)); - assertFalse(pe13.impliesCodeSource(cs20)); - assertFalse(pe13.impliesCodeSource(cs21)); - assertFalse(pe13.impliesCodeSource(cs22)); - assertFalse(pe13.impliesCodeSource(cs23)); - assertFalse(pe13.impliesCodeSource(cs30)); - assertFalse(pe13.impliesCodeSource(cs31)); - assertFalse(pe13.impliesCodeSource(cs32)); - assertFalse(pe13.impliesCodeSource(cs33)); - - assertFalse(pe20.impliesCodeSource(null)); - assertTrue (pe20.impliesCodeSource(cs10)); - assertFalse(pe20.impliesCodeSource(cs11)); - assertTrue (pe20.impliesCodeSource(cs12)); - assertFalse(pe20.impliesCodeSource(cs13)); - assertTrue (pe20.impliesCodeSource(cs20)); - assertFalse(pe20.impliesCodeSource(cs21)); - assertFalse(pe20.impliesCodeSource(cs22)); - assertFalse(pe20.impliesCodeSource(cs23)); - assertTrue (pe20.impliesCodeSource(cs30)); - assertFalse(pe20.impliesCodeSource(cs31)); - assertFalse(pe20.impliesCodeSource(cs32)); - assertFalse(pe20.impliesCodeSource(cs33)); - - assertFalse(pe21.impliesCodeSource(null)); - assertFalse(pe21.impliesCodeSource(cs10)); - assertTrue (pe21.impliesCodeSource(cs11)); - assertFalse(pe21.impliesCodeSource(cs12)); - assertTrue (pe21.impliesCodeSource(cs13)); - assertFalse(pe21.impliesCodeSource(cs20)); - assertTrue (pe21.impliesCodeSource(cs21)); - assertFalse(pe21.impliesCodeSource(cs22)); - assertTrue (pe21.impliesCodeSource(cs23)); - assertFalse(pe21.impliesCodeSource(cs30)); - assertTrue (pe21.impliesCodeSource(cs31)); - assertFalse(pe21.impliesCodeSource(cs32)); - assertTrue (pe21.impliesCodeSource(cs33)); - - assertFalse(pe22.impliesCodeSource(null)); - assertFalse(pe22.impliesCodeSource(cs10)); - // assertFalse(pe22.impliesCodeSource(cs11)); - assertFalse(pe22.impliesCodeSource(cs12)); - // assertFalse(pe22.impliesCodeSource(cs13)); - assertFalse(pe22.impliesCodeSource(cs20)); - assertFalse(pe22.impliesCodeSource(cs21)); - assertTrue (pe22.impliesCodeSource(cs22)); - assertFalse(pe22.impliesCodeSource(cs23)); - assertFalse(pe22.impliesCodeSource(cs30)); - assertFalse(pe22.impliesCodeSource(cs31)); - assertTrue (pe22.impliesCodeSource(cs32)); - assertFalse(pe22.impliesCodeSource(cs33)); - - assertFalse(pe23.impliesCodeSource(null)); - assertFalse(pe23.impliesCodeSource(cs10)); - assertTrue (pe23.impliesCodeSource(cs11)); - assertFalse(pe23.impliesCodeSource(cs12)); - assertTrue (pe23.impliesCodeSource(cs13)); - assertFalse(pe23.impliesCodeSource(cs20)); - assertTrue (pe23.impliesCodeSource(cs21)); - assertFalse(pe23.impliesCodeSource(cs22)); - assertTrue (pe23.impliesCodeSource(cs23)); - assertFalse(pe23.impliesCodeSource(cs30)); - assertTrue (pe23.impliesCodeSource(cs31)); - assertFalse(pe23.impliesCodeSource(cs32)); - assertTrue (pe23.impliesCodeSource(cs33)); - - assertFalse(pe30.impliesCodeSource(null)); - assertTrue (pe30.impliesCodeSource(cs10)); - assertFalse(pe30.impliesCodeSource(cs11)); - assertTrue (pe30.impliesCodeSource(cs12)); - assertFalse(pe30.impliesCodeSource(cs13)); - assertTrue (pe30.impliesCodeSource(cs20)); - assertFalse(pe30.impliesCodeSource(cs21)); - assertFalse(pe30.impliesCodeSource(cs22)); - assertFalse(pe30.impliesCodeSource(cs23)); - assertTrue (pe30.impliesCodeSource(cs30)); - assertFalse(pe30.impliesCodeSource(cs31)); - assertFalse(pe30.impliesCodeSource(cs32)); - assertFalse(pe30.impliesCodeSource(cs33)); - - assertFalse(pe31.impliesCodeSource(null)); - assertTrue (pe31.impliesCodeSource(cs10)); - assertTrue (pe31.impliesCodeSource(cs11)); - assertTrue (pe31.impliesCodeSource(cs12)); - assertTrue (pe31.impliesCodeSource(cs13)); - assertTrue (pe31.impliesCodeSource(cs20)); - assertTrue (pe31.impliesCodeSource(cs21)); - assertFalse(pe31.impliesCodeSource(cs22)); - assertTrue (pe31.impliesCodeSource(cs23)); - assertTrue (pe31.impliesCodeSource(cs30)); - assertTrue (pe31.impliesCodeSource(cs31)); - assertFalse(pe31.impliesCodeSource(cs32)); - assertTrue (pe31.impliesCodeSource(cs33)); - - assertFalse(pe32.impliesCodeSource(null)); - assertFalse(pe32.impliesCodeSource(cs10)); - assertFalse(pe32.impliesCodeSource(cs11)); - assertFalse(pe32.impliesCodeSource(cs12)); - assertFalse(pe32.impliesCodeSource(cs13)); - assertFalse(pe32.impliesCodeSource(cs20)); - assertFalse(pe32.impliesCodeSource(cs21)); - assertFalse(pe32.impliesCodeSource(cs22)); - assertFalse(pe32.impliesCodeSource(cs23)); - assertFalse(pe32.impliesCodeSource(cs30)); - assertFalse(pe32.impliesCodeSource(cs31)); - assertTrue (pe32.impliesCodeSource(cs32)); - assertFalse(pe32.impliesCodeSource(cs33)); - - assertFalse(pe33.impliesCodeSource(null)); - assertTrue (pe33.impliesCodeSource(cs10)); - assertTrue (pe33.impliesCodeSource(cs11)); - assertTrue (pe33.impliesCodeSource(cs12)); - assertTrue (pe33.impliesCodeSource(cs13)); - assertTrue (pe33.impliesCodeSource(cs20)); - assertTrue (pe33.impliesCodeSource(cs21)); - assertFalse(pe33.impliesCodeSource(cs22)); - assertTrue (pe33.impliesCodeSource(cs23)); - assertTrue (pe33.impliesCodeSource(cs30)); - assertTrue (pe33.impliesCodeSource(cs31)); - assertFalse(pe33.impliesCodeSource(cs32)); - assertTrue (pe33.impliesCodeSource(cs33)); - } - - /** - * Null or empty set of Principals of PolicyEntry implies any Principals; - * otherwise tested set must contain all Principals of PolicyEntry. - */ - public void testImpliesPrincipals() { - PolicyEntry pe = new PolicyEntry(null, null, null); - Principal[] pp1 = new Principal[] {}; - Principal[] pp2 = new Principal[] { new UnresolvedPrincipal("a.b.c", - "XXX") }; - Principal[] pp3 = new Principal[] { - new UnresolvedPrincipal("a.b.c", "YYY"), - new UnresolvedPrincipal("a.b.c", "XXX"), - new UnresolvedPrincipal("e.f.g", "ZZZ") }; - - assertTrue(pe.impliesPrincipals(null)); - assertTrue(pe.impliesPrincipals(pp1)); - - pe = new PolicyEntry(null, new HashSet(), null); - assertTrue(pe.impliesPrincipals(pp3)); - - pe = new PolicyEntry(null, Arrays.asList(pp2), null); - assertFalse(pe.impliesPrincipals(null)); - assertFalse(pe.impliesPrincipals(pp1)); - assertTrue(pe.impliesPrincipals(pp3)); - } -} diff --git a/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/DefaultPolicyParserTest.java b/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/DefaultPolicyParserTest.java deleted file mode 100644 index a6e5e01..0000000 --- a/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/DefaultPolicyParserTest.java +++ /dev/null @@ -1,104 +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 -*/ - -package org.apache.harmony.security.tests.fortress; - -import java.io.File; -import java.io.FileWriter; -import java.net.URL; -import java.security.CodeSource; -import java.security.Principal; -import java.security.SecurityPermission; -import java.security.cert.Certificate; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.harmony.security.PolicyEntry; -import org.apache.harmony.security.fortress.DefaultPolicyParser; -import junit.framework.TestCase; - - -/** - * Tests for DefaultPolicyParser - * - */ - -public class DefaultPolicyParserTest extends TestCase { - - /** - * Tests parsing of a sample policy from temporary file, validates returned - * PolicyEntries. - */ - public void testParse() throws Exception { - File tmp = File.createTempFile("policy", null); - try { - FileWriter out = new FileWriter(tmp); - out.write("grant{}KeyStore \"url2\", \"type2\" " - + "GRANT signedby \"duke,Li\", codebase\"\", principal a.b.c \"guest\" " - + "{permission XXX \"YYY\", SignedBy \"ZZZ\" \n \t };;;" - + "GRANT codebase\"http://a.b.c/-\", principal * * " - + "{permission java.security.SecurityPermission \"YYY\";}" - + "GRANT {permission java.security.SecurityPermission \"ZZZ\";}" - + "GRANT {permission java.security.UnresolvedPermission \"NONE\";}"); - out.flush(); - out.close(); - - DefaultPolicyParser parser = new DefaultPolicyParser(); - Collection entries = parser.parse(tmp.toURI().toURL(), null); - assertEquals(2, entries.size()); - for (Iterator iter = entries.iterator(); iter.hasNext();) { - PolicyEntry element = (PolicyEntry)iter.next(); - if (element.getPermissions() - .contains(new SecurityPermission("ZZZ"))) { - assertTrue(element.impliesCodeSource(new CodeSource(null, - (Certificate[])null))); - assertTrue(element.impliesPrincipals(null)); - } else if (element.getPermissions() - .contains(new SecurityPermission("YYY"))) { - assertFalse(element.impliesCodeSource(null)); - assertFalse(element.impliesPrincipals(null)); - assertTrue(element.impliesCodeSource(new CodeSource(new URL( - "http://a.b.c/-"), (Certificate[])null))); - assertTrue(element - .impliesPrincipals(new Principal[] { new FakePrincipal( - "qqq") })); - } else { - fail("Extra entry parsed"); - } - } - } finally { - tmp.delete(); - } - } -} - -class FakePrincipal implements Principal { - - private String name; - - public FakePrincipal(String name) { - this.name = name; - } - - public String getName() { - return name; - } -} diff --git a/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/DefaultPolicyTest.java b/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/DefaultPolicyTest.java deleted file mode 100644 index 6d230f3..0000000 --- a/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/DefaultPolicyTest.java +++ /dev/null @@ -1,174 +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 -*/ - -package org.apache.harmony.security.tests.fortress; - -import java.net.URL; -import java.security.cert.Certificate; -import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Principal; -import java.security.ProtectionDomain; -import java.security.SecurityPermission; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Properties; - -import org.apache.harmony.security.PolicyEntry; -import org.apache.harmony.security.UnresolvedPrincipal; -import org.apache.harmony.security.fortress.DefaultPolicy; -import org.apache.harmony.security.fortress.DefaultPolicyParser; -import junit.framework.TestCase; - - -/** - * Tests for DefaultPolicy - * - */ -public class DefaultPolicyTest extends TestCase { - - static class TestParser extends DefaultPolicyParser { - - PolicyEntry[] content; - - public TestParser(PolicyEntry[] content) { - this.content = content; - } - - public Collection parse(URL location, Properties system) - throws Exception { - if (content != null) { - return Arrays.asList(content); - } - throw new RuntimeException(); - } - } - - /** - * Tests that policy is really resetted on refresh(). - */ - public void testRefresh() { - Permission sp = new SecurityPermission("sdf"); - PolicyEntry[] pe = new PolicyEntry[] { new PolicyEntry(null, null, - Arrays.asList(new Permission[] { sp })) }; - TestParser tp = new TestParser(pe); - DefaultPolicy policy = new DefaultPolicy(tp); - CodeSource cs = new CodeSource(null, (Certificate[])null); - assertTrue(policy.getPermissions(cs).implies(sp)); - - tp.content = new PolicyEntry[0]; - policy.refresh(); - assertFalse(policy.getPermissions(cs).implies(sp)); - - tp.content = null; - policy.refresh(); - assertFalse(policy.getPermissions(cs).implies(sp)); - } - - /** - * Tests that refresh() does not fail on failing parser. - */ - public void testRefresh_Failure() { - CodeSource cs = new CodeSource(null, (Certificate[])null); - DefaultPolicy policy = new DefaultPolicy(new TestParser(null)); - policy.refresh(); - assertFalse(policy.getPermissions(cs).elements().hasMoreElements()); - } - - /** - * Tests proper policy evaluation for CodeSource parameters. - */ - public void testGetPermissions_CodeSource() throws Exception { - CodeSource cs = new CodeSource(null, (Certificate[])null); - CodeSource cs2 = new CodeSource(new URL("http://a.b.c"), - (Certificate[])null); - Permission sp1 = new SecurityPermission("aaa"); - Permission sp2 = new SecurityPermission("bbb"); - Permission sp3 = new SecurityPermission("ccc"); - PolicyEntry pe1 = new PolicyEntry(cs, null, Arrays - .asList(new Permission[] { sp1 })); - PolicyEntry pe2 = new PolicyEntry(cs2, new HashSet(), Arrays - .asList(new Permission[] { sp2 })); - PolicyEntry pe3 = new PolicyEntry(cs, Arrays - .asList(new Principal[] { new FakePrincipal("qqq") }), Arrays - .asList(new Permission[] { sp3 })); - PolicyEntry[] peArray = new PolicyEntry[] { - pe1, pe2, pe3 }; - DefaultPolicy policy = new DefaultPolicy(new TestParser(peArray)); - - assertTrue(policy.getPermissions(cs).implies(sp1)); - assertFalse(policy.getPermissions(cs).implies(sp2)); - assertFalse(policy.getPermissions(cs).implies(sp3)); - - assertTrue(policy.getPermissions(cs2).implies(sp1)); - assertTrue(policy.getPermissions(cs2).implies(sp2)); - assertFalse(policy.getPermissions(cs2).implies(sp3)); - } - - /** - * Tests proper policy evaluation for ProtectionDomain parameters. - */ - public void testGetPermissions_ProtectionDomain() throws Exception { - Permission sp1 = new SecurityPermission("aaa"); - Permission sp2 = new SecurityPermission("bbb"); - Permission sp3 = new SecurityPermission("ccc"); - Permission sp4 = new SecurityPermission("ddd"); - Permission spZ = new SecurityPermission("zzz"); - PermissionCollection pcZ = spZ.newPermissionCollection(); - pcZ.add(spZ); - CodeSource cs = new CodeSource(null, (Certificate[])null); - CodeSource cs2 = new CodeSource(new URL("http://a.b.c"), - (Certificate[])null); - ProtectionDomain pd1 = new ProtectionDomain(cs, null); - ProtectionDomain pd2 = new ProtectionDomain(cs2, pcZ, null, - new Principal[] { new FakePrincipal("qqq") }); - - PolicyEntry pe1 = new PolicyEntry(cs, null, Arrays - .asList(new Permission[] { sp1 })); - PolicyEntry pe2 = new PolicyEntry(cs2, Arrays - .asList(new Principal[] { new UnresolvedPrincipal( - UnresolvedPrincipal.WILDCARD, UnresolvedPrincipal.WILDCARD) }), - Arrays.asList(new Permission[] { sp2 })); - PolicyEntry pe3 = new PolicyEntry(cs, Arrays - .asList(new Principal[] { new UnresolvedPrincipal( - FakePrincipal.class.getName(), "qqq") }), Arrays - .asList(new Permission[] { sp3 })); - PolicyEntry pe4 = new PolicyEntry(cs2, Arrays - .asList(new Principal[] { new UnresolvedPrincipal( - FakePrincipal.class.getName(), "ttt") }), Arrays - .asList(new Permission[] { sp4 })); - PolicyEntry[] peArray = new PolicyEntry[] { - pe1, pe2, pe3, pe4 }; - DefaultPolicy policy = new DefaultPolicy(new TestParser(peArray)); - - assertTrue(policy.getPermissions(pd1).implies(sp1)); - assertFalse(policy.getPermissions(pd1).implies(sp2)); - assertFalse(policy.getPermissions(pd1).implies(sp3)); - assertFalse(policy.getPermissions(pd1).implies(sp4)); - - assertTrue(policy.getPermissions(pd2).implies(sp1)); - assertTrue(policy.getPermissions(pd2).implies(sp2)); - assertTrue(policy.getPermissions(pd2).implies(sp3)); - assertFalse(policy.getPermissions(pd2).implies(sp4)); - } -} diff --git a/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/PolicyUtilsTest.java b/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/PolicyUtilsTest.java deleted file mode 100644 index 8208f59..0000000 --- a/security/src/test/impl/java/org/apache/harmony/security/tests/fortress/PolicyUtilsTest.java +++ /dev/null @@ -1,330 +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 -*/ - -package org.apache.harmony.security.tests.fortress; - -import java.io.File; -import java.net.URL; -import java.security.AllPermission; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Security; -import java.security.SecurityPermission; -import java.security.UnresolvedPermission; -import java.util.Arrays; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Properties; - -import org.apache.harmony.security.fortress.PolicyUtils; -import junit.framework.TestCase; - - -/** - * Tests for <code>PolicyUtils</code> class fields and methods. - * - */ - -public class PolicyUtilsTest extends TestCase { - - /** Tests valid expansion of ${key} entries. */ - public void testExpand() throws Exception { - String[] input = new String[] { "${key.1}", "abcd${key.1}", - "a ${key.1} b ${$key$}${key.2}", "$key.1", "${}" }; - String[] output = new String[] { "value1", "abcdvalue1", - "a value1 b ${${${${${${value.2", "$key.1", "" }; - Properties props = new Properties(); - props.put("key.1", "value1"); - props.put("key.2", "value.2"); - props.put("$key$", "${${${${${${"); - props.put("", ""); - for (int i = 0; i < output.length; i++) { - assertEquals(output[i], PolicyUtils.expand(input[i], props)); - } - } - - /** Tests ExpansionFailedException for missing keys of ${key} entries. */ - public void testExpandFailed() throws Exception { - try { - PolicyUtils.expand("${key.123}", new Properties()); - fail("Should throw ExpansionFailedException"); - } - catch (PolicyUtils.ExpansionFailedException ok) {} - } - - /** Tests valid URL-specific expansion. */ - public void testExpandURL() throws Exception { - String input = "file:/${my.home}" + File.separator + "lib/extensions/"; - Properties props = new Properties(); - String q = File.separator + "drl" + File.separator + "tools1.2"; - props.put("my.home", q); - assertEquals("file://drl/tools1.2/lib/extensions/", PolicyUtils.expandURL(input, - props)); - } - - /** Tests valid expansion of ${{protocol:data}} entries. */ - public void testExpandGeneral() throws Exception { - String[] input = new String[] { "${{a:b}}", "a ${{self}}${{a: made}}", - "${{}}" }; - String[] output = new String[] { "b", "a this made", "" }; - PolicyUtils.GeneralExpansionHandler handler = new PolicyUtils.GeneralExpansionHandler() { - - public String resolve(String protocol, String data) { - if ("a".equals(protocol)) { - return data; - } - if ("self".equals(protocol)) { - return "this"; - } - if ("".equals(protocol)) { - return protocol; - } - return null; - } - }; - for (int i = 0; i < output.length; i++) { - assertEquals(output[i], PolicyUtils - .expandGeneral(input[i], handler)); - } - } - - /** - * Tests ExpansionFailedException for undefined protocol - * of ${{protocol:data}} entries. - */ - public void testExpandGeneralFailed() throws Exception { - try { - PolicyUtils.expandGeneral("${{c}}", - new PolicyUtils.GeneralExpansionHandler() { - - public String resolve(String protocol, String data) - throws PolicyUtils.ExpansionFailedException { - throw new PolicyUtils.ExpansionFailedException(""); - } - }); - fail("Should throw ExpansionFailedException"); - } - catch (PolicyUtils.ExpansionFailedException ok) {} - } - - /** - * Tests positive/negative/invalid/missing values of - * "policy.expandProperties" security property. - */ - public void testCanExpandProperties() { - final String key = "policy.expandProperties"; - String OLD = Security.getProperty(key); - try { - Security.setProperty(key, "true"); - assertTrue(PolicyUtils.canExpandProperties()); - Security.setProperty(key, "false"); - assertFalse(PolicyUtils.canExpandProperties()); - Security.setProperty(key, ""); - assertTrue(PolicyUtils.canExpandProperties()); - Security.setProperty(key, "laejhg"); - assertTrue(PolicyUtils.canExpandProperties()); - } - finally { - Security.setProperty(key, OLD); - } - } - - /** - * Tests cases of enabled/disabled system URL. - */ - public void testGetPolicyURLs01() throws Throwable { - final String KEY_DYNAMIC = "policy.allowSystemProperty"; - String OLD_DYNAMIC = Security.getProperty(KEY_DYNAMIC); - - final String KEY = "dsfvdf"; - Properties arg = new Properties(); - arg.put(KEY, "http://foo.bar.com"); - try { - Security.setProperty(KEY_DYNAMIC, "true"); - URL[] result = PolicyUtils.getPolicyURLs(arg, KEY, ""); - assertNotNull(result); - assertEquals(1, result.length); - assertEquals(new URL("http://foo.bar.com"), result[0]); - - Security.setProperty(KEY_DYNAMIC, "false"); - result = PolicyUtils.getPolicyURLs(arg, KEY, ""); - assertNotNull(result); - assertEquals(0, result.length); - - Security.setProperty(KEY_DYNAMIC, ""); - result = PolicyUtils.getPolicyURLs(arg, KEY, ""); - assertNotNull(result); - assertEquals(1, result.length); - assertEquals(new URL("http://foo.bar.com"), result[0]); - } - finally { - Security.setProperty(KEY_DYNAMIC, OLD_DYNAMIC); - } - } - - /** Tests finding algorithm for numbered locations in security properties. */ - public void testGetPolicyURLs02() throws Throwable { - final String PREFIX = "testGetPolicyURLs02."; - String[] OLD = new String[5]; - for (int i = 0; i < OLD.length; i++) { - OLD[i] = Security.getProperty(PREFIX + i); - } - - try { - Security.setProperty(PREFIX + 0, "http://foo0.bar.com"); - Security.setProperty(PREFIX + 1, "http://foo1.bar.com"); - Security.setProperty(PREFIX + 2, "http://foo2.bar.com"); - Security.setProperty(PREFIX + 4, "http://foo4.bar.com"); - URL[] result = PolicyUtils.getPolicyURLs(new Properties(), "", - PREFIX); - assertNotNull(result); - assertEquals(2, result.length); - assertEquals(new URL("http://foo1.bar.com"), result[0]); - assertEquals(new URL("http://foo2.bar.com"), result[1]); - - Security.setProperty(PREFIX + 1, "slkjdfhk/svfv*&^"); - Security.setProperty(PREFIX + 3, "dlkfjvb3lk5jt"); - result = PolicyUtils.getPolicyURLs(new Properties(), "", PREFIX); - assertNotNull(result); - assertEquals(2, result.length); - assertEquals(new URL("http://foo2.bar.com"), result[0]); - assertEquals(new URL("http://foo4.bar.com"), result[1]); - } - finally { - for (int i = 0; i < OLD.length; i++) { - Security - .setProperty(PREFIX + i, (OLD[i] == null) ? "" : OLD[i]); - } - } - } - - /** - * Tests expansion in system and security URLs. - */ - public void testGetPolicyURLs03() throws Throwable { - final String KEY_DYNAMIC = "policy.allowSystemProperty"; - final String OLD_DYNAMIC = Security.getProperty(KEY_DYNAMIC); - final String KEY_EXP = "policy.expandProperties"; - final String OLD_EXP = Security.getProperty(KEY_EXP); - final String PREFIX = "testGetPolicyURLs03."; - String[] OLD = new String[5]; - for (int i = 0; i < OLD.length; i++) { - OLD[i] = Security.getProperty(PREFIX + i); - } - - final String KEY = "dsfvdf"; - Properties arg = new Properties(); - arg.put(KEY, "file://${foo.path}/${foo.name}"); - arg.put("foo.path", "path"); - arg.put("foo.name", "name"); - arg.put("foo", "acme"); - Security.setProperty(KEY_DYNAMIC, "true"); - Security.setProperty(KEY_EXP, "true"); - Security.setProperty(PREFIX + 1, "http://foo0.${foo}.org"); - Security.setProperty(PREFIX + 2, "http://${bar}.com"); - Security.setProperty(PREFIX + 3, - "http://foo2.bar.com/${foo.path}/${foo.name}"); - try { - - URL[] result = PolicyUtils.getPolicyURLs(arg, KEY, PREFIX); - assertNotNull(result); - assertEquals(3, result.length); - assertEquals(new URL("http://foo0.acme.org"), result[0]); - assertEquals(new URL("http://foo2.bar.com/path/name"), result[1]); - assertEquals(new URL("file://path/name"), result[2]); - - //expansion here cannot be switched off - Security.setProperty(KEY_EXP, "false"); - result = PolicyUtils.getPolicyURLs(arg, KEY, PREFIX); - assertNotNull(result); - assertEquals(3, result.length); - assertEquals(new URL("http://foo0.acme.org"), result[0]); - assertEquals(new URL("http://foo2.bar.com/path/name"), result[1]); - assertEquals(new URL("file://path/name"), result[2]); - } - finally { - Security.setProperty(KEY_DYNAMIC, OLD_DYNAMIC); - Security.setProperty(KEY_EXP, OLD_EXP); - for (int i = 0; i < OLD.length; i++) { - Security - .setProperty(PREFIX + i, (OLD[i] == null) ? "" : OLD[i]); - } - } - } - - /** Tests conversion of null, empty and non-empty heterogeneous collections. */ - public void testToPermissionCollection() { - Permission p1 = new SecurityPermission("abc"); - Permission p2 = new AllPermission(); - Collection c1 = Arrays.asList(new Permission[] { p1, p2, }); - - PermissionCollection pc = PolicyUtils.toPermissionCollection(null); - assertNotNull(pc); - assertFalse(pc.elements().hasMoreElements()); - - pc = PolicyUtils.toPermissionCollection(new HashSet()); - assertNotNull(pc); - assertFalse(pc.elements().hasMoreElements()); - - pc = PolicyUtils.toPermissionCollection(c1); - assertNotNull(pc); - Enumeration en = pc.elements(); - Collection c2 = new HashSet(); - c2.add(en.nextElement()); - c2.add(en.nextElement()); - assertFalse(en.hasMoreElements()); - assertTrue(c2.contains(p1)); - assertTrue(c2.contains(p2)); - } - - public void testInstantiatePermission() throws Throwable { - String name = "abc"; - Permission expected = new SecurityPermission(name); - //test valid input - assertEquals(expected, PolicyUtils.instantiatePermission(SecurityPermission.class, name, null)); - assertEquals(expected, PolicyUtils.instantiatePermission(SecurityPermission.class, name, "4t46")); - - //test invalid class - try { - PolicyUtils.instantiatePermission(UnresolvedPermission.class, null, null); - fail("IllegalArgumentException expected on invalid class argument"); - } catch (IllegalArgumentException ok) {} - } - - /** - * Tests various combinations of arrays: - * null/empty/containing null/containing real objects. - */ - public void testMatchSubset() { - assertTrue(PolicyUtils.matchSubset(null, null)); - assertTrue(PolicyUtils.matchSubset(new Object[] {}, null)); - assertTrue(PolicyUtils.matchSubset(new Object[] { null }, null)); - assertTrue(PolicyUtils.matchSubset(new Object[] {}, - new Object[] { null })); - assertTrue(PolicyUtils.matchSubset(new Object[] { "1", "2" }, - new Object[] { "3", "2", "1" })); - assertTrue(PolicyUtils.matchSubset(new Object[] { "1", null }, - new Object[] { "3", "2", "1" })); - assertFalse(PolicyUtils.matchSubset(new Object[] { "1", null }, - new Object[] { "3", "2", })); - } -} diff --git a/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java b/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java deleted file mode 100644 index bef756b..0000000 --- a/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java +++ /dev/null @@ -1,222 +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 -*/ - -package org.apache.harmony.security.tests.java.security; - -import java.net.MalformedURLException; -import java.net.URL; -import java.security.CodeSigner; -import java.security.CodeSource; -import java.security.Provider; -import java.security.Security; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.util.ArrayList; - -import javax.security.auth.x500.X500Principal; - -import org.apache.harmony.security.tests.support.TestCertUtils; - -import junit.framework.TestCase; - -/** - * Unit test for CodeSource. - * - */ - -public class CodeSource_ImplTest extends TestCase { - - /* Below are various URLs used during the testing */ - private static URL urlSite; - - static { - try { - String siteName = "www.intel.com"; - urlSite = new URL("http://"+siteName+""); - } catch (MalformedURLException ex) { - throw new Error(ex); - } - } - - /** - * Test for equals(Object)<br> - * The signer certificate may contain nulls, and equals() must not fail with NPE - */ - public void testEqualsObject_03() { - Certificate cert0 = new TestCertUtils.TestCertificate(); - Certificate[] certs0 = new Certificate[] { cert0, null }; - Certificate[] certs1 = new Certificate[] { null, 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 certs are taken into account - properly. - */ - public void testEqualsObject_05() { - Certificate cert0 = new TestCertUtils.TestCertificate("cert0"); - Certificate cert1 = new TestCertUtils.TestCertificate("cert1"); - Certificate cert2 = new TestCertUtils.TestCertificate("cert2"); - - Certificate[] smallSet = new Certificate[] { cert0, cert1 }; - Certificate[] bigSet = new Certificate[] { cert0, cert1, cert2 }; - - CodeSource thiz = new CodeSource(urlSite, smallSet); - CodeSource that = new CodeSource(urlSite, (Certificate[]) null); - assertFalse(thiz.equals(that)); - - that = new CodeSource(urlSite, bigSet); - assertFalse(thiz.equals(that)); - - thiz = new CodeSource(urlSite, bigSet); - that = new CodeSource(urlSite, smallSet); - assertFalse(thiz.equals(that)); - - thiz = new CodeSource(urlSite, (Certificate[]) null); - that = new CodeSource(urlSite, /*any set*/smallSet); - assertFalse(thiz.equals(that)); - assertFalse(that.equals(thiz)); - } - - /** - * getCodeSigners() must not take into account non-X509 certificates. - */ - public void testGetCodeSigners_01() { - Certificate[] certs = { new TestCertUtils.TestCertificate("00") }; - CodeSource cs = new CodeSource(null, certs); - assertNull(cs.getCodeSigners()); - } - - /** - * getCodeSigners() must return null if no X509 factory available - */ - public void testGetCodeSigners_02() { - ArrayList al = new ArrayList(); - boolean noMoreFactories = false; - try { - // remove all providers for x509 - // 'for' loop here for the sake of avoiding endless loop - well, just - // in case if something is wrong with add/remove machinery. - // '100' seems reasonable big to remove all necessary providers - // ... - for (int i = 0; i < 100; i++) { - try { - CertificateFactory f = CertificateFactory - .getInstance("X.509"); - al.add(f.getProvider()); - Security.removeProvider(f.getProvider().getName()); - } catch (CertificateException ex) { - noMoreFactories = true; - break; - } - } - if (!noMoreFactories) { - throw new Error( - "Unable to setup test: too many providers provide X.509"); - } - Certificate[] certs = new Certificate[] { TestCertUtils.rootCA }; - CodeSource cs = new CodeSource(null, certs); - assertNull(cs.getCodeSigners()); - } finally { - // .. and restore providers back - to avoid affecting following tests - for (int i = 0; i < al.size(); i++) { - Security.addProvider((Provider) al.get(i)); - } - } - - } - - /** - * getCodeSigners() must return an array of CodeSigners. Just make sure - * the array looks healthy. - */ - public void testGetCodeSigners_03() { - TestCertUtils.install_test_x509_factory(); - try { - X500Principal[] ps = TestCertUtils.UniGen.genX500s(3); - - // 2-certs chain - X509Certificate rootCA = TestCertUtils.rootCA; - X509Certificate c0 = new TestCertUtils.TestX509Certificate(ps[0], - rootCA.getIssuerX500Principal()); - // - X509Certificate c1 = new TestCertUtils.TestX509Certificate(ps[1], - ps[1]); - X509Certificate c2 = new TestCertUtils.TestX509Certificate(ps[2], - ps[2]); - - java.security.cert.Certificate [] certs = new java.security.cert.Certificate[] { - c0, rootCA, c1, c2 }; - CodeSource cs = new CodeSource(null, certs); - CodeSigner[] signers = cs.getCodeSigners(); - - // must get exactly 3 CodeSigner-s: one for the chain, and one - // for each of single certs - assertEquals(3, signers.length); - } finally { - TestCertUtils.uninstall_test_x509_factory(); - } - } - - /** - * getCodeSigners(). Make sure, that CertException is handled properly - */ - public void testGetCodeSigners_04() { - try { - TestCertUtils.install_test_x509_factory(); - X500Principal[] ps = TestCertUtils.UniGen.genX500s(1); - - // 2-certs chain - X509Certificate rootCA = TestCertUtils.rootCA; - X509Certificate c0 = new TestCertUtils.TestInvalidX509Certificate( - ps[0], rootCA.getIssuerX500Principal()); - java.security.cert.Certificate [] certs = new java.security.cert.Certificate[] { - c0, rootCA }; - - CodeSource cs = new CodeSource(null, certs); - CodeSigner[] signers = cs.getCodeSigners(); - - assertNull(signers); - - // Must force a check for 'factory==null' - cs.getCodeSigners(); - } finally { - TestCertUtils.uninstall_test_x509_factory(); - } - } - - - /** - * @tests java.security.CodeSource#toString() - */ - public void test_toString() throws Exception { - // Test for method java.lang.String java.security.CodeSource.toString() - CodeSource cs = new CodeSource(new java.net.URL("file:///test"), - (Certificate[]) null); - assertEquals("toString did not return expected value.", - "CodeSource, url=file:/test, <no certificates>", cs.toString()); - } - -} diff --git a/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java b/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java deleted file mode 100644 index 819bb25..0000000 --- a/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.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 org.apache.harmony.security.tests.java.security; - -import java.security.Permission; -import java.security.PermissionCollection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; - -import junit.framework.TestCase; - -/** - * Tests for <code>PermissionCollection</code> - */ -public class PermissionCollection_ImplTest extends TestCase { - // Bare extension to instantiate abstract PermissionCollection class - private static final class RealPermissionCollection extends - PermissionCollection { - final private Collection col; - - public RealPermissionCollection(Collection<Permission> col) { - this.col = col; - } - - public void add(Permission permission) { - } - - public Enumeration<Permission> elements() { - return col == null ? null : Collections.enumeration(col); - } - - public boolean implies(Permission permission) { - return false; - } - } - - /** Test toString() transformation with different elements. */ - public void testToString() { - // no elements - PermissionCollection pc = new RealPermissionCollection(null); - try { - assertNotNull("No elements", pc.toString()); - } catch (NullPointerException e) { - // Allowed - } - - // several elements - List<Permission> bpList = new ArrayList<Permission>(); - bpList.add(new RuntimePermission("aaa")); - bpList.add(new RuntimePermission("bbb")); - bpList.add(new RuntimePermission("ccc")); - String pcString = new RealPermissionCollection(bpList).toString(); - assertTrue("Failed to find aaa", pcString.contains("aaa")); - assertTrue("Failed to find bbb", pcString.contains("bbb")); - assertTrue("Failed to find ccc", pcString.contains("ccc")); - } -} diff --git a/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Permissions_ImplTest.java b/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Permissions_ImplTest.java deleted file mode 100644 index ebab944..0000000 --- a/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Permissions_ImplTest.java +++ /dev/null @@ -1,98 +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 -*/ - -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 junit.framework.TestCase; - -/** - * Tests for <code>Permissions</code> - * - */ - -public class Permissions_ImplTest extends TestCase { - - /** - * A permission is implied by this collection, if either of the following is - * true: - * <ul> - * <li>This collection contains AllPermission; - * <li>This collection has elements of the same type as the permission - * being checked, and they imply it; - * <li>This collection has UnresolvedPermissions which can be resolved to - * the checked type, and after resolving they imply the checked one. - * </ul> - * The only exception is UnresolvedPermission itself, which is effectively - * implied only by AllPermission - */ - public void testImplies() { - Permissions ps = new Permissions(); - Permission ap = new AllPermission(); - Permission bp1 = new BasicPermission("jhb23jhg5") { - }; - Permission bp2 = new BasicPermission("&%#&^$HJVH") { - - public PermissionCollection newPermissionCollection() { - return null; - } - }; - Permission sp1 = new SecurityPermission("a.b.c"); - Permission sp2 = new SecurityPermission("a.b.*"); - Permission sp3 = new SecurityPermission("a.*"); - Permission up = new UnresolvedPermission( - "java.security.SecurityPermission", "*", null, null); - - Permission[] arr = new Permission[] { - ap, bp1, bp2, sp1, sp2, up }; - for (int i = 0; i < arr.length; i++) { - assertFalse(ps.implies(arr[i])); - } - - ps.add(bp1); - assertTrue(ps.implies(bp1)); - assertFalse(ps.implies(bp2)); - assertFalse(ps.implies(ap)); - assertFalse(ps.implies(sp1)); - - ps.add(sp2); - assertTrue(ps.implies(sp1)); - assertTrue(ps.implies(sp2)); - assertFalse(ps.implies(sp3)); - - ps.add(up); - assertFalse(ps.implies(up)); - assertTrue(ps.implies(sp1)); - assertTrue(ps.implies(sp2)); - assertTrue(ps.implies(sp3)); - - ps.add(ap); - for (int i = 0; i < arr.length; i++) { - assertTrue(ps.implies(arr[i])); - } - } - } diff --git a/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Policy_ImplTest.java b/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Policy_ImplTest.java deleted file mode 100644 index 9152658..0000000 --- a/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Policy_ImplTest.java +++ /dev/null @@ -1,108 +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 -*/ - -package org.apache.harmony.security.tests.java.security; -import java.security.AllPermission; -import java.security.CodeSource; -import java.security.PermissionCollection; -import java.security.Policy; -import java.security.ProtectionDomain; -import java.security.Security; -import java.security.SecurityPermission; - -import junit.framework.TestCase; - -/** - * Tests for <code>Policy</code> - * - */ - -public class Policy_ImplTest extends TestCase { - - public static class TestProvider extends Policy { - - PermissionCollection pc; - - public PermissionCollection getPermissions(CodeSource cs) { - return pc; - } - - public void refresh() { - } - } - - /** - * Tests loading of a default provider, both valid and invalid class - * references. - */ - public void testGetPolicy_LoadDefaultProvider() { - Policy oldPolicy = Policy.getPolicy(); - String POLICY_PROVIDER = "policy.provider"; - String oldProvider = Security.getProperty(POLICY_PROVIDER); - try { - Security.setProperty(POLICY_PROVIDER, TestProvider.class.getName()); - Policy.setPolicy(null); - Policy p = Policy.getPolicy(); - assertNotNull(p); - assertEquals(TestProvider.class.getName(), p.getClass().getName()); - - Security.setProperty(POLICY_PROVIDER, "a.b.c.D"); - Policy.setPolicy(null); - p = Policy.getPolicy(); - assertNotNull(p); - //exact type of default provider does not matter - //assertEquals(DefaultPolicy.class.getName(), p.getClass().getName()); - } finally { - Security.setProperty(POLICY_PROVIDER, (oldProvider == null) ? "" - : oldProvider); - Policy.setPolicy(oldPolicy); - } - } - - /** - * Tests that implies() does proper permission evaluation. - */ - public void testImplies() { - TestProvider policy = new TestProvider(); - SecurityPermission sp = new SecurityPermission("abc"); - policy.pc = sp.newPermissionCollection(); - - policy.pc.add(sp); - assertTrue(policy.implies(new ProtectionDomain(null, null), sp)); - assertFalse(policy.implies(null, sp)); - assertFalse(policy.implies(new ProtectionDomain(null, null), null)); - - //RI throws NullPointerException. - try { - policy.implies(null, null); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected. - } - - - ProtectionDomain pd = new ProtectionDomain(null, policy.pc); - policy.pc = null; - assertTrue(policy.implies(pd, sp)); - assertFalse(policy.implies(pd, new AllPermission())); - } - -} diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser Binary files differdeleted file mode 100644 index 931ee3f..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.golden.0.ser Binary files differdeleted file mode 100644 index 007acc5..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.golden.1.ser Binary files differdeleted file mode 100644 index a0b8ae6..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionCollectionTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index d90f72b..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/AllPermissionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.0.ser Binary files differdeleted file mode 100644 index 5f21eaa..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.1.ser Binary files differdeleted file mode 100644 index aed9511..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.2.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.2.ser Binary files differdeleted file mode 100644 index 3fcf4fb..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionCollectionTest.golden.2.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index e88e219..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/BasicPermissionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.0.ser Binary files differdeleted file mode 100644 index b2c234e..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.1.ser Binary files differdeleted file mode 100644 index b2c234e..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.2.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.2.ser Binary files differdeleted file mode 100644 index 57aee66..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.2.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.3.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.3.ser Binary files differdeleted file mode 100644 index 835c40b..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/CodeSourceTest.golden.3.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.golden.0.ser Binary files differdeleted file mode 100644 index 99fcd97..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.golden.1.ser Binary files differdeleted file mode 100644 index ab3f9e1..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionCollectionTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index c474702..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.golden.1.ser Binary files differdeleted file mode 100644 index 9e6af9e..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.golden.0.ser Binary files differdeleted file mode 100644 index d4ef01b..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.golden.1.ser Binary files differdeleted file mode 100644 index 3c5eebb..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/PermissionsTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index 670944f..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.golden.1.ser Binary files differdeleted file mode 100644 index 69242a9..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/SecurityPermissionTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.0.ser Binary files differdeleted file mode 100644 index 2a47e5b..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.1.ser Binary files differdeleted file mode 100644 index 7accff2..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.2.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.2.ser Binary files differdeleted file mode 100644 index cb09f46..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionCollectionTest.golden.2.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.0.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.0.ser Binary files differdeleted file mode 100644 index 9ea31ee..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.0.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.1.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.1.ser Binary files differdeleted file mode 100644 index 2be5b71..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.1.ser +++ /dev/null diff --git a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.ser b/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.ser Binary files differdeleted file mode 100644 index 2937f2f..0000000 --- a/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/serialization/UnresolvedPermissionTest.golden.ser +++ /dev/null diff --git a/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLPermissionTest.java b/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLPermissionTest.java deleted file mode 100644 index ed5edbc..0000000 --- a/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLPermissionTest.java +++ /dev/null @@ -1,73 +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.sql.tests.java.sql; - -import java.sql.SQLPermission; - -import junit.framework.TestCase; - -/** - * JUnit Testcase for the java.sql.SQLPermission class - * - * Note that the SQLPermission class only defines 2 constructors and all other - * methods are inherited. This testcase explicitly tets the constructors but - * also implicitly tests some of the inherited query methods. - * - */ - -public class SQLPermissionTest extends TestCase { - - /* - * Constructor test - */ - public void testSQLPermissionStringString() { - String validName = "setLog"; - String validActions = "theActions"; - - SQLPermission thePermission = new SQLPermission(validName, validActions); - - assertNotNull(thePermission); - assertEquals(validName, thePermission.getName()); - // System.out.println("The actions: " + thePermission.getActions() + "." - // ); - assertEquals("", thePermission.getActions()); - } // end method testSQLPermissionStringString - - /* - * Constructor test - */ - public void testSQLPermissionString() { - String validName = "setLog"; - - SQLPermission thePermission = new SQLPermission(validName); - - assertNotNull(thePermission); - assertEquals(validName, thePermission.getName()); - - // Set an invalid name ... - String invalidName = "foo"; - - thePermission = new SQLPermission(invalidName); - - assertNotNull(thePermission); - assertEquals(invalidName, thePermission.getName()); - assertEquals("", thePermission.getActions()); - } // end method testSQLPermissionString - -} // end class SQLPermissionTest - diff --git a/support/src/test/java/tests/support/resource/Support_Resources.java b/support/src/test/java/tests/support/resource/Support_Resources.java index 849b9bb..ec1a4b7 100644 --- a/support/src/test/java/tests/support/resource/Support_Resources.java +++ b/support/src/test/java/tests/support/resource/Support_Resources.java @@ -1,13 +1,13 @@ -/* +/* * 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. @@ -30,139 +30,124 @@ import tests.support.Support_Configuration; public class Support_Resources { - public static final String RESOURCE_PACKAGE = "/tests/resources/"; - - public static final String RESOURCE_PACKAGE_NAME = "tests.resources"; - - public static InputStream getStream(String name) { - return Support_Resources.class.getResourceAsStream(RESOURCE_PACKAGE - + name); - } - - public static String getURL(String name) { - String folder = null; - String fileName = name; - File resources = createTempFolder(); - int index = name.lastIndexOf("/"); - if (index != -1) { - folder = name.substring(0, index); - name = name.substring(index + 1); - } - copyFile(resources, folder, name); - URL url = null; - String resPath = resources.toString(); - if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') { + public static final String RESOURCE_PACKAGE = "/tests/resources/"; + + public static final String RESOURCE_PACKAGE_NAME = "tests.resources"; + + public static InputStream getStream(String name) { + // System.err.println("getResourceAsStream(" + RESOURCE_PACKAGE + name + ")"); + return Support_Resources.class.getResourceAsStream(RESOURCE_PACKAGE + name); + } + + public static String getURL(String name) { + String folder = null; + String fileName = name; + File resources = createTempFolder(); + int index = name.lastIndexOf("/"); + if (index != -1) { + folder = name.substring(0, index); + name = name.substring(index + 1); + } + copyFile(resources, folder, name); + URL url = null; + String resPath = resources.toString(); + if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') { resPath = resPath.substring(1); } - try { - url = new URL("file:/" + resPath + "/" + fileName); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return url.toString(); - } - - public static File createTempFolder() { - - File folder = null; - try { - folder = File.createTempFile("hyts_resources", "", null); - folder.delete(); - folder.mkdirs(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - folder.deleteOnExit(); - return folder; - } - - public static void copyFile(File root, String folder, String file) { - File f; - if (folder != null) { - f = new File(root.toString() + "/" + folder); - if (!f.exists()) { - f.mkdirs(); - f.deleteOnExit(); - } - } else { + try { + url = new URL("file:/" + resPath + "/" + fileName); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + return url.toString(); + } + + public static File createTempFolder() { + File folder = null; + try { + folder = File.createTempFile("hyts_resources", "", null); + folder.delete(); + folder.mkdirs(); + } catch (IOException e) { + throw new RuntimeException(e); + } + folder.deleteOnExit(); + return folder; + } + + public static void copyFile(File root, String folder, String file) { + File f; + if (folder != null) { + f = new File(root.toString() + "/" + folder); + if (!f.exists()) { + f.mkdirs(); + f.deleteOnExit(); + } + } else { f = root; } - File dest = new File(f.toString() + "/" + file); - - InputStream in = Support_Resources.getStream(folder == null ? file - : folder + "/" + file); - try { - copyLocalFileto(dest, in); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public static File createTempFile(String suffix) throws IOException { - return File.createTempFile("hyts_", suffix, null); - } - - public static void copyLocalFileto(File dest, InputStream in) - throws FileNotFoundException, IOException { - if (!dest.exists()) { - FileOutputStream out = new FileOutputStream(dest); - int result; - byte[] buf = new byte[4096]; - while ((result = in.read(buf)) != -1) { + String src = folder == null ? file : folder + "/" + file; + InputStream in = Support_Resources.getStream(src); + try { + File dst = new File(f.toString() + "/" + file); + copyLocalFileTo(dst, in); + } catch (Exception e) { + throw new RuntimeException("copyFile failed: root=" + root + " folder=" + folder + " file=" + file + " (src=" + src + ")", e); + } + } + + public static File createTempFile(String suffix) throws IOException { + return File.createTempFile("hyts_", suffix, null); + } + + public static void copyLocalFileTo(File dest, InputStream in) throws IOException { + if (!dest.exists()) { + FileOutputStream out = new FileOutputStream(dest); + int result; + byte[] buf = new byte[4096]; + while ((result = in.read(buf)) != -1) { out.write(buf, 0, result); } - in.close(); - out.close(); - dest.deleteOnExit(); - } - } - - public static File getExternalLocalFile(String url) throws IOException, - MalformedURLException { - File resources = createTempFolder(); - InputStream in = new URL(url).openStream(); - File temp = new File(resources.toString() + "/local.tmp"); - copyLocalFileto(temp, in); - return temp; - } - - public static String getResourceURL(String resource) { - return "http://" + Support_Configuration.TestResources + resource; - } + in.close(); + out.close(); + dest.deleteOnExit(); + } + } + + public static File getExternalLocalFile(String url) throws IOException, MalformedURLException { + File resources = createTempFolder(); + InputStream in = new URL(url).openStream(); + File temp = new File(resources.toString() + "/local.tmp"); + copyLocalFileTo(temp, in); + return temp; + } + + public static String getResourceURL(String resource) { + return "http://" + Support_Configuration.TestResources + resource; + } /** * Util method to load resource files - * + * * @param name - name of resource file * @return - resource input stream */ public static InputStream getResourceStream(String name) { - - InputStream is = ClassLoader.getSystemClassLoader() - .getResourceAsStream(name); - + InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(name); if (is == null) { throw new RuntimeException("Failed to load resource: " + name); } - return is; } - + /** * Util method to get absolute path to resource file - * + * * @param name - name of resource file * @return - path to resource */ public static String getAbsoluteResourcePath(String name) { - URL url = ClassLoader.getSystemClassLoader().getResource(name); if (url == null) { throw new RuntimeException("Failed to load resource: " + name); diff --git a/support/src/test/java/tests/resources/Broken_entry.jar b/support/src/test/resources/tests/resources/Broken_entry.jar Binary files differindex e6e7927..e6e7927 100644 --- a/support/src/test/java/tests/resources/Broken_entry.jar +++ b/support/src/test/resources/tests/resources/Broken_entry.jar diff --git a/support/src/test/java/tests/resources/Broken_manifest.jar b/support/src/test/resources/tests/resources/Broken_manifest.jar Binary files differindex 4c3ff31..4c3ff31 100644 --- a/support/src/test/java/tests/resources/Broken_manifest.jar +++ b/support/src/test/resources/tests/resources/Broken_manifest.jar diff --git a/support/src/test/java/tests/resources/Created_by_1_4.jar b/support/src/test/resources/tests/resources/Created_by_1_4.jar Binary files differindex 1fe7947..1fe7947 100644 --- a/support/src/test/java/tests/resources/Created_by_1_4.jar +++ b/support/src/test/resources/tests/resources/Created_by_1_4.jar diff --git a/support/src/test/java/tests/resources/EmptyEntries_signed.jar b/support/src/test/resources/tests/resources/EmptyEntries_signed.jar Binary files differindex 237d244..237d244 100644 --- a/support/src/test/java/tests/resources/EmptyEntries_signed.jar +++ b/support/src/test/resources/tests/resources/EmptyEntries_signed.jar diff --git a/support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gz b/support/src/test/resources/tests/resources/GZIPInputStream/hyts_gInput.txt.gz Binary files differindex e0f5a00..e0f5a00 100644 --- a/support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gz +++ b/support/src/test/resources/tests/resources/GZIPInputStream/hyts_gInput.txt.gz diff --git a/support/src/test/java/tests/resources/Harmony.GIF b/support/src/test/resources/tests/resources/Harmony.GIF Binary files differindex be2dc56..be2dc56 100644 --- a/support/src/test/java/tests/resources/Harmony.GIF +++ b/support/src/test/resources/tests/resources/Harmony.GIF diff --git a/support/src/test/java/tests/resources/Harmony.jpg b/support/src/test/resources/tests/resources/Harmony.jpg Binary files differindex 85bfc6e..85bfc6e 100644 --- a/support/src/test/java/tests/resources/Harmony.jpg +++ b/support/src/test/resources/tests/resources/Harmony.jpg diff --git a/support/src/test/java/tests/resources/Harmony.png b/support/src/test/resources/tests/resources/Harmony.png Binary files differindex 5ec399c..5ec399c 100644 --- a/support/src/test/java/tests/resources/Harmony.png +++ b/support/src/test/resources/tests/resources/Harmony.png diff --git a/support/src/test/java/tests/resources/Inserted_Entry_Manifest.jar b/support/src/test/resources/tests/resources/Inserted_Entry_Manifest.jar Binary files differindex 154d8d6..154d8d6 100644 --- a/support/src/test/java/tests/resources/Inserted_Entry_Manifest.jar +++ b/support/src/test/resources/tests/resources/Inserted_Entry_Manifest.jar diff --git a/support/src/test/java/tests/resources/Inserted_Entry_Manifest_with_DigestCode.jar b/support/src/test/resources/tests/resources/Inserted_Entry_Manifest_with_DigestCode.jar Binary files differindex a94ae49..a94ae49 100644 --- a/support/src/test/java/tests/resources/Inserted_Entry_Manifest_with_DigestCode.jar +++ b/support/src/test/resources/tests/resources/Inserted_Entry_Manifest_with_DigestCode.jar diff --git a/support/src/test/java/tests/resources/Integrate.jar b/support/src/test/resources/tests/resources/Integrate.jar Binary files differindex 16e9c55..16e9c55 100644 --- a/support/src/test/java/tests/resources/Integrate.jar +++ b/support/src/test/resources/tests/resources/Integrate.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_11.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_11.jar Binary files differindex 19cf5f2..19cf5f2 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_11.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_11.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_12.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_12.jar Binary files differindex 236659b..236659b 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_12.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_12.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_13.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_13.jar Binary files differindex 9ea6806..9ea6806 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_13.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_13.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_14.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_14.jar Binary files differindex d8bc44b..d8bc44b 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_14.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_14.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_21.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_21.jar Binary files differindex c25d4bf..c25d4bf 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_21.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_21.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_22-new.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_22-new.jar Binary files differindex 542c22a..542c22a 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_22-new.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_22-new.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_22.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_22.jar Binary files differindex 84c7af0..84c7af0 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_22.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_22.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_23.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_23.jar Binary files differindex a932052..a932052 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_23.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_23.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_31.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_31.jar Binary files differindex ab69696..ab69696 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_31.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_31.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_32.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_32.jar Binary files differindex 12de6bb..12de6bb 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_32.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_32.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_33.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_33.jar Binary files differindex 086e494..086e494 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_33.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_33.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_41.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_41.jar Binary files differindex fb71bf8..fb71bf8 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_41.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_41.jar diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_42.jar b/support/src/test/resources/tests/resources/JarIndex/hyts_42.jar Binary files differindex 06a35cd..06a35cd 100644 --- a/support/src/test/java/tests/resources/JarIndex/hyts_42.jar +++ b/support/src/test/resources/tests/resources/JarIndex/hyts_42.jar diff --git a/support/src/test/java/tests/resources/Modified_Class.jar b/support/src/test/resources/tests/resources/Modified_Class.jar Binary files differindex d8113c7..d8113c7 100644 --- a/support/src/test/java/tests/resources/Modified_Class.jar +++ b/support/src/test/resources/tests/resources/Modified_Class.jar diff --git a/support/src/test/java/tests/resources/Modified_Manifest_EntryAttributes.jar b/support/src/test/resources/tests/resources/Modified_Manifest_EntryAttributes.jar Binary files differindex bd1dbb1..bd1dbb1 100644 --- a/support/src/test/java/tests/resources/Modified_Manifest_EntryAttributes.jar +++ b/support/src/test/resources/tests/resources/Modified_Manifest_EntryAttributes.jar diff --git a/support/src/test/java/tests/resources/Modified_Manifest_MainAttributes.jar b/support/src/test/resources/tests/resources/Modified_Manifest_MainAttributes.jar Binary files differindex 5bc60e6..5bc60e6 100644 --- a/support/src/test/java/tests/resources/Modified_Manifest_MainAttributes.jar +++ b/support/src/test/resources/tests/resources/Modified_Manifest_MainAttributes.jar diff --git a/support/src/test/java/tests/resources/Modified_SF_EntryAttributes.jar b/support/src/test/resources/tests/resources/Modified_SF_EntryAttributes.jar Binary files differindex 7b76694..7b76694 100644 --- a/support/src/test/java/tests/resources/Modified_SF_EntryAttributes.jar +++ b/support/src/test/resources/tests/resources/Modified_SF_EntryAttributes.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_all_attributes.jar b/support/src/test/resources/tests/resources/Package/hyts_all_attributes.jar Binary files differindex bde3f4d..bde3f4d 100644 --- a/support/src/test/java/tests/resources/Package/hyts_all_attributes.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_all_attributes.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_c.jar b/support/src/test/resources/tests/resources/Package/hyts_c.jar Binary files differindex 111f73c..111f73c 100644 --- a/support/src/test/java/tests/resources/Package/hyts_c.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_c.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_d.jar b/support/src/test/resources/tests/resources/Package/hyts_d.jar Binary files differindex 1218f76..1218f76 100644 --- a/support/src/test/java/tests/resources/Package/hyts_d.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_d.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_d1.jar b/support/src/test/resources/tests/resources/Package/hyts_d1.jar Binary files differindex e4a0b4d..e4a0b4d 100644 --- a/support/src/test/java/tests/resources/Package/hyts_d1.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_d1.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_d2.jar b/support/src/test/resources/tests/resources/Package/hyts_d2.jar Binary files differindex 2665a06..2665a06 100644 --- a/support/src/test/java/tests/resources/Package/hyts_d2.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_d2.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_no_attributes.jar b/support/src/test/resources/tests/resources/Package/hyts_no_attributes.jar Binary files differindex 1879acb..1879acb 100644 --- a/support/src/test/java/tests/resources/Package/hyts_no_attributes.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_no_attributes.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_no_entry.jar b/support/src/test/resources/tests/resources/Package/hyts_no_entry.jar Binary files differindex 66090a5..66090a5 100644 --- a/support/src/test/java/tests/resources/Package/hyts_no_entry.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_no_entry.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_pq.jar b/support/src/test/resources/tests/resources/Package/hyts_pq.jar Binary files differindex 5919f6c..5919f6c 100644 --- a/support/src/test/java/tests/resources/Package/hyts_pq.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_pq.jar diff --git a/support/src/test/java/tests/resources/Package/hyts_some_attributes.jar b/support/src/test/resources/tests/resources/Package/hyts_some_attributes.jar Binary files differindex 95c87a8..95c87a8 100644 --- a/support/src/test/java/tests/resources/Package/hyts_some_attributes.jar +++ b/support/src/test/resources/tests/resources/Package/hyts_some_attributes.jar diff --git a/support/src/test/java/tests/resources/ServiceLoader/hyts_services.jar b/support/src/test/resources/tests/resources/ServiceLoader/hyts_services.jar Binary files differindex 12503a6..12503a6 100644 --- a/support/src/test/java/tests/resources/ServiceLoader/hyts_services.jar +++ b/support/src/test/resources/tests/resources/ServiceLoader/hyts_services.jar diff --git a/support/src/test/java/tests/resources/ServiceLoader/hyts_services2.jar b/support/src/test/resources/tests/resources/ServiceLoader/hyts_services2.jar Binary files differindex a7a754a..a7a754a 100644 --- a/support/src/test/java/tests/resources/ServiceLoader/hyts_services2.jar +++ b/support/src/test/resources/tests/resources/ServiceLoader/hyts_services2.jar diff --git a/support/src/test/java/tests/resources/TestCodeSigners.jar b/support/src/test/resources/tests/resources/TestCodeSigners.jar Binary files differindex a4c42aa..a4c42aa 100644 --- a/support/src/test/java/tests/resources/TestCodeSigners.jar +++ b/support/src/test/resources/tests/resources/TestCodeSigners.jar diff --git a/support/src/test/java/tests/resources/hyts_Bar.ser b/support/src/test/resources/tests/resources/hyts_Bar.ser Binary files differindex 2802528..2802528 100644 --- a/support/src/test/java/tests/resources/hyts_Bar.ser +++ b/support/src/test/resources/tests/resources/hyts_Bar.ser diff --git a/support/src/test/java/tests/resources/hyts_Foo.ser b/support/src/test/resources/tests/resources/hyts_Foo.ser Binary files differindex 9f511ac..9f511ac 100644 --- a/support/src/test/java/tests/resources/hyts_Foo.ser +++ b/support/src/test/resources/tests/resources/hyts_Foo.ser diff --git a/support/src/test/java/tests/resources/hyts_PropertiesTest.properties b/support/src/test/resources/tests/resources/hyts_PropertiesTest.properties index 6c1b950..6c1b950 100644 --- a/support/src/test/java/tests/resources/hyts_PropertiesTest.properties +++ b/support/src/test/resources/tests/resources/hyts_PropertiesTest.properties diff --git a/support/src/test/java/tests/resources/hyts_ZipFile.zip b/support/src/test/resources/tests/resources/hyts_ZipFile.zip Binary files differindex f9cd6ed..f9cd6ed 100644 --- a/support/src/test/java/tests/resources/hyts_ZipFile.zip +++ b/support/src/test/resources/tests/resources/hyts_ZipFile.zip diff --git a/support/src/test/java/tests/resources/hyts_att.jar b/support/src/test/resources/tests/resources/hyts_att.jar Binary files differindex 7f4530c..7f4530c 100644 --- a/support/src/test/java/tests/resources/hyts_att.jar +++ b/support/src/test/resources/tests/resources/hyts_att.jar diff --git a/support/src/test/java/tests/resources/hyts_available.tst b/support/src/test/resources/tests/resources/hyts_available.tst Binary files differindex d67b2f4..d67b2f4 100644 --- a/support/src/test/java/tests/resources/hyts_available.tst +++ b/support/src/test/resources/tests/resources/hyts_available.tst diff --git a/support/src/test/java/tests/resources/hyts_checkInput.txt b/support/src/test/resources/tests/resources/hyts_checkInput.txt index 6d49d33..6d49d33 100644 --- a/support/src/test/java/tests/resources/hyts_checkInput.txt +++ b/support/src/test/resources/tests/resources/hyts_checkInput.txt diff --git a/support/src/test/java/tests/resources/hyts_compDiction.bin b/support/src/test/resources/tests/resources/hyts_compDiction.bin Binary files differindex f0478c8..f0478c8 100644 --- a/support/src/test/java/tests/resources/hyts_compDiction.bin +++ b/support/src/test/resources/tests/resources/hyts_compDiction.bin diff --git a/support/src/test/java/tests/resources/hyts_compressD.bin b/support/src/test/resources/tests/resources/hyts_compressD.bin Binary files differindex 36c89f2..36c89f2 100644 --- a/support/src/test/java/tests/resources/hyts_compressD.bin +++ b/support/src/test/resources/tests/resources/hyts_compressD.bin diff --git a/support/src/test/java/tests/resources/hyts_construO.bin b/support/src/test/resources/tests/resources/hyts_construO.bin Binary files differindex b6bd7b4..b6bd7b4 100644 --- a/support/src/test/java/tests/resources/hyts_construO.bin +++ b/support/src/test/resources/tests/resources/hyts_construO.bin diff --git a/support/src/test/java/tests/resources/hyts_construOD.bin b/support/src/test/resources/tests/resources/hyts_construOD.bin Binary files differindex 035d12e..035d12e 100644 --- a/support/src/test/java/tests/resources/hyts_construOD.bin +++ b/support/src/test/resources/tests/resources/hyts_construOD.bin diff --git a/support/src/test/java/tests/resources/hyts_construODI.bin b/support/src/test/resources/tests/resources/hyts_construODI.bin Binary files differindex 1e5d284..1e5d284 100644 --- a/support/src/test/java/tests/resources/hyts_construODI.bin +++ b/support/src/test/resources/tests/resources/hyts_construODI.bin diff --git a/support/src/test/java/tests/resources/hyts_flushed.jar b/support/src/test/resources/tests/resources/hyts_flushed.jar Binary files differindex 56b717c..56b717c 100644 --- a/support/src/test/java/tests/resources/hyts_flushed.jar +++ b/support/src/test/resources/tests/resources/hyts_flushed.jar diff --git a/support/src/test/java/tests/resources/hyts_htmltest.html b/support/src/test/resources/tests/resources/hyts_htmltest.html index 9464371..9464371 100644 --- a/support/src/test/java/tests/resources/hyts_htmltest.html +++ b/support/src/test/resources/tests/resources/hyts_htmltest.html diff --git a/support/src/test/java/tests/resources/hyts_mainClass.ser b/support/src/test/resources/tests/resources/hyts_mainClass.ser Binary files differindex 0421ba9..0421ba9 100644 --- a/support/src/test/java/tests/resources/hyts_mainClass.ser +++ b/support/src/test/resources/tests/resources/hyts_mainClass.ser diff --git a/support/src/test/java/tests/resources/hyts_manifest1.jar b/support/src/test/resources/tests/resources/hyts_manifest1.jar Binary files differindex fb292b2..fb292b2 100644 --- a/support/src/test/java/tests/resources/hyts_manifest1.jar +++ b/support/src/test/resources/tests/resources/hyts_manifest1.jar diff --git a/support/src/test/java/tests/resources/hyts_missingclass.ser b/support/src/test/resources/tests/resources/hyts_missingclass.ser Binary files differindex 0a71403..0a71403 100644 --- a/support/src/test/java/tests/resources/hyts_missingclass.ser +++ b/support/src/test/resources/tests/resources/hyts_missingclass.ser diff --git a/support/src/test/java/tests/resources/hyts_patch.jar b/support/src/test/resources/tests/resources/hyts_patch.jar Binary files differindex f3c51d0..f3c51d0 100644 --- a/support/src/test/java/tests/resources/hyts_patch.jar +++ b/support/src/test/resources/tests/resources/hyts_patch.jar diff --git a/support/src/test/java/tests/resources/hyts_patch2.jar b/support/src/test/resources/tests/resources/hyts_patch2.jar Binary files differindex c26f9e7..c26f9e7 100644 --- a/support/src/test/java/tests/resources/hyts_patch2.jar +++ b/support/src/test/resources/tests/resources/hyts_patch2.jar diff --git a/support/src/test/java/tests/resources/hyts_resource.properties b/support/src/test/resources/tests/resources/hyts_resource.properties index baf5762..baf5762 100644 --- a/support/src/test/java/tests/resources/hyts_resource.properties +++ b/support/src/test/resources/tests/resources/hyts_resource.properties diff --git a/support/src/test/java/tests/resources/hyts_security.jar b/support/src/test/resources/tests/resources/hyts_security.jar Binary files differindex abef675..abef675 100644 --- a/support/src/test/java/tests/resources/hyts_security.jar +++ b/support/src/test/resources/tests/resources/hyts_security.jar diff --git a/support/src/test/java/tests/resources/hyts_signed.jar b/support/src/test/resources/tests/resources/hyts_signed.jar Binary files differindex 8ea8489..8ea8489 100644 --- a/support/src/test/java/tests/resources/hyts_signed.jar +++ b/support/src/test/resources/tests/resources/hyts_signed.jar diff --git a/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF b/support/src/test/resources/tests/resources/manifest/hyts_MANIFEST.MF index 2402bca..2402bca 100644 --- a/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF +++ b/support/src/test/resources/tests/resources/manifest/hyts_MANIFEST.MF diff --git a/support/src/test/java/tests/resources/morestuff/hyts_patch.jar b/support/src/test/resources/tests/resources/morestuff/hyts_patch.jar Binary files differindex f3c51d0..f3c51d0 100644 --- a/support/src/test/java/tests/resources/morestuff/hyts_patch.jar +++ b/support/src/test/resources/tests/resources/morestuff/hyts_patch.jar diff --git a/support/src/test/java/tests/resources/morestuff/hyts_patch2.jar b/support/src/test/resources/tests/resources/morestuff/hyts_patch2.jar Binary files differindex c26f9e7..c26f9e7 100644 --- a/support/src/test/java/tests/resources/morestuff/hyts_patch2.jar +++ b/support/src/test/resources/tests/resources/morestuff/hyts_patch2.jar diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_en.properties b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_en.properties index 40b8caf..40b8caf 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_en.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_en.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US.java b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US.java index 1913879..1913879 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US.properties b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US.properties index 06c99f6..06c99f6 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US_VAR.java b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US_VAR.java index 1c75ec8..1c75ec8 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US_VAR.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_en_US_VAR.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr.java b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr.java index d049d7b..d049d7b 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr.properties b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr.properties index 447f06c..447f06c 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR.java b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR.java index ae11beb..ae11beb 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR.properties b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR.properties index 0ac2c73..0ac2c73 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR_VAR.java b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR_VAR.java index 958c5ff..958c5ff 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR_VAR.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR_VAR.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR_VAR.properties b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR_VAR.properties index dd76478..dd76478 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR_VAR.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/norootresources/hyts_resource_fr_FR_VAR.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.java b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource.java index afa3e6e..afa3e6e 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource.properties index eae054e..eae054e 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_en.properties b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_en.properties index 40b8caf..40b8caf 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_en.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_en.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_en_US.java b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_en_US.java index 16c6e08..16c6e08 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_en_US.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_en_US.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_en_US.properties b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_en_US.properties index 06c99f6..06c99f6 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_en_US.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_en_US.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_en_US_VAR.java b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_en_US_VAR.java index aba4675..aba4675 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_en_US_VAR.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_en_US_VAR.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr.java b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr.java index adac070..adac070 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr.properties b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr.properties index 447f06c..447f06c 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR.properties b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR.properties index 0ac2c73..0ac2c73 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR.properties diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR_VAR.java b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR_VAR.java index 5d48aa3..5d48aa3 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR_VAR.java +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR_VAR.java diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR_VAR.properties b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR_VAR.properties index dd76478..dd76478 100644 --- a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR_VAR.properties +++ b/support/src/test/resources/tests/resources/subfolder/tests/resources/hyts_resource_fr_FR_VAR.properties diff --git a/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/SSLPermissionTest.java b/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/SSLPermissionTest.java deleted file mode 100644 index a42785b..0000000 --- a/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/SSLPermissionTest.java +++ /dev/null @@ -1,43 +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.xnet.tests.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 testSSLPermissionString() { - new SSLPermission("name"); - } - - /* - * Class under test for void SSLPermission(String, String) - */ - public void testSSLPermissionStringString() { - new SSLPermission("name", "action"); - } -} |