Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSigner_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSigner_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSigner_ImplTest.java (revision 0)
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Alexander V. Astapchuk
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.security.CodeSigner;
+import java.security.Timestamp;
+import java.security.cert.CertPath;
+import java.util.Date;
+
+import org.apache.harmony.security.tests.support.TestCertUtils;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for CodeSigner.
+ */
+
+public class CodeSigner_ImplTest extends TestCase {
+
+ private CertPath cpath = TestCertUtils.genCertPath(3, 0);
+ private Date now = new Date();
+
+ private Timestamp ts = new Timestamp(now, cpath);
+
+ /**
+ * Tests CodeSigner.hashCode()
+ */
+ public void testHashCode() {
+ assertTrue(new CodeSigner(cpath, ts).hashCode() == (cpath.hashCode() ^ ts
+ .hashCode()));
+ assertTrue(new CodeSigner(cpath, null).hashCode() == cpath.hashCode());
+ }
+
+}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KSBuilder_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KSBuilder_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KSBuilder_ImplTest.java (working copy)
@@ -19,48 +19,51 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.security.InvalidKeyException;
+import java.security.InvalidParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.PublicKey;
+import java.security.SignatureException;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;
-
import java.util.Enumeration;
-import junit.framework.TestCase;
-
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
import org.apache.harmony.security.tests.support.SpiEngUtils;
import org.apache.harmony.security.tests.support.TestKeyPair;
import org.apache.harmony.security.tests.support.TestUtils;
+import org.apache.harmony.security.tests.support.tmpCallbackHandler;
+import junit.framework.TestCase;
+
/**
* Tests for KeyStore.Builder class
*
*/
-public class KSBuilderTest extends TestCase {
- /**
- * Constructor for KSBuilderTest
- *
- * @param arg
- */
- public KSBuilderTest(String arg) {
- super(arg);
- }
+public class KSBuilder_ImplTest extends TestCase {
+
private static char[] pass = {'s','t','o','r','e','p','w','d'};
private KeyStore.PasswordProtection protPass = new KeyStore.PasswordProtection(pass);
private tmpCallbackHandler tmpCall = new tmpCallbackHandler();
private KeyStore.CallbackHandlerProtection callbackHand = new KeyStore.CallbackHandlerProtection(tmpCall);
private myProtectionParameter myProtParam = new myProtectionParameter(new byte[5]);
- public static String[] validValues = KeyStore1Test.validValues;
+ public static String[] validValues = KeyStoreTestSupport.validValues;
- private static String defaultType = KeyStore1Test.defaultType;
+ private static String defaultType = KeyStoreTestSupport.defaultType;
private static boolean JKSSupported = false;
@@ -72,7 +75,7 @@
static {
defaultProvider = SpiEngUtils.isSupport(
- KeyStore1Test.defaultType, KeyStore1Test.srvKeyStore);
+ KeyStoreTestSupport.defaultType, KeyStoreTestSupport.srvKeyStore);
JKSSupported = (defaultProvider != null);
fileEmpty = SpiEngUtils.getFileName(TestUtils.TEST_ROOT,
fileEmpty);
@@ -83,7 +86,7 @@
private boolean isCreateKS;
// Creates empty KeyStoreand loads it to file
- private void createKS() {
+ private void createKS()throws Exception {
isCreateKS = false;
FileOutputStream fos = null;
try {
@@ -100,8 +103,6 @@
ks.load(null, null);
ks.store(fos, pass);
isCreateKS = true;
- } catch (Exception e) {
- e.printStackTrace(System.out);
} finally {
if (fos != null) {
try {
@@ -129,8 +130,6 @@
deleteKS();
}
-
-
/*
* Test for method:
* newInstance(KeyStore keyStore, ProtectionParameter protectionParameter)
@@ -269,8 +268,7 @@
*
*/
public void testNewInstanceStringProviderFileProtectionParameter()
- throws KeyStoreException, NoSuchAlgorithmException, IOException,
- CertificateException {
+ throws Exception {
if (!JKSSupported) {
fail(defaultType + " type is not supported");
return;
@@ -397,13 +395,8 @@
iter = ks1.aliases();
while (iter.hasMoreElements()) {
aName = (String) iter.nextElement();
- try {
- assertEquals("Incorrect ProtectionParameter", ksB1
- .getProtectionParameter(aName), pp[i]);
- } catch (Exception e) {
- fail("Unexpected: " + e.toString()
- + " was thrown for alias: " + aName);
- }
+ assertEquals("Incorrect ProtectionParameter", ksB1
+ .getProtectionParameter(aName), pp[i]);
}
try {
@@ -534,10 +527,7 @@
}
}
}
-
- public static void main(String args[]) {
- junit.textui.TestRunner.run(KSBuilderTest.class);
- }
+
/**
* Additional class for creation Certificate object
*/
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl1Test.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl1Test.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl1Test.java (working copy)
@@ -19,18 +19,23 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.KeyStoreSpi;
+import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.Security;
+import java.security.UnrecoverableEntryException;
+import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
-import java.security.cert.CertificateEncodingException;
-import java.security.cert.CertificateException;
-import java.security.spec.InvalidKeySpecException;
+import java.util.Arrays;
-import javax.crypto.SecretKey;
-import javax.security.auth.DestroyFailedException;
-
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
import org.apache.harmony.security.tests.support.MyKeyStoreSpi;
import org.apache.harmony.security.tests.support.MyLoadStoreParams;
import org.apache.harmony.security.tests.support.SpiEngUtils;
@@ -43,119 +48,40 @@
*
*/
-public class KeyStore1Test extends TestCase {
+public class KeyStore_Impl1Test extends TestCase {
- public static final String srvKeyStore = "KeyStore";
- public static String[] validValues = {
- "bks", "BKS", "bKS", "Bks", "bKs", "BkS"
- };
+ public static final String srvKeyStore = KeyStoreTestSupport.srvKeyStore;
+ public static String[] validValues = KeyStoreTestSupport.validValues;
+
private static final String[] aliases = { "", "alias", "Alias", "ALIAS",
"new alias", "another alias", "ADDITIONAL", "THE SAME ALIAS" };
-
private static String[] invalidValues = SpiEngUtils.invalidValues;
- public static String defaultType = "bks";
- public static boolean JKSSupported = false;
-
- public static String defaultProviderName = null;
-
- public static Provider defaultProvider = null;
-
- private static String NotSupportMsg = "";
-
- static {
- defaultProvider = SpiEngUtils.isSupport(
- defaultType, srvKeyStore);
- JKSSupported = (defaultProvider != null);
- defaultProviderName = (JKSSupported ? defaultProvider.getName() : null);
- NotSupportMsg = defaultType.concat(" type does not supported");
- }
-
- /**
- * Constructor for KeyStoreTest.
- *
- * @param arg0
- */
- public KeyStore1Test(String arg0) {
- super(arg0);
- }
-
- public KeyStore [] createKS() {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return null;
- }
+ public static String defaultType = KeyStoreTestSupport.defaultType;
+ public static boolean JKSSupported = KeyStoreTestSupport.JKSSupported;
+ public static String defaultProviderName = KeyStoreTestSupport.defaultProviderName;
+ public static Provider defaultProvider = KeyStoreTestSupport.defaultProvider;
+
+ private static String NotSupportMsg = "Default KeyStore type is not supported";
+
+ public KeyStore[] createKS() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
KeyStore[] kpg = new KeyStore[3];
- try {
- kpg[0] = KeyStore.getInstance(defaultType);
- kpg[1] = KeyStore.getInstance(defaultType, defaultProvider);
- kpg[2] = KeyStore.getInstance(defaultType, defaultProviderName);
- return kpg;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- /**
- * Test for getDefaultType() method Assertion: returns
- * default security key store type or "jks" string
- */
- public void testKeyStore01() {
- String propName = "keystore.type";
- String defKSType = Security.getProperty(propName);
- String dType = KeyStore.getDefaultType();
- String resType = defKSType;
- if (resType == null) {
- resType = defaultType;
- }
- assertNotNull("Default type have not be null", dType);
- assertEquals("Incorrect default type", dType, resType);
-
- if (defKSType == null) {
- Security.setProperty(propName, defaultType);
- dType = KeyStore.getDefaultType();
- resType = Security.getProperty(propName);
- assertNotNull("Incorrect default type", resType);
- assertNotNull("Default type have not be null", dType);
- assertEquals("Incorrect default type", dType, resType);
- }
+ kpg[0] = KeyStore.getInstance(defaultType);
+ kpg[1] = KeyStore.getInstance(defaultType, defaultProvider);
+ kpg[2] = KeyStore.getInstance(defaultType, defaultProviderName);
+ return kpg;
}
/**
* Test for getInstance(String type) method
- * Assertion:
- * throws NullPointerException when type is null
- * throws KeyStoreException when type is not available
- *
- */
- public void testKeyStore02() throws KeyStoreException {
- try {
- KeyStore.getInstance(null);
- fail("NullPointerException or must be thrown when type is null");
- } catch (NullPointerException e) {
- }
- for (int i = 0; i < invalidValues.length; i++) {
- try {
- KeyStore.getInstance(invalidValues[i]);
- fail("KeyStoreException must be thrown (type: ".concat(
- invalidValues[i]).concat(" )"));
- } catch (KeyStoreException e) {
- }
- }
- }
-
- /**
- * Test for getInstance(String type) method
* Assertion:
* returns KeyStoreException object
*/
public void testKeyStore03() throws KeyStoreException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ assertTrue(NotSupportMsg, JKSSupported);
KeyStore ks;
for (int i = 0; i < validValues.length; i++) {
ks = KeyStore.getInstance(validValues[i]);
@@ -167,12 +93,8 @@
* Test for getInstance(String type, String provider) method
* Assertion: throws IllegalArgumentException when provider is null or empty
*/
- public void testKeyStore04() throws NoSuchProviderException,
- KeyStoreException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ public void testKeyStore04() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
String provider = null;
for (int i = 0; i < validValues.length; i++) {
try {
@@ -195,10 +117,7 @@
* Assertion: throws NoSuchProviderException when provider is not available
*/
public void testKeyStore05() throws KeyStoreException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ assertTrue(NotSupportMsg, JKSSupported);
for (int i = 0; i < validValues.length; i++) {
for (int j = 1; j < invalidValues.length; j++) {
try {
@@ -219,10 +138,7 @@
* throws KeyStoreException when type is not available
*/
public void testKeyStore06() throws NoSuchProviderException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ assertTrue(NotSupportMsg, JKSSupported);
try {
KeyStore.getInstance(null, defaultProviderName);
fail("KeyStoreException must be thrown when type is null");
@@ -244,12 +160,8 @@
* Test for getInstance(String type, String provider) method
* Assertion: returns KeyStore object
*/
- public void testKeyStore07() throws NoSuchProviderException,
- KeyStoreException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ public void testKeyStore07() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
KeyStore ks;
for (int i = 0; i < validValues.length; i++) {
ks = KeyStore.getInstance(validValues[i], defaultProviderName);
@@ -264,10 +176,7 @@
* Assertion: throws IllegalArgumentException when provider is null
*/
public void testKeyStore08() throws KeyStoreException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ assertTrue(NotSupportMsg, JKSSupported);
Provider provider = null;
for (int i = 0; i < validValues.length; i++) {
try {
@@ -287,10 +196,7 @@
* throws KeyStoreException when type is not available
*/
public void testKeyStore09() {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ assertTrue(NotSupportMsg, JKSSupported);
try {
KeyStore.getInstance(null, defaultProvider);
fail("KeyStoreException must be thrown when type is null");
@@ -314,10 +220,7 @@
* Assertion: returns KeyStore object
*/
public void testKeyStore10() throws KeyStoreException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ assertTrue(NotSupportMsg, JKSSupported);
KeyStore ks;
for (int i = 0; i < validValues.length; i++) {
ks = KeyStore.getInstance(validValues[i], defaultProvider);
@@ -346,13 +249,8 @@
* store(OutputStream stream, char[] password)
* Assertion: throws KeyStoreException when KeyStore was not initialized
*/
- public void testKeyStore11() throws KeyStoreException, CertificateException,
- NoSuchAlgorithmException, UnrecoverableKeyException,
- IOException, UnrecoverableEntryException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ public void testKeyStore11() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
String msgF ="KeyStoreException must be thrown because KeyStore was not initialized";
KeyStore [] kss = createKS();
assertNotNull("KeyStore objects were not created", kss);
@@ -440,7 +338,7 @@
} catch (KeyStoreException e) {
}
KeyStore.TrustedCertificateEntry entry = new KeyStore.TrustedCertificateEntry(
- new MCertificate("type", new byte[0]));
+ new KeyStoreTestSupport.MCertificate("type", new byte[0]));
try {
kss[i].setEntry("aaa", entry, null);
fail(msgF);
@@ -473,14 +371,10 @@
* used trusted certificate.
*
*/
- public void testEntry01() throws NoSuchAlgorithmException, IOException,
- CertificateException, KeyStoreException,
- UnrecoverableEntryException {
- if (!JKSSupported) {
- fail(defaultType + " type does not supported");
- return;
- }
- MCertificate trust = new MCertificate("type", new byte[0]);
+ public void testEntry01() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
+ KeyStoreTestSupport.MCertificate trust = new KeyStoreTestSupport.MCertificate(
+ "type", new byte[0]);
KeyStore.TrustedCertificateEntry entry = new KeyStore.TrustedCertificateEntry(
trust);
KeyStore[] kss = createKS();
@@ -563,18 +457,14 @@
* KeyStore.PrivateKeyEntry is used.
*
*/
- public void testEntry02() throws NoSuchAlgorithmException, IOException,
- CertificateException, KeyStoreException, InvalidKeySpecException,
- UnrecoverableEntryException, DestroyFailedException,
- UnrecoverableKeyException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ public void testEntry02() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
TestKeyPair tkp = new TestKeyPair("DSA");
- MCertificate certs[] = {
- new MCertificate("DSA", tkp.getPrivate().getEncoded()),
- new MCertificate("DSA", tkp.getPrivate().getEncoded()) };
+ KeyStoreTestSupport.MCertificate certs[] = {
+ new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+ .getEncoded()),
+ new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+ .getEncoded()) };
PrivateKey privKey = tkp.getPrivate();
KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(privKey,
certs);
@@ -582,7 +472,7 @@
KeyStore.PasswordProtection pPath = new KeyStore.PasswordProtection(pwd);
KeyStore.PasswordProtection anotherPath = new KeyStore.PasswordProtection(
new char[0]);
- ProtPar pPar = new ProtPar();
+ KeyStoreTestSupport.ProtPar pPar = new KeyStoreTestSupport.ProtPar();
KeyStore[] kss = createKS();
assertNotNull("KeyStore objects were not created", kss);
for (int i = 0; i < kss.length; i++) {
@@ -609,13 +499,8 @@
}
byte[] enc = key.getEncoded();
byte[] enc1 = key1.getEncoded();
- if (enc != null) {
- for (int ii = 0; ii < enc.length; ii++) {
- if (enc[ii] != enc1[ii]) {
- fail("Diff. keys encoding");
- }
- }
- }
+ assertTrue("Diff. keys encoding", Arrays.equals(enc, enc1));
+
cc = ((KeyStore.PrivateKeyEntry) en).getCertificateChain();
assertEquals("Incorrect CertificateChain", cc.length,
certs.length);
@@ -631,13 +516,7 @@
}
enc = key.getEncoded();
enc1 = key1.getEncoded();
- if (enc != null) {
- for (int ii = 0; ii < enc.length; ii++) {
- if (enc[ii] != enc1[ii]) {
- fail("Incorrect Entry: Diff. keys encoding");
- }
- }
- }
+ assertTrue("Incorrect Entry: Diff. keys encoding", Arrays.equals(enc, enc1));
cc = kss[i].getCertificateChain(aliases[j]);
assertEquals("Incorrect CertificateChain", cc.length,
@@ -695,23 +574,17 @@
* FIXME: this test should be changed to verify SecretKeyEntry.
* It is not supoorted.
*/
- public void testEntry03() throws NoSuchAlgorithmException,
- IOException, CertificateException,
- KeyStoreException, InvalidKeySpecException,
- UnrecoverableEntryException, DestroyFailedException,
- UnrecoverableKeyException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ public void testEntry03() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
TestKeyPair tkp = new TestKeyPair("DSA");
- SKey secKey = new SKey("DSA",tkp.getPrivate().getEncoded());
+ KeyStoreTestSupport.SKey secKey = new KeyStoreTestSupport.SKey("DSA",
+ tkp.getPrivate().getEncoded());
KeyStore.SecretKeyEntry sKey = new KeyStore.SecretKeyEntry(
secKey);
char [] pwd = {'p', 'a', 's', 's', 'w', 'd'};
KeyStore.PasswordProtection pPath = new KeyStore.PasswordProtection(pwd);
- AnotherEntry aEntry = new AnotherEntry();
- ProtPar pPar = new ProtPar();
+ KeyStoreTestSupport.AnotherEntry aEntry = new KeyStoreTestSupport.AnotherEntry();
+ KeyStoreTestSupport.ProtPar pPar = new KeyStoreTestSupport.ProtPar();
KeyStore [] kss = createKS();
assertNotNull("KeyStore objects were not created", kss);
for (int i = 0; i < kss.length; i++) {
@@ -742,13 +615,7 @@
}
byte[] enc = secKey.getEncoded();
byte[] enc1 = key1.getEncoded();
- if (enc != null) {
- for (int ii = 0; ii < enc.length; ii++) {
- if (enc[ii] != enc1[ii]) {
- fail("Diff. keys encoding");
- }
- }
- }
+ assertTrue("Diff. keys encoding", Arrays.equals(enc, enc1));
assertNull("Incorrect CertificateChain", kss[i].getCertificateChain(aliases[j]));
}
}
@@ -789,14 +656,10 @@
* setCertificateEntry(..) stores used entry and getCertificate(..) returns it
*
*/
- public void testEntry04() throws NoSuchAlgorithmException,
- IOException, CertificateException, KeyStoreException,
- UnrecoverableEntryException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
- MCertificate cert = new MCertificate("type", new byte[0]);
+ public void testEntry04() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
+ KeyStoreTestSupport.MCertificate cert = new KeyStoreTestSupport.MCertificate(
+ "type", new byte[0]);
KeyStore [] kss = createKS();
assertNotNull("KeyStore objects were not created", kss);
@@ -863,18 +726,13 @@
* returns cert
*
*/
- public void testEntry05() throws NoSuchAlgorithmException,
- IOException, CertificateException, KeyStoreException, InvalidKeySpecException,
- UnrecoverableKeyException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
- MCertificate certs[] = {
- new MCertificate("type1", new byte[10]),
- new MCertificate("type2", new byte[10])
- };
- MCertificate cert = new MCertificate("type", new byte[0]);
+ public void testEntry05() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
+ KeyStoreTestSupport.MCertificate certs[] = {
+ new KeyStoreTestSupport.MCertificate("type1", new byte[10]),
+ new KeyStoreTestSupport.MCertificate("type2", new byte[10]) };
+ KeyStoreTestSupport.MCertificate cert = new KeyStoreTestSupport.MCertificate(
+ "type", new byte[0]);
char[] pwd = new char[0];
TestKeyPair tkp = new TestKeyPair("DSA");
PrivateKey key = tkp.getPrivate();
@@ -899,7 +757,8 @@
} catch (KeyStoreException e) {
}
try {
- kss[i].setKeyEntry("ZZZ", key, pwd, new MCertificate[0]);
+ kss[i].setKeyEntry("ZZZ", key, pwd,
+ new KeyStoreTestSupport.MCertificate[0]);
fail("KeyStoreException or IllegalArgumentException should be thrown "
+ "when chain is empty and key is private");
} catch (KeyStoreException e) {
@@ -943,13 +802,7 @@
}
byte[] enc = key.getEncoded();
byte[] enc1 = key1.getEncoded();
- if (enc != null) {
- for (int ii = 0; ii < enc.length; ii++) {
- if (enc[ii] != enc1[ii]) {
- fail("Diff. keys encoding");
- }
- }
- }
+ assertTrue("Diff. keys encoding", Arrays.equals(enc, enc1));
Certificate [] cc = kss[i].getCertificateChain(aliases[j]);
assertEquals("Incorrect chain", cc.length, certs.length);
for (int t = 0; t < cc.length; t++) {
@@ -980,20 +833,17 @@
* deletes entry from KeyStore.
*
*/
- public void testEntry06() throws NoSuchAlgorithmException, IOException,
- CertificateException, KeyStoreException, InvalidKeySpecException,
- UnrecoverableEntryException, UnrecoverableKeyException {
- if (!JKSSupported) {
- fail(defaultType + " type does not supported");
- return;
- }
+ public void testEntry06() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
KeyStore.TrustedCertificateEntry tCert = new KeyStore.TrustedCertificateEntry(
- new MCertificate("type", new byte[0]));
+ new KeyStoreTestSupport.MCertificate("type", new byte[0]));
TestKeyPair tkp = new TestKeyPair("DSA");
- MCertificate certs[] = {
- new MCertificate("DSA", tkp.getPrivate().getEncoded()),
- new MCertificate("DSA", tkp.getPrivate().getEncoded()) };
+ KeyStoreTestSupport.MCertificate certs[] = {
+ new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+ .getEncoded()),
+ new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+ .getEncoded()) };
KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(tkp
.getPrivate(), certs);
char[] pwd = { 'p', 'a', 's', 's', 'w', 'd' };
@@ -1050,18 +900,14 @@
* KeyStore.PrivateKeyEntry is used.
*
*/
- public void testEntry07() throws NoSuchAlgorithmException,
- IOException, CertificateException, InvalidKeySpecException,
- KeyStoreException {
- if (!JKSSupported) {
- fail(NotSupportMsg);
- return;
- }
+ public void testEntry07() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
TestKeyPair tkp = new TestKeyPair("DSA");
- MCertificate certs[] = {
- new MCertificate("DSA", tkp.getPrivate().getEncoded()),
- new MCertificate("DSA", tkp.getPrivate().getEncoded())
- };
+ KeyStoreTestSupport.MCertificate certs[] = {
+ new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+ .getEncoded()),
+ new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+ .getEncoded()) };
PrivateKey privKey = tkp.getPrivate();
KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(privKey, certs);
char [] pwd = {'p', 'a', 's', 's', 'w', 'd'};
@@ -1110,13 +956,8 @@
* constructor
* Assertion: constructs KeyStore object
*/
- public void testKeyStoreConstr() throws NoSuchAlgorithmException,
- KeyStoreException, IOException,
- NoSuchAlgorithmException, CertificateException {
- if (!JKSSupported) {
- fail(defaultType + " type does not supported");
- return;
- }
+ public void testKeyStoreConstr() throws Exception {
+ assertTrue(NotSupportMsg, JKSSupported);
KeyStoreSpi spi = new MyKeyStoreSpi();
KeyStore keySt = new tmpKeyStore(spi, defaultProvider,
defaultType);
@@ -1138,119 +979,7 @@
} catch (NullPointerException e) {
}
}
- public static void main(String args[]) {
- junit.textui.TestRunner.run(KeyStore1Test.class);
- }
-
- /**
- * Additional class to create SecretKey object
- */
- public class SKey implements SecretKey {
- private String type;
- private byte[] encoded;
-
- public SKey(String type, byte[] encoded) {
- this.type = type;
- this.encoded = encoded;
- }
-
- public String getAlgorithm() {
- return type;
- }
-
- public byte[] getEncoded() {
- return encoded;
- }
-
- public String getFormat() {
- return "test";
- }
- }
- /**
- * Additional class to create PrivateKey object
- */
- public class MyPrivateKey implements PrivateKey {
- private String algorithm;
- private String format;
- private byte [] encoded;
-
- public MyPrivateKey(String algorithm, String format, byte[] encoded) {
- this.algorithm = algorithm;
- this.format = format;
- this.encoded = encoded;
- }
- public String getAlgorithm() {
- return algorithm;
- }
- public String getFormat() {
- return format;
- }
- public byte[] getEncoded() {
- return encoded;
- }
- }
-
- /**
- * Additional class to create Certificate and Key objects
- */
- public class MCertificate extends Certificate {
- private final byte[] encoding;
-
- private final String type;
-
- public MCertificate(String type, byte[] encoding) {
- super(type);
- this.encoding = encoding;
- this.type = type;
- }
-
- public byte[] getEncoded() throws CertificateEncodingException {
- return encoding.clone();
- }
-
- public void verify(PublicKey key) throws CertificateException,
- NoSuchAlgorithmException, InvalidKeyException,
- NoSuchProviderException, SignatureException {
- }
-
- public void verify(PublicKey key, String sigProvider)
- throws CertificateException, NoSuchAlgorithmException,
- InvalidKeyException, NoSuchProviderException, SignatureException {
- }
-
- public String toString() {
- return "[MCertificate, type: " + getType() + "]";
- }
-
- public PublicKey getPublicKey() {
- return new PublicKey() {
- public String getAlgorithm() {
- return type;
- }
-
- public byte[] getEncoded() {
- return encoding;
- }
-
- public String getFormat() {
- return "test";
- }
- };
- }
- }
-
- /**
- * Additional class to create ProtectionParameter object
- */
- public class ProtPar implements KeyStore.ProtectionParameter {
- }
-
- /**
- * Additional class to create KeyStore.Entry object
- */
- public class AnotherEntry implements KeyStore.Entry {
- }
}
/**
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl2Test.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl2Test.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl2Test.java (working copy)
@@ -19,35 +19,41 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.Security;
+import java.security.UnrecoverableEntryException;
+import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
+import java.util.Date;
import javax.crypto.spec.SecretKeySpec;
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
import org.apache.harmony.security.tests.support.MyLoadStoreParams;
import org.apache.harmony.security.tests.support.SpiEngUtils;
+import org.apache.harmony.security.tests.support.SpiEngUtils.MyProvider;
import org.apache.harmony.security.tests.support.cert.MyCertificate;
import junit.framework.TestCase;
-import java.util.Date;
-
-
/**
* Tests for KeyStore constructor and methods
*
*/
-public class KeyStore2Test extends TestCase {
+public class KeyStore_Impl2Test extends TestCase {
- private static final String KeyStoreProviderClass = "org.apache.harmony.security.tests.support.MyKeyStoreSpi";
+ private static final String KeyStoreProviderClass =
+ "org.apache.harmony.security.tests.support.MyKeyStoreSpi";
private static final String defaultAlg = "KeyStore";
@@ -68,7 +74,7 @@
protected void setUp() throws Exception {
super.setUp();
mProv = (new SpiEngUtils()).new MyProvider("MyKSProvider",
- "Testing provider", KeyStore1Test.srvKeyStore.concat(".").concat(
+ "Testing provider", KeyStoreTestSupport.srvKeyStore.concat(".").concat(
defaultAlg), KeyStoreProviderClass);
Security.insertProviderAt(mProv, 2);
}
@@ -81,15 +87,6 @@
Security.removeProvider(mProv.getName());
}
- /**
- * Constructor for SecurityManagerFactoryTest2.
- *
- * @param arg0
- */
- public KeyStore2Test(String arg0) {
- super(arg0);
- }
-
private void checkResult(KeyStore keyS) throws KeyStoreException,
IOException, CertificateException, NoSuchAlgorithmException,
UnrecoverableKeyException {
@@ -433,8 +430,5 @@
checkResult(keyS);
}
}
- public static void main(String args[]) {
- junit.textui.TestRunner.run(KeyStore2Test.class);
- }
}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/SecureRandom_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/SecureRandom_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/SecureRandom_ImplTest.java (working copy)
@@ -19,20 +19,23 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
+import java.security.NoSuchAlgorithmException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
import java.util.Arrays;
import java.util.Random;
import junit.framework.TestCase;
-
/**
*
* Tests for internal Secure Random implementation based on Random
*
*/
-public class SecureRandom2Test extends TestCase {
+public class SecureRandom_ImplTest extends TestCase {
/**
* Registered providers
@@ -100,12 +103,9 @@
byte[] b2 = new byte[8];
sr.nextBytes(b1);
r.nextBytes(b2);
- if (!Arrays.equals(b1, b2)) {
- fail("incorrect random bytes");
- }
+ assertTrue("incorrect random bytes", Arrays.equals(b1, b2));
}
-
/*
* Class under test for SecureRandom getInstance(String)
*/
@@ -116,19 +116,14 @@
} catch (NoSuchAlgorithmException e) {
}
}
-
public final void testGetProvider() {
- if (new SecureRandom().getProvider() != null) {
- fail("Non null provider");
- }
+ assertNull("Non null provider", new SecureRandom().getProvider());
}
public final void testGetAlgorithm() {
SecureRandom sr = new SecureRandom();
- if (!sr.getAlgorithm().equals("java.util.Random")) {
- fail("Incorrect algorithm");
- }
+ assertEquals("Incorrect algorithm", "java.util.Random", sr.getAlgorithm());
}
/*
@@ -150,19 +145,11 @@
sr.setSeed(seed1);
}
- /**
- *
- *
- */
public final void testGetSeed() {
byte[] seed = SecureRandom.getSeed(5);
new SecureRandom(seed).nextBytes(new byte[20]);
}
- /**
- *
- *
- */
public final void testGenerateSeed() {
SecureRandom sr = new SecureRandom();
byte[] seed = sr.generateSeed(5);
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl3Test.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl3Test.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl3Test.java (working copy)
@@ -19,29 +19,35 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.PrivateKey;
import java.security.Provider;
import java.security.Security;
import java.security.cert.Certificate;
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport.MCertificate;
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport.MyPrivateKey;
import org.apache.harmony.security.tests.support.MyLoadStoreParams;
import org.apache.harmony.security.tests.support.SpiEngUtils;
+import org.apache.harmony.security.tests.support.SpiEngUtils.MyProvider;
import junit.framework.TestCase;
-
/**
* Tests for KeyStore constructor and methods
*
*/
-public class KeyStore3Test extends TestCase {
+public class KeyStore_Impl3Test extends TestCase {
- private static final String KeyStoreProviderClass = "java.security.MyKeyStore";
+ private static final String KeyStoreProviderClass = "org.apache.harmony.security.tests.support.MyKeyStore";
private static final String defaultType = "KeyStore";
@@ -56,9 +62,7 @@
Provider mProv;
public KeyStore[] createKS() throws Exception {
- if (!KSSupported) {
- fail(NotSupportMsg);
- }
+ assertTrue(NotSupportMsg, KSSupported);
KeyStore[] kpg = new KeyStore[3];
kpg[0] = KeyStore.getInstance(defaultType);
@@ -70,11 +74,11 @@
protected void setUp() throws Exception {
super.setUp();
mProv = (new SpiEngUtils()).new MyProvider("MyKSProvider",
- "Testing provider", KeyStore1Test.srvKeyStore.concat(".")
+ "Testing provider", KeyStoreTestSupport.srvKeyStore.concat(".")
.concat(defaultType), KeyStoreProviderClass);
Security.insertProviderAt(mProv, 2);
defaultProvider = SpiEngUtils.isSupport(defaultType,
- KeyStore1Test.srvKeyStore);
+ KeyStoreTestSupport.srvKeyStore);
KSSupported = (defaultProvider != null);
defaultProviderName = (KSSupported ? defaultProvider.getName() : null);
}
@@ -88,15 +92,6 @@
}
/**
- * Constructor for SecurityManagerFactoryTest2.
- *
- * @param arg0
- */
- public KeyStore3Test(String arg0) {
- super(arg0);
- }
-
- /**
* Test for load(InputStream stream, char[] password)
* store(InputStream stream, char[] password)
* size()
@@ -110,19 +105,16 @@
*/
public void testLoadStore01() throws Exception {
- if (!KSSupported) {
- fail(NotSupportMsg);
- }
+ assertTrue(NotSupportMsg, KSSupported);
String tType = "TestType";
- KeyStore1Test keyStoreT1 = new KeyStore1Test("proba");
KeyStore.TrustedCertificateEntry tCert = new KeyStore.TrustedCertificateEntry(
- keyStoreT1.new MCertificate("type", new byte[0]));
+ new KeyStoreTestSupport.MCertificate("type", new byte[0]));
Certificate certs[] = {
- keyStoreT1.new MCertificate(tType, new byte[10]),
- keyStoreT1.new MCertificate(tType, new byte[20]) };
- PrivateKey pk = keyStoreT1.new MyPrivateKey(tType, "", new byte[10]);
+ new KeyStoreTestSupport.MCertificate(tType, new byte[10]),
+ new KeyStoreTestSupport.MCertificate(tType, new byte[20]) };
+ PrivateKey pk = new KeyStoreTestSupport.MyPrivateKey(tType, "", new byte[10]);
KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(pk, certs);
char[] pwd = { 'p', 'a', 's', 's', 'w', 'd' };
KeyStore.PasswordProtection pPath = new KeyStore.PasswordProtection(pwd);
@@ -213,91 +205,4 @@
kss1[i].getCreationDate(aliases[4]));
}
}
-
- /**
- * Test for load(LoadStoreParameter param)
- * store(LoadStoreParameter param)
- * methods
- * Assertions: throw IllegalArgumentException if param is null;
- */
- public void testLoadStore02() throws Exception {
- if (!KSSupported) {
- fail(NotSupportMsg);
- }
-
- KeyStore[] kss = createKS();
- assertNotNull("KeyStore objects were not created", kss);
-
- for (int i = 0; i < kss.length; i++) {
- try {
- kss[i].load(null);
- fail("IOException or IllegalArgumentException should be thrown for null parameter");
- } catch (IOException e) {
- } catch (IllegalArgumentException e) {
- }
- kss[i].load(null, null);
- try {
- kss[i].store(null);
- fail("IOException or IllegalArgumentException should be thrown for nill parameter");
- } catch (IOException e) {
- } catch (IllegalArgumentException e) {
- }
- }
- KeyStore.LoadStoreParameter lParam = new MyLoadStoreParams(
- new KeyStore.PasswordProtection(new char[0]));
- for (int i = 0; i < kss.length; i++) {
- kss[i].load(lParam);
- assertEquals("Incorrect result", kss[i].size(), 0);
- kss[i].store(lParam);
- }
- }
-
-
- /**
- * Test for setKeyEntry(String alias, bute[] key, Certificate[] chain)
- * method
- * Assertion: stores KeyEntry.
- */
- public void testSetKeyEntry() throws Exception {
- if (!KSSupported) {
- fail(NotSupportMsg);
- }
-
- KeyStore[] kss = createKS();
- assertNotNull("KeyStore objects were not created", kss);
- byte[] kk = { (byte) 1, (byte) 2, (byte) 127, (byte) 77 };
- String alias = "keyEntry";
- char[] pwd = new char[0];
- byte[] res;
- KeyStore1Test keyStoreT1 = new KeyStore1Test("proba");
- Certificate certs[] = {
- keyStoreT1.new MCertificate(alias, kk),
- keyStoreT1.new MCertificate(alias, kk) };
- for (int i = 0; i < kss.length; i++) {
- kss[i].load(null, null);
- try {
- kss[i].setKeyEntry("proba", null, null);
- fail("KeyStoreException must be thrown");
- } catch (KeyStoreException e) {
- }
- kss[i].setKeyEntry(alias, kk, certs);
- res = kss[i].getKey(alias, pwd).getEncoded();
- assertEquals(kk.length, res.length);
- for (int j = 0; j < res.length; j++) {
- assertEquals(res[j], kk[j]);
- }
- assertEquals(kss[i].getCertificateChain(alias).length, certs.length);
- kss[i].setKeyEntry(alias, kk, null);
- res = kss[i].getKey(alias, pwd).getEncoded();
- assertEquals(kk.length, res.length);
- for (int j = 0; j < res.length; j++) {
- assertEquals(res[j], kk[j]);
- }
- assertNull(kss[i].getCertificateChain(alias));
- }
- }
-
- public static void main(String args[]) {
- junit.textui.TestRunner.run(KeyStore3Test.class);
- }
}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java (revision 0)
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Alexander V. Astapchuk
+* @version $Revision$
+*/
+
+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)
+ * 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)
+ * 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 avoding 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();
+ }
+ }
+
+}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator_ImplTest.java (revision 0)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.security.AlgorithmParameterGenerator;
+import java.security.Provider;
+import java.security.SecureRandom;
+
+import org.apache.harmony.security.tests.support.SpiEngUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for AlgorithmParameterGenerator class constructors and
+ * methods.
+ *
+ */
+
+public class AlgorithmParameterGenerator_ImplTest extends TestCase {
+
+ private static String validAlgName = "DSA";
+
+ public static final String srvAlgorithmParameterGenerator = "AlgorithmParameterGenerator";
+
+
+ private static String validProviderName = null;
+
+ private static Provider validProvider = null;
+
+ private static boolean DSASupported = false;
+
+ static {
+ validProvider = SpiEngUtils.isSupport(
+ validAlgName,
+ srvAlgorithmParameterGenerator);
+ DSASupported = (validProvider != null);
+ validProviderName = (DSASupported ? validProvider.getName() : null);
+ }
+
+ protected AlgorithmParameterGenerator[] createAPGen() throws Exception {
+ if (!DSASupported) {
+ fail(validAlgName + " algorithm is not supported");
+ return null;
+ }
+ AlgorithmParameterGenerator[] apg = new AlgorithmParameterGenerator[3];
+ apg[0] = AlgorithmParameterGenerator.getInstance(validAlgName);
+ apg[1] = AlgorithmParameterGenerator.getInstance(validAlgName,
+ validProvider);
+ apg[2] = AlgorithmParameterGenerator.getInstance(validAlgName,
+ validProviderName);
+ return apg;
+ }
+
+ /**
+ * Test for init(int size) and
+ * init(int size, SecureRandom random methods
+ * Assertion: throws InvalidParameterExceptiom when size is incorrect
+ */
+ public void testAlgorithmParameterGenerator11() throws Exception {
+ if (!DSASupported) {
+ fail(validAlgName + " algorithm is not supported");
+ return;
+ }
+ int [] keys = {-10000, -512, -1, 0, 10000};
+ SecureRandom random = new SecureRandom();
+ AlgorithmParameterGenerator[] apgs = createAPGen();
+ assertNotNull("AlgorithmParameterGenerator objects were not created",
+ apgs);
+
+ for (int i = 0; i < apgs.length; i++) {
+ for (int j = 0; j < keys.length; j++) {
+ apgs[i].init(keys[j]);
+ apgs[i].init(keys[j], random);
+ apgs[i].init(keys[j], null);
+ }
+ apgs[i].init(1024);
+ apgs[i].init(1024, random);
+ }
+ }
+
+}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Policy_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Policy_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Policy_ImplTest.java (revision 0)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Alexey V. Varlamov
+* @version $Revision$
+*/
+
+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 Policy
+ *
+ */
+
+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));
+ assertFalse(policy.implies(null, null));
+
+ ProtectionDomain pd = new ProtectionDomain(null, policy.pc);
+ policy.pc = null;
+ assertTrue(policy.implies(pd, sp));
+ assertFalse(policy.implies(pd, new AllPermission()));
+ }
+
+}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Timestamp_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Timestamp_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Timestamp_ImplTest.java (revision 0)
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Alexander V. Astapchuk
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.security.Timestamp;
+import java.security.cert.CertPath;
+import java.util.Date;
+
+import org.apache.harmony.security.tests.support.cert.MyCertPath;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for Timestamp class fields and methods
+ *
+ */
+
+public class Timestamp_ImplTest extends TestCase {
+
+ private Date now = new Date();
+
+ private static final byte[] encoding = { 1, 2, 3 };
+
+ private CertPath cpath = new MyCertPath(encoding);
+
+ public void testHashCode() {
+ assertTrue(new Timestamp(now, cpath).hashCode() == (now.hashCode() ^ cpath
+ .hashCode()));
+ }
+
+}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java (revision 0)
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Alexey V. Varlamov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for PermissionCollection
+ *
+ */
+
+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 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 toString() transformation with different elements. */
+ public void testToString()
+ {
+ // no elements
+ PermissionCollection pc = new RealPermissionCollection(null);
+ String superString = pc.getClass().getName() + "@" + Integer.toHexString(pc.hashCode());
+ assertEquals("no elements", superString + " (\n)", pc.toString());
+
+ // several elements
+ pc = new RealPermissionCollection(Arrays.asList(new Object[]{"aaa", "bbb", "ccc"}));
+ superString = pc.getClass().getName() + "@" + Integer.toHexString(pc.hashCode());
+ assertEquals("several elements", superString + " (\n aaa\n bbb\n ccc\n)", pc.toString());
+ }
+
+}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl1Test.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl1Test.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl1Test.java (revision 0)
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import org.apache.harmony.security.tests.support.MyMessageDigest1;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for MessageDigest constructor and methods
+ *
+ */
+public class MessageDigest_Impl1Test extends TestCase {
+
+ /*
+ * Class under test for int digest(byte[], int, int)
+ */
+ public void testDigestbyteArrayintint() throws Exception {
+ MyMessageDigest1 md = new MyMessageDigest1("ABC");
+ byte[] b = {1, 2, 3, 4, 5};
+ assertEquals("incorrect result", 0, md.digest(b, 2, 3));
+ assertTrue("digest failed", md.runEngineDigest);
+ }
+
+ /*
+ * Class under test for String toString()
+ */
+ public void testToString() {
+ MyMessageDigest1 md = new MyMessageDigest1("ABC");
+ assertEquals("incorrect result", "MESSAGE DIGEST ABC", md.toString());
+ }
+}
+
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl2Test.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl2Test.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl2Test.java (working copy)
@@ -19,8 +19,12 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
+import java.security.MessageDigest;
+import java.security.Provider;
+import java.security.Security;
+
import org.apache.harmony.security.tests.support.MyMessageDigest1;
import org.apache.harmony.security.tests.support.MyMessageDigest2;
@@ -30,7 +34,7 @@
* Tests for MessageDigest constructor and methods
*
*/
-public class MessageDigest2Test extends TestCase {
+public class MessageDigest_Impl2Test extends TestCase {
/**
* Provider
@@ -57,177 +61,103 @@
/*
* Class under test for MessageDigest getInstance(String)
*/
- public void testGetInstanceString1() {
- MessageDigest md1 = null;
-
- try {
- md1 = MessageDigest.getInstance("ABC");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
+ public void testGetInstanceString1() throws Exception {
+ MessageDigest md1 = MessageDigest.getInstance("ABC");
checkMD1(md1, p);
}
/*
* Class under test for MessageDigest getInstance(String)
*/
- public void testGetInstanceString2() {
- MessageDigest md2 = null;
-
- try {
- md2 = MessageDigest.getInstance("CBA");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
+ public void testGetInstanceString2() throws Exception {
+ MessageDigest md2 = MessageDigest.getInstance("CBA");
checkMD2(md2, p);
}
/*
* Class under test for MessageDigest getInstance(String, String)
*/
- public void testGetInstanceStringString1() {
- MessageDigest md1 = null;
-
- try {
- md1 = MessageDigest.getInstance("ABC", "MyProvider");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- } catch (NoSuchProviderException e) {
- fail(e.toString());
- }
+ public void testGetInstanceStringString1() throws Exception {
+ MessageDigest md1 = MessageDigest.getInstance("ABC", "MyProvider");
checkMD1(md1, p);
}
/*
* Class under test for MessageDigest getInstance(String, String)
*/
- public void testGetInstanceStringString2() {
- MessageDigest md2 = null;
- try {
- md2 = MessageDigest.getInstance("CBA", "MyProvider");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- } catch (NoSuchProviderException e) {
- fail(e.toString());
- }
+ public void testGetInstanceStringString2() throws Exception {
+ MessageDigest md2 = MessageDigest.getInstance("CBA", "MyProvider");
checkMD2(md2, p);
}
/*
* Class under test for MessageDigest getInstance(String, Provider)
*/
- public void testGetInstanceStringProvider1() {
- MessageDigest md1 = null;
-
+ public void testGetInstanceStringProvider1() throws Exception {
Provider p = new MyProvider();
- try {
- md1 = MessageDigest.getInstance("ABC", p);
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
+ MessageDigest md1 = MessageDigest.getInstance("ABC", p);
checkMD1(md1, p);
}
/*
* Class under test for MessageDigest getInstance(String, Provider)
*/
- public void testGetInstanceStringProvider2() {
- MessageDigest md2 = null;
- Provider p = new MyProvider();
- try {
- md2 = MessageDigest.getInstance("CBA", p);
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
- checkMD2(md2, p);
- }
+ public void testGetInstanceStringProvider2() throws Exception {
+ Provider p = new MyProvider();
+ MessageDigest md2 = MessageDigest.getInstance("CBA", p);
+ checkMD2(md2, p);
+ }
- private void checkMD1(MessageDigest md1, Provider p) {
- byte[] b = {1, 2, 3, 4, 5};
-
- if (!(md1 instanceof MyMessageDigest1)) {
- fail("getInstance() failed");
- }
- if (md1.getProvider() != p) {
- fail("getProvider() failed");
- }
- if (!"ABC".equals(md1.getAlgorithm())) {
- fail("getAlgorithm() failed");
- }
- md1.update((byte)1);
- md1.update(b, 1, 4);
- if (!((MyMessageDigest1)md1).runEngineUpdate1 ||
- !((MyMessageDigest1)md1).runEngineUpdate2) {
- fail("update failed");
- }
- try {
- if (md1.digest() != null) {
- fail("incorrect digest result");
- }
- if (md1.digest(b, 2, 3) != 0) {
- fail("incorrect digest result");
- }
- } catch (java.security.DigestException e) {
- fail(e.toString());
- }
- if (!((MyMessageDigest1)md1).runEngineDigest) {
- fail("update failed");
- }
- md1.reset();
- if (!((MyMessageDigest1)md1).runEngineReset) {
- fail("reset failed");
- }
- if (md1.getDigestLength() != 0) {
- fail("getDigestLength failed");
- }
- try {
- md1.clone();
- fail("No expected CloneNotSupportedException");
- } catch (CloneNotSupportedException e) {
- }
- }
+ private void checkMD1(MessageDigest md1, Provider p) throws Exception {
+ byte[] b = { 1, 2, 3, 4, 5 };
+ assertTrue("getInstance() failed", md1 instanceof MyMessageDigest1);
+ assertEquals("getProvider() failed", p, md1.getProvider());
+ assertEquals("getAlgorithm() failed", "ABC", md1.getAlgorithm());
+
+ md1.update((byte) 1);
+ md1.update(b, 1, 4);
+ assertTrue("update failed", ((MyMessageDigest1) md1).runEngineUpdate1);
+ assertTrue("update failed", ((MyMessageDigest1) md1).runEngineUpdate2);
+
+ assertNull("incorrect digest result", md1.digest());
+ assertEquals("getProvider() failed", 0, md1.digest(b, 2, 3));
+ assertTrue("digest failed", ((MyMessageDigest1) md1).runEngineDigest);
+
+ md1.reset();
+ assertTrue("reset failed", ((MyMessageDigest1) md1).runEngineReset);
+
+ assertEquals("getDigestLength() failed", 0, md1.getDigestLength());
+ try {
+ md1.clone();
+ fail("No expected CloneNotSupportedException");
+ } catch (CloneNotSupportedException e) {
+ }
+ }
- private void checkMD2(MessageDigest md2, Provider p) {
- byte[] b = {1, 2, 3, 4, 5};
-
- if (md2.getProvider() != p) {
- fail("getProvider() failed");
- }
- if (!"CBA".equals(md2.getAlgorithm())) {
- fail("getAlgorithm() failed");
- }
- md2.update((byte)1);
- md2.update(b, 1, 3);
- if (!MyMessageDigest2.runEngineUpdate1 ||
- !MyMessageDigest2.runEngineUpdate2) {
- fail("update failed");
- }
- try {
- if (md2.digest() != null) {
- fail("incorrect digest result");
- }
- if (md2.digest(b, 2, 3) != 0) {
- fail("incorrect digest result");
- }
- } catch (java.security.DigestException e) {
- fail(e.toString());
- }
- if (!MyMessageDigest2.runEngineDigest) {
- fail("update failed");
- }
- md2.reset();
- if (!MyMessageDigest2.runEngineReset) {
- fail("reset failed");
- }
- if (md2.getDigestLength() != 0) {
- fail("getDigestLength failed");
- }
- try {
- md2.clone();
- fail("No expected CloneNotSupportedException");
- } catch (CloneNotSupportedException e) {
- }
- }
+ private void checkMD2(MessageDigest md2, Provider p) throws Exception {
+ byte[] b = { 1, 2, 3, 4, 5 };
+ assertEquals("getProvider() failed", p, md2.getProvider());
+ assertEquals("getAlgorithm() failed", "CBA", md2.getAlgorithm());
+
+ md2.update((byte) 1);
+ md2.update(b, 1, 3);
+ assertTrue("update failed", MyMessageDigest2.runEngineUpdate1);
+ assertTrue("update failed", MyMessageDigest2.runEngineUpdate2);
+
+ assertNull("incorrect digest result", md2.digest());
+ assertEquals("getProvider() failed", 0, md2.digest(b, 2, 3));
+ assertTrue("digest failed", MyMessageDigest2.runEngineDigest);
+
+ md2.reset();
+ assertTrue("reset failed", MyMessageDigest2.runEngineReset);
+
+ assertEquals("getDigestLength() failed", 0, md2.getDigestLength());
+ try {
+ md2.clone();
+ fail("No expected CloneNotSupportedException");
+ } catch (CloneNotSupportedException e) {
+ }
+ }
private class MyProvider extends Provider {
MyProvider() {
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/ProviderService_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/ProviderService_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/ProviderService_ImplTest.java (revision 0)
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.security.Provider;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for Provider.Service constructor and methods
+ *
+ */
+public class ProviderService_ImplTest extends TestCase {
+
+ /*
+ * Class under test for String toString()
+ */
+ public void testToString() {
+ Provider p = new MyProvider();
+ Provider.Service s = new Provider.Service(p, "type", "algorithm",
+ "className", null, null);
+ assertEquals("first toString() failed",
+ "Provider MyProvider Service type.algorithm className",
+ s.toString());
+
+ HashMap hm = new HashMap();
+ hm.put("attribute", "value");
+ hm.put("KeySize", "1024");
+ hm.put("AAA", "BBB");
+
+ s = new Provider.Service(p, "type", "algorithm", "className",
+ null, hm);
+ assertTrue("second toString() failed", s.toString().startsWith(
+ "Provider MyProvider Service type.algorithm className\n"
+ + "Attributes "));
+ }
+
+ class MyProvider extends Provider {
+ MyProvider() {
+ super("MyProvider", 1.0, "Provider for testing");
+ put("MessageDigest.SHA-1", "SomeClassName");
+ }
+ }
+}
Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Permissions_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Permissions_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/Permissions_ImplTest.java (revision 0)
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Alexey V. Varlamov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+import java.security.AllPermission;
+import java.security.BasicPermission;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+import java.security.SecurityPermission;
+import java.security.UnresolvedPermission;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for Permissions
+ *
+ */
+
+public class Permissions_ImplTest extends TestCase {
+
+ /**
+ * A permission is implied by this collection, if either of the following is
+ * true:
+ *
+ * - This collection contains AllPermission;
+ *
- This collection has elements of the same type as the permission
+ * being checked, and they imply it;
+ *
- This collection has UnresolvedPermissions which can be resolved to
+ * the checked type, and after resolving they imply the checked one.
+ *
+ * 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]));
+ }
+ }
+ }
Index: modules/security/src/test/impl/java.injected/java/security/Signature_Impl1Test.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/Signature_Impl1Test.java (revision 0)
+++ modules/security/src/test/impl/java.injected/java/security/Signature_Impl1Test.java (revision 0)
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package java.security;
+
+import org.apache.harmony.security.tests.support.MySignature1;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for Signature constructor and methods
+ *
+ */
+public class Signature_Impl1Test extends TestCase {
+
+ /*
+ * Class under test for int sign(byte[], int, int)
+ */
+ public void testSignbyteArrayintint() {
+ MySignature1 s = new MySignature1("ABC");
+ byte[] b = new byte[8];
+ try {
+ s.sign(b, 0, 5);
+ fail("No expected SignatureException 1");
+ } catch (SignatureException e) {
+ }
+
+ try {
+ s.initVerify(new MyPublicKey());
+ } catch (InvalidKeyException e) {
+ fail(e.toString());
+ }
+
+ try {
+ s.sign(b, 0, 5);
+ fail("No expected SignatureException 1");
+ } catch (SignatureException e) {
+ }
+
+ try {
+ s.initSign(new MyPrivateKey());
+ } catch (InvalidKeyException e) {
+ fail(e.toString());
+ }
+
+ try {
+ s.sign(b, 0, 5);
+ } catch (SignatureException e) {
+ fail(e.toString());
+ }
+ if (s.getState() != Signature.SIGN) {
+ fail("Incorrect state");
+ }
+ if (!s.runEngineSign) {
+ fail("sign() failed");
+ }
+ }
+
+ /*
+ * Class under test for String toString()
+ */
+ public void testToString() {
+ MySignature1 s = new MySignature1("ABC");
+ assertEquals("toString() failed", "SIGNATURE ABC state: UNINITIALIZED",
+ s.toString());
+ }
+
+ private class MyKey implements Key {
+ public String getFormat() {
+ return "123";
+ }
+ public byte[] getEncoded() {
+ return null;
+ }
+ public String getAlgorithm() {
+ return "aaa";
+ }
+ }
+
+ private class MyPublicKey extends MyKey implements PublicKey {}
+
+ private class MyPrivateKey extends MyKey implements PrivateKey {}
+
+}
Index: modules/security/src/test/impl/java.injected/java/security/Signature_Impl2Test.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/Signature_Impl2Test.java (revision 412994)
+++ modules/security/src/test/impl/java.injected/java/security/Signature_Impl2Test.java (working copy)
@@ -30,7 +30,7 @@
* Tests for Signature constructor and methods
*
*/
-public class Signature2Test extends TestCase {
+public class Signature_Impl2Test extends TestCase {
/**
* Provider
@@ -57,294 +57,145 @@
/*
* Class under test for Signature getInstance(String)
*/
- public void testGetInstanceString1() {
- Signature sig = null;
-
- try {
- sig = Signature.getInstance("ABC");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
+ public void testGetInstanceString1() throws Exception {
+ Signature sig = Signature.getInstance("ABC");
checkSig1(sig, p);
}
/*
* Class under test for Signature getInstance(String)
*/
- public void testGetInstanceString2() {
- Signature sig = null;
-
- try {
- sig = Signature.getInstance("CBA");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
+ public void testGetInstanceString2() throws Exception {
+ Signature sig = Signature.getInstance("CBA");
checkSig2(sig, p);
}
/*
* Class under test for Signature getInstance(String, String)
*/
- public void testGetInstanceStringString1() {
- Signature sig = null;
-
- try {
- sig = Signature.getInstance("ABC", "MyProvider");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- } catch (NoSuchProviderException e) {
- fail(e.toString());
- }
+ public void testGetInstanceStringString1() throws Exception {
+ Signature sig = Signature.getInstance("ABC", "MyProvider");
checkSig1(sig, p);
}
/*
* Class under test for Signature getInstance(String, String)
*/
- public void testGetInstanceStringString2() {
- Signature sig = null;
-
- try {
- sig = Signature.getInstance("CBA", "MyProvider");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- } catch (NoSuchProviderException e) {
- fail(e.toString());
- }
+ public void testGetInstanceStringString2() throws Exception {
+ Signature sig = Signature.getInstance("CBA", "MyProvider");
checkSig2(sig, p);
-
}
/*
* Class under test for Signature getInstance(String, Provider)
*/
- public void testGetInstanceStringProvider1() {
+ public void testGetInstanceStringProvider1() throws Exception {
Provider p1 = new MyProvider();
- Signature sig = null;
-
- try {
- sig = Signature.getInstance("ABC", p1);
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
+ Signature sig = Signature.getInstance("ABC", p1);
checkSig1(sig, p1);
}
/*
* Class under test for Signature getInstance(String, Provider)
*/
- public void testGetInstanceStringProvider2() {
+ public void testGetInstanceStringProvider2() throws Exception {
Provider p2 = new MyProvider();
- Signature sig = null;
-
- try {
- sig = Signature.getInstance("CBA", p2);
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
+ Signature sig = Signature.getInstance("CBA", p2);
checkSig2(sig, p2);
}
- private void checkSig1(Signature s, Provider p) {
- byte[] b = {1, 2, 3, 4};
- if (!(s instanceof MySignature1)) {
- fail("getInstance() failed");
- }
- if (s.getProvider() != p) {
- System.out.println(p);
- System.out.println(s.getProvider());
- fail("getProvider() failed");
- }
+ private void checkSig1(Signature s, Provider p) throws Exception {
+ byte[] b = { 1, 2, 3, 4 };
+ assertTrue("getInstance() failed", s instanceof MySignature1);
+ assertEquals("getProvider() failed", p, s.getProvider());
+ assertEquals("getAlgorithm() failed", "ABC", s.getAlgorithm());
- if (!"ABC".equals(s.getAlgorithm())) {
- fail("getAlgorithm() failed");
- }
- try {
- s.sign();
- fail("No expected SignatureException");
- } catch (SignatureException e) {
- }
+ try {
+ s.sign();
+ fail("No expected SignatureException");
+ } catch (SignatureException e) {
+ }
- try {
- s.initVerify(new MyPublicKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
-
- try {
- s.sign();
- fail("No expected SignatureException");
- } catch (SignatureException e) {
- }
-
- try {
- s.initSign(new MyPrivateKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
- try {
- s.sign();
- } catch (SignatureException e) {
- fail(e.toString());
- }
- if (((MySignature1)s).getState() != Signature.SIGN) {
- fail("Incorrect state");
- }
- if (!((MySignature1)s).runEngineSign) {
- fail("sign() failed");
- }
-
- try {
- s.initVerify(new MyPublicKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
-
- try {
- s.update((byte)1);
- } catch (SignatureException e) {
- fail(e.toString());
- }
-
- try {
- s.initSign(new MyPrivateKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
- try {
- s.update((byte)1);
- } catch (SignatureException e) {
- fail(e.toString());
- }
- if (((MySignature1)s).getState() != Signature.SIGN) {
- fail("Incorrect state");
- }
- if (!((MySignature1)s).runEngineUpdate1) {
- fail("update() failed");
- }
-
- try {
- s.initSign(new MyPrivateKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
-
- try {
- s.verify(b);
- fail("No expected SignatureException");
- } catch (SignatureException e) {
- }
-
- try {
- s.initVerify(new MyPublicKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
-
- try {
- s.verify(b);
- } catch (SignatureException e) {
- fail(e.toString());
- }
-
- if (((MySignature1)s).getState() != Signature.VERIFY) {
- fail("Incorrect state");
- }
- if (!((MySignature1)s).runEngineVerify) {
- fail("verify() failed");
- }
- }
+ s.initVerify(new MyPublicKey());
+
+ try {
+ s.sign();
+ fail("No expected SignatureException");
+ } catch (SignatureException e) {
+ }
+
+ s.initSign(new MyPrivateKey());
+ s.sign();
+ assertEquals("Incorrect state", Signature.SIGN, ((MySignature1) s)
+ .getState());
+ assertTrue("sign() failed", ((MySignature1) s).runEngineSign);
+
+ s.initVerify(new MyPublicKey());
+ s.update((byte) 1);
+
+ s.initSign(new MyPrivateKey());
+ s.update((byte) 1);
+
+ assertEquals("Incorrect state", Signature.SIGN, ((MySignature1) s)
+ .getState());
+ assertTrue("sign() failed", ((MySignature1) s).runEngineUpdate1);
+
+ s.initSign(new MyPrivateKey());
+
+ try {
+ s.verify(b);
+ fail("No expected SignatureException");
+ } catch (SignatureException e) {
+ }
+ s.initVerify(new MyPublicKey());
+ s.verify(b);
+ assertEquals("Incorrect state", Signature.VERIFY, ((MySignature1) s)
+ .getState());
+ assertTrue("verify() failed", ((MySignature1) s).runEngineVerify);
+ }
- private void checkSig2(Signature s, Provider p) {
- byte[] b = {1, 2, 3, 4};
- if (s.getProvider() != p) {
- fail("getProvider() failed");
- }
- if (!"CBA".equals(s.getAlgorithm())) {
- fail("getAlgorithm() failed");
- }
- try {
- s.initVerify(new MyCertificate());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
- try {
- s.sign(b, 0, 5);
- fail("No expected SignatureException 1");
- } catch (SignatureException e) {
- }
-
- try {
- s.initSign(new MyPrivateKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
-
- try {
- s.sign(b, 0, 3);
- } catch (SignatureException e) {
- fail(e.toString());
- }
+ private void checkSig2(Signature s, Provider p) throws Exception {
+ byte[] b = { 1, 2, 3, 4 };
- if (!MySignature2.runEngineSign) {
- fail("sign() failed");
- }
- try {
- s.update(b);
- } catch (SignatureException e) {
- fail(e.toString());
- }
-
- try {
- s.initSign(new MyPrivateKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
- try {
- s.update(b);
- } catch (SignatureException e) {
- fail(e.toString());
- }
+ assertEquals("getProvider() failed", p, s.getProvider());
+ assertEquals("getAlgorithm() failed", "CBA", s.getAlgorithm());
- if (!MySignature2.runEngineUpdate2) {
- fail("update() failed");
- }
-
- try {
- s.initSign(new MyPrivateKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
- try {
- s.verify(b, 0, 3);
- fail("No expected SignatureException");
- } catch (SignatureException e) {
- }
-
- try {
- s.initVerify(new MyPublicKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
-
- try {
- s.verify(b, 0, 5);
- fail("No expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- } catch (SignatureException e) {
- }
-
- try {
- s.verify(b, 0, 3);
- } catch (SignatureException e) {
- fail(e.toString());
- }
-
- if (!MySignature2.runEngineVerify) {
- fail("verify() failed");
- }
- }
+ s.initVerify(new MyCertificate());
+
+ try {
+ s.sign(b, 0, 5);
+ fail("No expected SignatureException 1");
+ } catch (SignatureException e) {
+ }
+
+ s.initSign(new MyPrivateKey());
+ s.sign(b, 0, 3);
+
+ assertTrue("sign() failed", MySignature2.runEngineSign);
+ s.update(b);
+ s.initSign(new MyPrivateKey());
+ s.update(b);
+ assertTrue("update() failed", MySignature2.runEngineUpdate2);
+
+ s.initSign(new MyPrivateKey());
+ try {
+ s.verify(b, 0, 3);
+ fail("No expected SignatureException");
+ } catch (SignatureException e) {
+ }
+ s.initVerify(new MyPublicKey());
+
+ try {
+ s.verify(b, 0, 5);
+ fail("No expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ } catch (SignatureException e) {
+ }
+
+ s.verify(b, 0, 3);
+ assertTrue("verify() failed", MySignature2.runEngineVerify);
+ }
private class MyProvider extends Provider {
MyProvider() {
Index: modules/security/src/test/impl/java.injected/java/security/Provider_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/Provider_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java.injected/java/security/Provider_ImplTest.java (revision 0)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package java.security;
+
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for Provider constructor and methods
+ *
+ */
+public class Provider_ImplTest extends TestCase {
+
+ Provider p;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ p = new MyProvider();
+ }
+
+ /*
+ * Class under test for String toString()
+ */
+ public final void testToString() {
+ assertEquals("Incorrect provider.toString()",
+ "MyProvider provider, Ver. 1.0 Provider for testing", p
+ .toString());
+ }
+
+ public final void testImplementsAlg() {
+ HashMap hm = new HashMap();
+ hm.put("KeySize", "1024");
+ hm.put("AAA", "BBB");
+ Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
+ "className", null, hm);
+ p.putService(s);
+ if (!p.implementsAlg("Type", "Algorithm", null, null) ||
+ !p.implementsAlg("MessageDigest", "SHA-1", null, null)) {
+ fail("Case 1. implementsAlg failed");
+ }
+ if (!p.implementsAlg("Type", "Algorithm", "KeySize", "512")) {
+ fail("Case 2. implementsAlg failed");
+ }
+ if (p.implementsAlg("Type", "Algorithm", "KeySize", "1025")) {
+ fail("Case 3. implementsAlg failed");
+ }
+ if (!p.implementsAlg("Type", "Algorithm", "AAA", "BBB")) {
+ fail("Case 3. implementsAlg failed");
+ }
+ }
+
+ public final void testSetProviderNumber() {
+ p.setProviderNumber(100);
+ assertEquals("Incorrect ProviderNumber", 100, p.getProviderNumber());
+ }
+
+ public final void testGetProviderNumber() {
+ assertEquals("Incorrect ProviderNumber", -1, p.getProviderNumber());
+
+ int i = Security.addProvider(p);
+ assertEquals("Incorrect ProviderNumber", i, p.getProviderNumber());
+ Security.removeProvider(p.getName()); // clean up
+ }
+
+ class MyProvider extends Provider {
+ MyProvider() {
+ super("MyProvider", 1.0, "Provider for testing");
+ put("MessageDigest.SHA-1", "SomeClassName");
+ put("MessageDigest.abc", "SomeClassName");
+ put("Alg.Alias.MessageDigest.SHA1", "SHA-1");
+ }
+
+ MyProvider(String name, double version, String info) {
+ super(name, version, info);
+ }
+ }
+}
Index: modules/security/src/test/impl/java.injected/java/security/AllPermissionCollection_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/AllPermissionCollection_ImplTest.java (revision 412994)
+++ modules/security/src/test/impl/java.injected/java/security/AllPermissionCollection_ImplTest.java (working copy)
@@ -32,12 +32,8 @@
*
*/
-public class AllPermissionCollectionTest extends TestCase {
+public class AllPermissionCollection_ImplTest extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(AllPermissionCollectionTest.class);
- }
-
/**
* Empty collection implies nothing, non-empty collection implies
* everything.
Index: modules/security/src/test/impl/java.injected/java/security/UnresolvedPermission_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/UnresolvedPermission_ImplTest.java (revision 412994)
+++ modules/security/src/test/impl/java.injected/java/security/UnresolvedPermission_ImplTest.java (working copy)
@@ -28,57 +28,9 @@
*
*/
-public class UnresolvedPermissionTest extends TestCase {
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(UnresolvedPermissionTest.class);
- }
-
- /**
- * Constructor for UnresolvedPermissionTest.
- * @param arg0
- */
- public UnresolvedPermissionTest(String arg0) {
- super(arg0);
- }
+public class UnresolvedPermission_ImplTest extends TestCase {
/**
- * Creates an Object with given name, type, action, certificaties.
- * 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("exception is not thrown on null type");
- }
- catch (Exception ok) {}
- /*try {
- new UnresolvedPermission("", name, action, null);
- fail("exception is not thrown on empty type");
- }
- catch (Exception ok) {}*/
- }
-
- /**
* 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.
@@ -126,29 +78,6 @@
assertTrue(up.equals(up2));
assertTrue(up.hashCode() == up2.hashCode());
}
-
- /**
- * 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")));
- }
-
- /**
- * newPermissionCollection() should return new BasicPermissionCollection on every invokation
- */
- 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);
- }
/**
* resolve the unresolved permission to the permission of specified class.
Index: modules/security/src/test/impl/java.injected/java/security/MessageDigestSpi_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/MessageDigestSpi_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java.injected/java/security/MessageDigestSpi_ImplTest.java (revision 0)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package java.security;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for MessageDigestSpi constructor and methods
+ *
+ */
+public class MessageDigestSpi_ImplTest extends TestCase {
+ /*
+ * Class under test for int engineDigest(byte[], int, int)
+ */
+ public void testEngineDigestbyteArrayintint() throws Exception {
+ MyMessageDigest md = new MyMessageDigest();
+ byte[] b = new byte[5];
+ try {
+ md.engineDigest(null, 1, 1);
+ fail("No expected NullPointerException");
+ } catch (NullPointerException e) {
+ }
+ try {
+ md.engineDigest(b, 3, 10);
+ fail("No expected DigestException");
+ } catch (DigestException e) {
+ }
+
+ assertEquals("incorrect result", 0, md.engineDigest(b, 1, 3));
+ }
+
+ private class MyMessageDigest extends MessageDigestSpi {
+
+ public void engineReset() {}
+
+ public byte[] engineDigest() {
+ return null;
+ }
+
+ public void engineUpdate(byte arg0) {}
+
+ public void engineUpdate(byte[] arg0, int arg1, int arg2) {}
+
+ public Object clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException();
+ }
+ }
+}
Index: modules/security/src/test/impl/java.injected/java/security/BasicPermissionCollection_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/BasicPermissionCollection_ImplTest.java (revision 412994)
+++ modules/security/src/test/impl/java.injected/java/security/BasicPermissionCollection_ImplTest.java (working copy)
@@ -39,12 +39,8 @@
*
*/
-public class BasicPermissionCollectionTest extends TestCase {
+public class BasicPermissionCollection_ImplTest extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(BasicPermissionCollectionTest.class);
- }
-
/**
* Can add only BasicPermissions of the same type as the first added. Cannot
* add if collection is read-only.
Index: modules/security/src/test/impl/java.injected/java/security/Security_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/Security_ImplTest.java (revision 0)
+++ modules/security/src/test/impl/java.injected/java/security/Security_ImplTest.java (revision 0)
@@ -0,0 +1,227 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package java.security;
+
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.harmony.security.tests.support.TestKeyPair;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for Security constructor and methods
+ *
+ */
+public class Security_ImplTest extends TestCase {
+
+ public final void testGetAlgorithmProperty() {
+ assertNull("Incorrect result on null parameter", Security
+ .getAlgorithmProperty(null, "MyService"));
+ assertNull("Incorrect result on null parameter", Security
+ .getAlgorithmProperty("MyAlgorithm", null));
+ assertNull("Incorrect result (provider not added)", Security
+ .getAlgorithmProperty("MyAlgorithm", "MyService"));
+
+ Provider p = new MyProvider();
+ Security.addProvider(p);
+ try {
+ assertEquals("Incorrect result (provider added)",
+ "SomeClassName", Security.getAlgorithmProperty("MyAlGoriThm", "MySerVicE"));
+ } finally { //clean up
+ Security.removeProvider(p.getName());
+ }
+ }
+
+ /*
+ * Class under test for Provider[] getProviders()
+ */
+ public final void testGetProviders() {
+ Provider[] providers;
+
+ providers = Security.getProviders();
+ for (int i = 0; i < providers.length; i++) {
+ // position is 1-based
+ assertEquals("Incorrect provider number", i + 1, providers[i]
+ .getProviderNumber());
+ }
+ }
+
+ /*
+ * Class under test for Provider[] getProviders(String)
+ */
+ public final void testGetProvidersString() {
+ Provider[] providers;
+ try {
+ Security.getProviders("");
+ fail("No expected InvalidParameterException");
+ } catch (InvalidParameterException e) {
+ }
+
+ try {
+ Security.getProviders((String) null);
+ fail("No expected NullPointerException");
+ } catch (NullPointerException e) {
+ }
+
+ try {
+ Security.getProviders("AAA.BBB CCC");
+ fail("AAA.BBB CCC: No expected InvalidParameterException");
+ } catch (InvalidParameterException e) {
+ }
+
+ Provider p = new MyProvider();
+
+ try {
+ Security.addProvider(p);
+ providers = Security.getProviders("MyService.MyAlgorithm");
+ assertTrue("failed for MyService.MyAlgorithm", providers != null);
+ assertEquals("failed for MyService.MyAlgorithm", 1,
+ providers.length);
+ assertEquals("failed for MyService.MyAlgorithm", p, providers[0]);
+ if (providers == null || providers.length != 1 || providers[0] != p) {
+ fail("fail for MyService.MyAlgorithm");
+ }
+
+ providers = Security
+ .getProviders("MyService.MyAlgorithm KeySize:512");
+ assertTrue("failed for MyService.MyAlgorithm KeySize:512",
+ providers != null);
+ assertEquals("failed for MyService.MyAlgorithm KeySize:512", 1,
+ providers.length);
+ assertEquals("failed for MyService.MyAlgorithm KeySize:512", p,
+ providers[0]);
+
+ providers = Security
+ .getProviders("MyService.MyAlgorithm KeySize:1025");
+ assertNull("failed for MyService.MyAlgorithm KeySize:1025",
+ providers);
+
+ } finally { //clean up
+ Security.removeProvider(p.getName());
+ }
+ }
+
+ /*
+ * Class under test for Provider[] getProviders(Map)
+ */
+ public final void testGetProvidersMap() {
+ Provider[] providers;
+ Map m = new Properties();
+ Security.getProviders(m);
+ assertNull("Not null result on empty map", Security.getProviders(m));
+
+ try {
+ Security.getProviders((Map)null);
+ fail("No expected NullPointerException");
+ } catch (NullPointerException e) {
+ }
+
+ m.clear();
+ m.put("AAA.BBB CCC", "");
+ m.put("AAA.BBB", "");
+ try {
+ Security.getProviders(m);
+ fail("attribute value is empty string: No expected InvalidParameterException");
+ } catch (InvalidParameterException e) {
+ }
+
+ m.clear();
+ m.put("AAA.BBB.CCC", "aaaa");
+ m.put("AAA.BBB", "");
+ try {
+ Security.getProviders(m);
+ fail("value associated with the key is not an empty string: No expected InvalidParameterException");
+ } catch (InvalidParameterException e) {
+ }
+
+ Provider p = new MyProvider();
+ try {
+ Security.addProvider(p);
+ m.clear();
+ m.put("MyService.MyAlgorithm", "");
+ m.put("MessageDigest.SHA-1", "");
+ providers = Security.getProviders(m);
+ assertNotNull("failed for MyService.MyAlgorithm", providers);
+ assertEquals("failed for MyService.MyAlgorithm", 1,
+ providers.length);
+ assertEquals("failed for MyService.MyAlgorithm", p, providers[0]);
+
+ m.clear();
+ m.put("MyService.MyAlgorithm KeySize", "512");
+ m.put("MessageDigest.SHA-1", "");
+ providers = Security.getProviders(m);
+ assertNotNull("failed for MyService.MyAlgorithm KeySize:512",
+ providers);
+ assertEquals("failed for MyService.MyAlgorithm KeySize:512", 1,
+ providers.length);
+ assertEquals("failed for MyService.MyAlgorithm KeySize:512", p,
+ providers[0]);
+
+ m.clear();
+ m.put("MyService.MyAlgorithm KeySize", "1025");
+ m.put("MessageDigest.SHA-1", "");
+ providers = Security.getProviders(m);
+ assertNull("failed for MyService.MyAlgorithm KeySize:1025",
+ providers);
+ } finally { //clean up
+ Security.removeProvider(p.getName());
+ }
+ }
+
+ public final void testGetAlgorithms() {
+ Set alg1;
+ Set alg2;
+
+ alg1 = Security.getAlgorithms("AAAAAAAAAAAAAAA");
+ assertTrue("failed for non-existent service", alg1 != null);
+ assertEquals("failed for non-existent service", 0, alg1.size());
+
+ alg1 = Security.getAlgorithms("SecureRandom");
+ alg2 = Security.getAlgorithms("seCuReranDom");
+ assertEquals("different size", alg1.size(), alg2.size());
+ assertTrue("different content", alg2.containsAll(alg1));
+
+ Provider p = new MyProvider();
+
+ try {
+ Security.addProvider(p);
+ alg1 = Security.getAlgorithms("MyService");
+ assertEquals("failed for MyService", 1, alg1.size());
+ assertTrue("failed for MyService", alg1.contains("MyAlgorithm"));
+ } finally { //clean up
+ Security.removeProvider(p.getName());
+ }
+ }
+
+ class MyProvider extends Provider {
+ MyProvider() {
+ super("MyProvider", 1.0, "Provider for testing");
+ put("MessageDigest.SHA-1", "SomeClassName");
+ put("MyService.MyAlgorithm", "SomeClassName");
+ put("MyService.MyAlgorithm KeySize", "1024");
+ }
+ }
+
+}
Index: modules/security/src/test/impl/java.injected/java/security/UnresolvedPermissionCollection_ImplTest.java
===================================================================
--- modules/security/src/test/impl/java.injected/java/security/UnresolvedPermissionCollection_ImplTest.java (revision 412994)
+++ modules/security/src/test/impl/java.injected/java/security/UnresolvedPermissionCollection_ImplTest.java (working copy)
@@ -31,7 +31,7 @@
*
*/
-public class UnresolvedPermissionCollectionTest extends TestCase {
+public class UnresolvedPermissionCollection_ImplTest extends TestCase {
public static void main(String[] args) {
junit.textui.TestRunner.run(UnresolvedPermissionCollectionTest.class);
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyRepTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyRepTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyRepTest.java (working copy)
@@ -19,13 +19,13 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
//import java.io.NotSerializableException;
//import java.io.ObjectStreamException;
//import java.util.Set;
//import java.util.Iterator;
-
+import java.security.*;
import junit.framework.TestCase;
/**
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSCallbackHandlerProtectionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSCallbackHandlerProtectionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSCallbackHandlerProtectionTest.java (working copy)
@@ -19,12 +19,14 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
+import java.security.KeyStore;
-
import javax.security.auth.callback.CallbackHandler;
+import org.apache.harmony.security.tests.support.tmpCallbackHandler;
+
import junit.framework.TestCase;
/**
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignedObjectTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignedObjectTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignedObjectTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.io.IOException;
import java.security.spec.InvalidKeySpecException;
import java.util.Properties;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/GuardedObjectTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/GuardedObjectTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/GuardedObjectTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import junit.framework.TestCase;
/**
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyManagementExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyManagementExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyManagementExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.KeyManagementException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreTest.java (revision 0)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreTest.java (revision 0)
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.Security;
+import java.security.cert.Certificate;
+
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport.MCertificate;
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport.MyPrivateKey;
+import org.apache.harmony.security.tests.support.MyLoadStoreParams;
+import org.apache.harmony.security.tests.support.SpiEngUtils;
+import org.apache.harmony.security.tests.support.SpiEngUtils.MyProvider;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for KeyStore constructor and methods
+ *
+ */
+
+public class KeyStoreTest extends TestCase {
+
+ private static final String KeyStoreProviderClass = "org.apache.harmony.security.tests.support.MyKeyStore";
+
+ private static final String defaultType = "KeyStore";
+
+ public static boolean KSSupported = false;
+
+ public static String defaultProviderName = null;
+
+ public static Provider defaultProvider = null;
+
+ private static String NotSupportMsg = "Default KeyStore type is not supported";
+
+ Provider mProv;
+
+ public KeyStore[] createKS() throws Exception {
+ assertTrue(NotSupportMsg, KSSupported);
+ KeyStore[] kpg = new KeyStore[3];
+
+ kpg[0] = KeyStore.getInstance(defaultType);
+ kpg[1] = KeyStore.getInstance(defaultType, defaultProvider);
+ kpg[2] = KeyStore.getInstance(defaultType, defaultProviderName);
+ return kpg;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mProv = (new SpiEngUtils()).new MyProvider("MyKSProvider",
+ "Testing provider", KeyStoreTestSupport.srvKeyStore.concat(".")
+ .concat(defaultType), KeyStoreProviderClass);
+ Security.insertProviderAt(mProv, 2);
+ defaultProvider = SpiEngUtils.isSupport(defaultType,
+ KeyStoreTestSupport.srvKeyStore);
+ KSSupported = (defaultProvider != null);
+ defaultProviderName = (KSSupported ? defaultProvider.getName() : null);
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ Security.removeProvider(mProv.getName());
+ }
+
+ /**
+ * Test for load(LoadStoreParameter param)
+ * store(LoadStoreParameter param)
+ * methods
+ * Assertions: throw IllegalArgumentException if param is null;
+ */
+ public void testLoadStore02() throws Exception {
+ assertTrue(NotSupportMsg, KSSupported);
+
+ KeyStore[] kss = createKS();
+ assertNotNull("KeyStore objects were not created", kss);
+
+ for (int i = 0; i < kss.length; i++) {
+ try {
+ kss[i].load(null);
+ fail("IOException or IllegalArgumentException should be thrown for null parameter");
+ } catch (IOException e) {
+ } catch (IllegalArgumentException e) {
+ }
+ kss[i].load(null, null);
+ try {
+ kss[i].store(null);
+ fail("IOException or IllegalArgumentException should be thrown for nill parameter");
+ } catch (IOException e) {
+ } catch (IllegalArgumentException e) {
+ }
+ }
+ KeyStore.LoadStoreParameter lParam = new MyLoadStoreParams(
+ new KeyStore.PasswordProtection(new char[0]));
+ for (int i = 0; i < kss.length; i++) {
+ kss[i].load(lParam);
+ assertEquals("Incorrect result", kss[i].size(), 0);
+ kss[i].store(lParam);
+ }
+ }
+
+
+ /**
+ * Test for setKeyEntry(String alias, bute[] key, Certificate[] chain)
+ * method
+ * Assertion: stores KeyEntry.
+ */
+ public void testSetKeyEntry() throws Exception {
+ assertTrue(NotSupportMsg, KSSupported);
+
+ KeyStore[] kss = createKS();
+ assertNotNull("KeyStore objects were not created", kss);
+ byte[] kk = { (byte) 1, (byte) 2, (byte) 127, (byte) 77 };
+ String alias = "keyEntry";
+ char[] pwd = new char[0];
+ byte[] res;
+ Certificate certs[] = {
+ new KeyStoreTestSupport.MCertificate(alias, kk),
+ new KeyStoreTestSupport.MCertificate(alias, kk) };
+ for (int i = 0; i < kss.length; i++) {
+ kss[i].load(null, null);
+ try {
+ kss[i].setKeyEntry("proba", null, null);
+ fail("KeyStoreException must be thrown");
+ } catch (KeyStoreException e) {
+ }
+ kss[i].setKeyEntry(alias, kk, certs);
+ res = kss[i].getKey(alias, pwd).getEncoded();
+ assertEquals(kk.length, res.length);
+ for (int j = 0; j < res.length; j++) {
+ assertEquals(res[j], kk[j]);
+ }
+ assertEquals(kss[i].getCertificateChain(alias).length, certs.length);
+ kss[i].setKeyEntry(alias, kk, null);
+ res = kss[i].getKey(alias, pwd).getEncoded();
+ assertEquals(kk.length, res.length);
+ for (int j = 0; j < res.length; j++) {
+ assertEquals(res[j], kk[j]);
+ }
+ assertNull(kss[i].getCertificateChain(alias));
+ }
+ }
+
+ /**
+ * Test for getDefaultType() method Assertion: returns
+ * default security key store type or "jks" string
+ */
+ public void testKeyStore01() {
+ String propName = "keystore.type";
+ String defKSType = Security.getProperty(propName);
+ String dType = KeyStore.getDefaultType();
+ String resType = defKSType;
+ if (resType == null) {
+ resType = defaultType;
+ }
+ assertNotNull("Default type have not be null", dType);
+ assertEquals("Incorrect default type", dType, resType);
+
+ if (defKSType == null) {
+ Security.setProperty(propName, defaultType);
+ dType = KeyStore.getDefaultType();
+ resType = Security.getProperty(propName);
+ assertNotNull("Incorrect default type", resType);
+ assertNotNull("Default type have not be null", dType);
+ assertEquals("Incorrect default type", dType, resType);
+ }
+ }
+
+ /**
+ * Test for getInstance(String type) method
+ * Assertion:
+ * throws NullPointerException when type is null
+ * throws KeyStoreException when type is not available
+ *
+ */
+ public void testKeyStore02() throws KeyStoreException {
+ String[] invalidValues = SpiEngUtils.invalidValues;
+ try {
+ KeyStore.getInstance(null);
+ fail("NullPointerException must be thrown when type is null");
+ } catch (NullPointerException e) {
+ }
+ for (int i = 0; i < invalidValues.length; i++) {
+ try {
+ KeyStore.getInstance(invalidValues[i]);
+ fail("KeyStoreException must be thrown (type: ".concat(
+ invalidValues[i]).concat(" )"));
+ } catch (KeyStoreException e) {
+ }
+ }
+ }
+}
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import junit.framework.TestCase;
/**
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.ProviderException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java (working copy)
@@ -19,8 +19,9 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import junit.framework.TestCase;
import java.security.spec.AlgorithmParameterSpec;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestInputStreamTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestInputStreamTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestInputStreamTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSTrustedCertificateEntryTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSTrustedCertificateEntryTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSTrustedCertificateEntryTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.cert.Certificate;
import org.apache.harmony.security.tests.support.cert.MyCertificate;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterExceptionTest.java (working copy)
@@ -19,7 +19,7 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
import java.security.InvalidAlgorithmParameterException;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.URLClassLoader;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidKeyExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidKeyExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidKeyExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.InvalidKeyException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator2Test.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator2Test.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator2Test.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import junit.framework.TestCase;
/**
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSignerTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSignerTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSignerTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.cert.CertPath;
import java.util.Date;
@@ -49,15 +49,6 @@
private Timestamp ts = new Timestamp(now, cpath);
/**
- * Tests CodeSigner.hashCode()
- */
- public void testHashCode() {
- assertTrue(new CodeSigner(cpath, ts).hashCode() == (cpath.hashCode() ^ ts
- .hashCode()));
- assertTrue(new CodeSigner(cpath, null).hashCode() == cpath.hashCode());
- }
-
- /**
* must throw NPE if signerCertPath is null
*/
public void testCodeSigner_00() {
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PrivateKeyTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PrivateKeyTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PrivateKeyTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.PrivateKey;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.KeyStoreException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/GeneralSecurityExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/GeneralSecurityExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/GeneralSecurityExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.GeneralSecurityException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.UnrecoverableKeyException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.NoSuchAlgorithmException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignerTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignerTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignerTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import org.apache.harmony.security.tests.support.PrivateKeyStub;
import org.apache.harmony.security.tests.support.PublicKeyStub;
import org.apache.harmony.security.tests.support.SignerStub;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/NoSuchProviderExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/NoSuchProviderExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/NoSuchProviderExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.NoSuchProviderException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderTest.java (working copy)
@@ -1,535 +1,332 @@
-/*
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
-* @author Boris V. Kuznetsov
-* @version $Revision$
-*/
-
-package java.security;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.security.tests.support.SpiEngUtils;
-import org.apache.harmony.security.tests.support.TestUtils;
-
-
-/**
- * Tests for Provider constructor and methods
- *
- */
-public class ProviderTest extends TestCase {
-
- Provider p;
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- p = new MyProvider();
- }
-
- /*
- * Class under test for void Provider()
- */
- public final void testProvider() {
- if (!p.getProperty("Provider.id name").equals(String.valueOf(p.getName()))) {
- fail("Incorrect \"Provider.id name\" value");
- }
- if (!p.getProperty("Provider.id version").equals(String.valueOf(p.getVersion()))) {
- fail("Incorrect \"Provider.id version\" value");
- }
- if (!p.getProperty("Provider.id info").equals(String.valueOf(p.getInfo()))) {
- fail("Incorrect \"Provider.id info\" value");
- }
- if (!p.getProperty("Provider.id className").equals(p.getClass().getName())) {
- fail("Incorrect \"Provider.id className\" value");
- }
- }
-
- public final void testClear() {
- p.clear();
- if (p.getProperty("MessageDigest.SHA-1") != null) {
- fail("Provider contains properties");
- }
- }
-
- /*
- * Class under test for void Provider(String, double, String)
- */
- public final void testProviderStringdoubleString() {
- Provider p = new MyProvider("Provider name", 123.456, "Provider info");
- if (!p.getName().equals("Provider name") ||
- p.getVersion() != 123.456 ||
- !p.getInfo().equals("Provider info")) {
- fail("Incorrect values");
- }
- }
-
- public final void testGetName() {
- if (!p.getName().equals("MyProvider")) {
- fail("Incorrect provider name");
- }
- }
-
- public final void testGetVersion() {
- if (p.getVersion() != 1.0) {
- fail("Incorrect provider version");
- }
- }
-
- public final void testGetInfo() {
- if (!p.getInfo().equals("Provider for testing")) {
- fail("Incorrect provider info");
- }
- }
-
- /*
- * Class under test for String toString()
- */
- public final void testToString() {
- if (!"MyProvider provider, Ver. 1.0 Provider for testing".equals(p.toString())) {
- fail("Incorrect provider.toString()");
- }
- }
-
- /*
- * Class under test for void load(InputStream)
- */
- public final void testLoadInputStream() {
- FileInputStream fis = null;
- String fileName = SpiEngUtils.getFileName(TestUtils.TEST_ROOT,
- "java/security/Provider.prop.dat");
- try {
- fis = new FileInputStream(fileName);
- } catch (FileNotFoundException e) {
- fail(e.toString());
- }
- try {
- p.load(fis);
- } catch (IOException e) {
- fail(e.toString());
- }
-
- if (!"value 1".equals(p.getProperty("Property 1").trim()) ||
- !"className".equals(p.getProperty("serviceName.algName").trim()) ||
- !"attrValue".equals(p.getProperty("serviceName.algName attrName").trim()) ||
- !"stanbdardName".equals(p.getProperty("Alg.Alias.engineClassName.aliasName").trim()) ||
- !String.valueOf(p.getName()).equals(p.getProperty("Provider.id name").trim()) ||
- !String.valueOf(p.getVersion()).equals(p.getProperty("Provider.id version").trim()) ||
- !String.valueOf(p.getInfo()).equals(p.getProperty("Provider.id info").trim()) ||
- !p.getClass().getName().equals(p.getProperty("Provider.id className").trim()) ||
- !"SomeClassName".equals(p.getProperty("MessageDigest.SHA-1").trim()) ) {
- fail("Incorrect property value");
- }
- }
-
- /*
- * Class under test for void putAll(Map)
- */
- public final void testPutAllMap() {
- HashMap hm = new HashMap();
- hm.put("MessageDigest.SHA-1", "aaa.bbb.ccc.ddd");
- hm.put("Property 1", "value 1");
- hm.put("serviceName.algName attrName", "attrValue");
- hm.put("Alg.Alias.engineClassName.aliasName", "stanbdardName");
- p.putAll(hm);
- if (!"value 1".equals(p.getProperty("Property 1").trim()) ||
- !"attrValue".equals(p.getProperty("serviceName.algName attrName").trim()) ||
- !"stanbdardName".equals(p.getProperty("Alg.Alias.engineClassName.aliasName").trim()) ||
- !"aaa.bbb.ccc.ddd".equals(p.getProperty("MessageDigest.SHA-1").trim()) ) {
- fail("Incorrect property value");
- }
- }
-
- /*
- * Class under test for Set entrySet()
- */
- public final void testEntrySet() {
- p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd");
-
- Set s = p.entrySet();
- try {
- s.clear();
- } catch (UnsupportedOperationException e) {
- }
- Set s1 = p.entrySet();
- if ((s == s1) || s1.isEmpty() ) {
- fail("Must return unmodifiable set");
- }
- if (s1.size() != 8) {
- fail("Incorrect set size");
- }
- for (Iterator it = s1.iterator(); it.hasNext();) {
- Entry e = (Entry)it.next();
- String key = (String)e.getKey();
- String val = (String)e.getValue();
- if (key.equals("MessageDigest.SHA-1") && val.equals("SomeClassName")) {
- continue;
- }
- if (key.equals("Alg.Alias.MessageDigest.SHA1") && val.equals("SHA-1")) {
- continue;
- }
- if (key.equals("MessageDigest.abc") && val.equals("SomeClassName")) {
- continue;
- }
- if (key.equals("Provider.id className") && val.equals(p.getClass().getName())) {
- continue;
- }
- if (key.equals("Provider.id name") && val.equals("MyProvider")) {
- continue;
- }
- if (key.equals("MessageDigest.SHA-256") && val.equals("aaa.bbb.ccc.ddd")) {
- continue;
- }
- if (key.equals("Provider.id version") && val.equals("1.0")) {
- continue;
- }
- if (key.equals("Provider.id info") && val.equals("Provider for testing")) {
- continue;
- }
- fail("Incorrect set");
- }
- }
-
- /*
- * Class under test for Set keySet()
- */
- public final void testKeySet() {
- p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd");
-
- Set s = p.keySet();
- try {
- s.clear();
- } catch (UnsupportedOperationException e) {
- }
- Set s1 = p.keySet();
- if ((s == s1) || s1.isEmpty() ) {
- fail("Must return unmodifiable set");
- }
- if (s1.size() != 8) {
- fail("Incorrect set size");
- }
- if (!s1.contains("MessageDigest.SHA-256") ||
- !s1.contains("MessageDigest.SHA-1") ||
- !s1.contains("Alg.Alias.MessageDigest.SHA1") ||
- !s1.contains("MessageDigest.abc") ||
- !s1.contains("Provider.id info") ||
- !s1.contains("Provider.id className") ||
- !s1.contains("Provider.id version") ||
- !s1.contains("Provider.id name")) {
- fail("Incorrect set");
- }
- }
-
- /*
- * Class under test for Collection values()
- */
- public final void testValues() {
- p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd");
-
- Collection c = p.values();
- try {
- c.clear();
- } catch (UnsupportedOperationException e) {
- }
- Collection c1 = p.values();
- if ((c == c1) || c1.isEmpty() ) {
- fail("Must return unmodifiable set");
- }
- if (c1.size() != 8) {
- fail("Incorrect set size " + c1.size());
- }
- if (!c1.contains("MyProvider") ||
- !c1.contains("aaa.bbb.ccc.ddd") ||
- !c1.contains("Provider for testing") ||
- !c1.contains("1.0") ||
- !c1.contains("SomeClassName") ||
- !c1.contains("SHA-1") ||
- !c1.contains(p.getClass().getName())) {
- fail("Incorrect set");
- }
- }
-
- /*
- * Class under test for Object put(Object, Object)
- */
- public final void testPutObjectObject() {
- p.put("MessageDigest.SHA-1", "aaa.bbb.ccc.ddd");
- p.put("Type.Algorithm", "className");
- if (!"aaa.bbb.ccc.ddd".equals(p.getProperty("MessageDigest.SHA-1").trim()) ) {
- fail("Incorrect property value");
- }
-
- Set services = p.getServices();
- if (services.size() != 3) {
- fail("incorrect size");
- }
- for (Iterator it = services.iterator(); it.hasNext();) {
- Provider.Service s = (Provider.Service)it.next();
- if ("Type".equals(s.getType()) &&
- "Algorithm".equals(s.getAlgorithm()) &&
- "className".equals(s.getClassName())) {
- continue;
- }
- if ("MessageDigest".equals(s.getType()) &&
- "SHA-1".equals(s.getAlgorithm()) &&
- "aaa.bbb.ccc.ddd".equals(s.getClassName())) {
- continue;
- }
- if ("MessageDigest".equals(s.getType()) &&
- "abc".equals(s.getAlgorithm()) &&
- "SomeClassName".equals(s.getClassName())) {
- continue;
- }
- fail("Incorrect service");
- }
- }
-
- /*
- * Class under test for Object remove(Object)
- */
- public final void testRemoveObject() {
- Object o = p.remove("MessageDigest.SHA-1");
- if (!"SomeClassName".equals(o)) {
- fail("Incorrect return value");
- }
- if (p.getProperty("MessageDigest.SHA-1") != null) {
- fail("Provider contains properties");
- }
- if (p.getServices().size() != 1){
- fail("Service not removed");
- }
- }
-
- public final void testImplementsAlg() {
- HashMap hm = new HashMap();
- hm.put("KeySize", "1024");
- hm.put("AAA", "BBB");
- Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
- "className", null, hm);
- p.putService(s);
- if (!p.implementsAlg("Type", "Algorithm", null, null) ||
- !p.implementsAlg("MessageDigest", "SHA-1", null, null)) {
- fail("Case 1. implementsAlg failed");
- }
- if (!p.implementsAlg("Type", "Algorithm", "KeySize", "512")) {
- fail("Case 2. implementsAlg failed");
- }
- if (p.implementsAlg("Type", "Algorithm", "KeySize", "1025")) {
- fail("Case 3. implementsAlg failed");
- }
- if (!p.implementsAlg("Type", "Algorithm", "AAA", "BBB")) {
- fail("Case 3. implementsAlg failed");
- }
- }
-
- public final void testSetProviderNumber() {
- p.setProviderNumber(100);
- if (p.getProviderNumber() != 100) {
- fail("Incorrect ProviderNumber");
- }
- }
-
- public final void testGetProviderNumber() {
- if (p.getProviderNumber() != -1) {
- fail("Case 1. Incorrect ProviderNumber");
- }
-
- int i = Security.addProvider(p);
- if (p.getProviderNumber() != i) {
- fail("Case 2. Incorrect ProviderNumber");
- }
- Security.removeProvider(p.getName()); // clean up
- }
-
- public final void testGetService() {
- try {
- p.getService(null, "algorithm");
- fail("No expected NullPointerException");
- } catch (NullPointerException e) {
- }
- try {
- p.getService("type", null);
- fail("No expected NullPointerException");
- } catch (NullPointerException e) {
- }
-
- Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
- "className", null, null);
- p.putService(s);
-
- if (p.getService("Type", "AlgoRithM") != s) {
- fail("Case 1. getService() failed");
- }
-
- Provider.Service s1 = p.getService("MessageDigest", "AbC");
- if (s1 == null) {
- fail("Case 2. getService() failed");
- }
-
- s = new Provider.Service(p, "MessageDigest", "SHA-1",
- "className", null, null);
- p.putService(s);
- if (s1 == p.getService("MessageDigest", "SHA-1")) {
- fail("Case 3. getService() failed");
- }
-
- if (p.getService("MessageDigest", "SHA1") == null) {
- fail("Case 4. getService() failed");
- }
- }
-
- public final void testGetServices() {
- Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
- "className", null, null);
-
- // incomplete services should be removed
- p.put("serv.alg", "aaaaaaaaaaaaa");
- p.put("serv.alg KeySize", "11111");
- p.put("serv1.alg1 KeySize", "222222");
- p.remove("serv.alg");
-
- p.putService(s);
- Set services = p.getServices();
- if (services.size() != 3) {
- fail("incorrect size");
- }
- for (Iterator it = services.iterator(); it.hasNext();) {
- s = (Provider.Service)it.next();
- if ("Type".equals(s.getType()) &&
- "Algorithm".equals(s.getAlgorithm()) &&
- "className".equals(s.getClassName())) {
- continue;
- }
- if ("MessageDigest".equals(s.getType()) &&
- "SHA-1".equals(s.getAlgorithm()) &&
- "SomeClassName".equals(s.getClassName())) {
- continue;
- }
- if ("MessageDigest".equals(s.getType()) &&
- "abc".equals(s.getAlgorithm()) &&
- "SomeClassName".equals(s.getClassName())) {
- continue;
- }
- fail("Incorrect service");
- }
- }
-
- public final void testPutService() {
- HashMap hm = new HashMap();
- hm.put("KeySize", "1024");
- hm.put("AAA", "BBB");
- Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
- "className", null, hm);
- p.putService(s);
- if (s != p.getService("Type", "Algorithm")){
- fail("putService failed");
- }
- if (!"className".equals(p.getProperty("Type.Algorithm"))) {
- fail("incorrect className");
- }
- if (!"1024".equals(p.getProperty("Type.Algorithm KeySize"))) {
- fail("incorrect attribute");
- }
- }
-
- public final void testRemoveService() {
- Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
- "className", null, null);
- p.putService(s);
- p.removeService(s);
- Set services = p.getServices();
- if (services.size() != 2) {
- fail("incorrect size");
- }
-
- for (Iterator it = services.iterator(); it.hasNext();) {
- s = (Provider.Service)it.next();
- if ("MessageDigest".equals(s.getType()) &&
- "SHA-1".equals(s.getAlgorithm()) &&
- "SomeClassName".equals(s.getClassName())) {
- continue;
- }
- if ("MessageDigest".equals(s.getType()) &&
- "abc".equals(s.getAlgorithm()) &&
- "SomeClassName".equals(s.getClassName())) {
- continue;
- }
- fail("Incorrect service");
- }
-
- if (p.getProperty("Type.Algorithm") != null) {
- fail("incorrect property");
- }
- }
-
- public final void testService1() {
- p.put("MessageDigest.SHA-1", "AnotherClassName");
- Provider.Service s = p.getService("MessageDigest", "SHA-1");
- if (!"AnotherClassName".equals(s.getClassName())) {
- fail("Incorrect class name "+ s.getClassName());
- }
- }
-
- /*
- public final void testService2() {
- Provider[] pp = Security.getProviders("MessageDigest.SHA-1");
- if (pp == null) {
- return;
- }
- Provider p2 = pp[0];
- String old = p2.getProperty("MessageDigest.SHA-1");
- try {
- p2.put("MessageDigest.SHA-1", "AnotherClassName");
- Provider.Service s = p2.getService("MessageDigest", "SHA-1");
- if (!"AnotherClassName".equals(s.getClassName())) {
- fail("Incorrect class name "+ s.getClassName());
- }
- try {
- s.newInstance(null);
- fail("No expected NoSuchAlgorithmException");
- } catch (NoSuchAlgorithmException e) {
- }
- } finally {
- p2.put("MessageDigest.SHA-1", old);
- }
- }
-*/
-
- class MyProvider extends Provider {
- MyProvider() {
- super("MyProvider", 1.0, "Provider for testing");
- put("MessageDigest.SHA-1", "SomeClassName");
- put("MessageDigest.abc", "SomeClassName");
- put("Alg.Alias.MessageDigest.SHA1", "SHA-1");
- }
-
- MyProvider(String name, double version, String info) {
- super(name, version, info);
- }
- }
-}
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.security.*;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.tests.support.SpiEngUtils;
+import org.apache.harmony.security.tests.support.TestUtils;
+
+
+/**
+ * Tests for Provider constructor and methods
+ *
+ */
+public class ProviderTest extends TestCase {
+
+ Provider p;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ p = new MyProvider();
+ }
+
+ /*
+ * Class under test for void Provider()
+ */
+ public final void testProvider() {
+ if (!p.getProperty("Provider.id name").equals(String.valueOf(p.getName()))) {
+ fail("Incorrect \"Provider.id name\" value");
+ }
+ if (!p.getProperty("Provider.id version").equals(String.valueOf(p.getVersion()))) {
+ fail("Incorrect \"Provider.id version\" value");
+ }
+ if (!p.getProperty("Provider.id info").equals(String.valueOf(p.getInfo()))) {
+ fail("Incorrect \"Provider.id info\" value");
+ }
+ if (!p.getProperty("Provider.id className").equals(p.getClass().getName())) {
+ fail("Incorrect \"Provider.id className\" value");
+ }
+ }
+
+ public final void testClear() {
+ p.clear();
+ if (p.getProperty("MessageDigest.SHA-1") != null) {
+ fail("Provider contains properties");
+ }
+ }
+
+ /*
+ * Class under test for void Provider(String, double, String)
+ */
+ public final void testProviderStringdoubleString() {
+ Provider p = new MyProvider("Provider name", 123.456, "Provider info");
+ if (!p.getName().equals("Provider name") ||
+ p.getVersion() != 123.456 ||
+ !p.getInfo().equals("Provider info")) {
+ fail("Incorrect values");
+ }
+ }
+
+ public final void testGetName() {
+ if (!p.getName().equals("MyProvider")) {
+ fail("Incorrect provider name");
+ }
+ }
+
+ public final void testGetVersion() {
+ if (p.getVersion() != 1.0) {
+ fail("Incorrect provider version");
+ }
+ }
+
+ public final void testGetInfo() {
+ if (!p.getInfo().equals("Provider for testing")) {
+ fail("Incorrect provider info");
+ }
+ }
+
+ /*
+ * Class under test for void putAll(Map)
+ */
+ public final void testPutAllMap() {
+ HashMap hm = new HashMap();
+ hm.put("MessageDigest.SHA-1", "aaa.bbb.ccc.ddd");
+ hm.put("Property 1", "value 1");
+ hm.put("serviceName.algName attrName", "attrValue");
+ hm.put("Alg.Alias.engineClassName.aliasName", "stanbdardName");
+ p.putAll(hm);
+ if (!"value 1".equals(p.getProperty("Property 1").trim()) ||
+ !"attrValue".equals(p.getProperty("serviceName.algName attrName").trim()) ||
+ !"stanbdardName".equals(p.getProperty("Alg.Alias.engineClassName.aliasName").trim()) ||
+ !"aaa.bbb.ccc.ddd".equals(p.getProperty("MessageDigest.SHA-1").trim()) ) {
+ fail("Incorrect property value");
+ }
+ }
+
+ /*
+ * Class under test for Set entrySet()
+ */
+ public final void testEntrySet() {
+ p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd");
+
+ Set s = p.entrySet();
+ try {
+ s.clear();
+ fail("Must return unmodifiable set");
+ } catch (UnsupportedOperationException e) {
+ }
+
+ assertEquals("Incorrect set size", 8, s.size());
+
+ for (Iterator it = s.iterator(); it.hasNext();) {
+ Entry e = (Entry)it.next();
+ String key = (String)e.getKey();
+ String val = (String)e.getValue();
+ if (key.equals("MessageDigest.SHA-1") && val.equals("SomeClassName")) {
+ continue;
+ }
+ if (key.equals("Alg.Alias.MessageDigest.SHA1") && val.equals("SHA-1")) {
+ continue;
+ }
+ if (key.equals("MessageDigest.abc") && val.equals("SomeClassName")) {
+ continue;
+ }
+ if (key.equals("Provider.id className") && val.equals(p.getClass().getName())) {
+ continue;
+ }
+ if (key.equals("Provider.id name") && val.equals("MyProvider")) {
+ continue;
+ }
+ if (key.equals("MessageDigest.SHA-256") && val.equals("aaa.bbb.ccc.ddd")) {
+ continue;
+ }
+ if (key.equals("Provider.id version") && val.equals("1.0")) {
+ continue;
+ }
+ if (key.equals("Provider.id info") && val.equals("Provider for testing")) {
+ continue;
+ }
+ fail("Incorrect set");
+ }
+ }
+
+ /*
+ * Class under test for Set keySet()
+ */
+ public final void testKeySet() {
+ p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd");
+
+ Set s = p.keySet();
+ try {
+ s.clear();
+ } catch (UnsupportedOperationException e) {
+ }
+ Set s1 = p.keySet();
+ if ((s == s1) || s1.isEmpty() ) {
+ fail("Must return unmodifiable set");
+ }
+ if (s1.size() != 8) {
+ fail("Incorrect set size");
+ }
+ if (!s1.contains("MessageDigest.SHA-256") ||
+ !s1.contains("MessageDigest.SHA-1") ||
+ !s1.contains("Alg.Alias.MessageDigest.SHA1") ||
+ !s1.contains("MessageDigest.abc") ||
+ !s1.contains("Provider.id info") ||
+ !s1.contains("Provider.id className") ||
+ !s1.contains("Provider.id version") ||
+ !s1.contains("Provider.id name")) {
+ fail("Incorrect set");
+ }
+ }
+
+ /*
+ * Class under test for Collection values()
+ */
+ public final void testValues() {
+ p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd");
+
+ Collection c = p.values();
+ try {
+ c.clear();
+ } catch (UnsupportedOperationException e) {
+ }
+ Collection c1 = p.values();
+ if ((c == c1) || c1.isEmpty() ) {
+ fail("Must return unmodifiable set");
+ }
+ if (c1.size() != 8) {
+ fail("Incorrect set size " + c1.size());
+ }
+ if (!c1.contains("MyProvider") ||
+ !c1.contains("aaa.bbb.ccc.ddd") ||
+ !c1.contains("Provider for testing") ||
+ !c1.contains("1.0") ||
+ !c1.contains("SomeClassName") ||
+ !c1.contains("SHA-1") ||
+ !c1.contains(p.getClass().getName())) {
+ fail("Incorrect set");
+ }
+ }
+
+ /*
+ * Class under test for Object put(Object, Object)
+ */
+ public final void testPutObjectObject() {
+ p.put("MessageDigest.SHA-1", "aaa.bbb.ccc.ddd");
+ p.put("Type.Algorithm", "className");
+ if (!"aaa.bbb.ccc.ddd".equals(p.getProperty("MessageDigest.SHA-1").trim()) ) {
+ fail("Incorrect property value");
+ }
+
+ Set services = p.getServices();
+ if (services.size() != 3) {
+ fail("incorrect size");
+ }
+ for (Iterator it = services.iterator(); it.hasNext();) {
+ Provider.Service s = (Provider.Service)it.next();
+ if ("Type".equals(s.getType()) &&
+ "Algorithm".equals(s.getAlgorithm()) &&
+ "className".equals(s.getClassName())) {
+ continue;
+ }
+ if ("MessageDigest".equals(s.getType()) &&
+ "SHA-1".equals(s.getAlgorithm()) &&
+ "aaa.bbb.ccc.ddd".equals(s.getClassName())) {
+ continue;
+ }
+ if ("MessageDigest".equals(s.getType()) &&
+ "abc".equals(s.getAlgorithm()) &&
+ "SomeClassName".equals(s.getClassName())) {
+ continue;
+ }
+ fail("Incorrect service");
+ }
+ }
+
+ /*
+ * Class under test for Object remove(Object)
+ */
+ public final void testRemoveObject() {
+ Object o = p.remove("MessageDigest.SHA-1");
+ if (!"SomeClassName".equals(o)) {
+ fail("Incorrect return value");
+ }
+ if (p.getProperty("MessageDigest.SHA-1") != null) {
+ fail("Provider contains properties");
+ }
+ if (p.getServices().size() != 1){
+ fail("Service not removed");
+ }
+ }
+
+ public final void testService1() {
+ p.put("MessageDigest.SHA-1", "AnotherClassName");
+ Provider.Service s = p.getService("MessageDigest", "SHA-1");
+ if (!"AnotherClassName".equals(s.getClassName())) {
+ fail("Incorrect class name "+ s.getClassName());
+ }
+ }
+
+ /*
+ public final void testService2() {
+ Provider[] pp = Security.getProviders("MessageDigest.SHA-1");
+ if (pp == null) {
+ return;
+ }
+ Provider p2 = pp[0];
+ String old = p2.getProperty("MessageDigest.SHA-1");
+ try {
+ p2.put("MessageDigest.SHA-1", "AnotherClassName");
+ Provider.Service s = p2.getService("MessageDigest", "SHA-1");
+ if (!"AnotherClassName".equals(s.getClassName())) {
+ fail("Incorrect class name "+ s.getClassName());
+ }
+ try {
+ s.newInstance(null);
+ fail("No expected NoSuchAlgorithmException");
+ } catch (NoSuchAlgorithmException e) {
+ }
+ } finally {
+ p2.put("MessageDigest.SHA-1", old);
+ }
+ }
+*/
+
+ class MyProvider extends Provider {
+ MyProvider() {
+ super("MyProvider", 1.0, "Provider for testing");
+ put("MessageDigest.SHA-1", "SomeClassName");
+ put("MessageDigest.abc", "SomeClassName");
+ put("Alg.Alias.MessageDigest.SHA1", "SHA-1");
+ }
+
+ MyProvider(String name, double version, String info) {
+ super(name, version, info);
+ }
+ }
+}
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator1Test.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator1Test.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator1Test.java (working copy)
@@ -19,9 +19,9 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
-
+import java.security.*;
import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnrecoverableEntryExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnrecoverableEntryExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnrecoverableEntryExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import junit.framework.TestCase;
/**
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator3Test.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator3Test.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator3Test.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import org.apache.harmony.security.tests.support.SpiEngUtils;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
@@ -107,54 +107,6 @@
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));
- assertFalse(policy.implies(null, null));
-
- ProtectionDomain pd = new ProtectionDomain(null, policy.pc);
- policy.pc = null;
- assertTrue(policy.implies(pd, sp));
- assertFalse(policy.implies(pd, new AllPermission()));
- }
/**
* Tests that getPermissions() does proper permission evaluation.
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/TimestampTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/TimestampTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/TimestampTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.cert.CertPath;
import java.util.Date;
@@ -46,11 +46,6 @@
private CertPath cpath = new MyCertPath(encoding);
- public void testHashCode() {
- assertTrue(new Timestamp(now, cpath).hashCode() == (now.hashCode() ^ cpath
- .hashCode()));
- }
-
public void testTimestamp() {
try {
new Timestamp(null, cpath);
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSPrivateKeyEntryTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSPrivateKeyEntryTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSPrivateKeyEntryTest.java (working copy)
@@ -19,9 +19,9 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
-
+import java.security.*;
import java.security.cert.Certificate;
import org.apache.harmony.security.tests.support.cert.MyCertificate;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.util.*;
import junit.framework.TestCase;
@@ -66,21 +66,7 @@
return false;
}
}
-
- /** Test toString() transformation with different elements. */
- public void testToString()
- {
- // no elements
- PermissionCollection pc = new RealPermissionCollection(null);
- String superString = pc.getClass().getName() + "@" + Integer.toHexString(pc.hashCode());
- assertEquals("no elements", superString + " (\n)", pc.toString());
- // several elements
- pc = new RealPermissionCollection(Arrays.asList(new Object[]{"aaa", "bbb", "ccc"}));
- superString = pc.getClass().getName() + "@" + Integer.toHexString(pc.hashCode());
- assertEquals("several elements", superString + " (\n aaa\n bbb\n ccc\n)", pc.toString());
- }
-
/** Test read-only flag. Should be false by default and can be set once forever. */
public void testReadOnly()
{
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.spec.InvalidKeySpecException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import org.apache.harmony.security.tests.support.MyMessageDigest1;
import junit.framework.TestCase;
@@ -88,24 +88,6 @@
}
/*
- * Class under test for int digest(byte[], int, int)
- */
- public void testDigestbyteArrayintint() {
- MyMessageDigest1 md = new MyMessageDigest1("ABC");
- byte[] b = {1, 2, 3, 4, 5};
- try {
- if (md.digest(b, 2, 3) != 0) {
- fail("incorrect result");
- }
- } catch (java.security.DigestException e) {
- fail(e.toString());
- }
- if (!md.runEngineDigest) {
- fail("digest failed");
- }
- }
-
- /*
* Class under test for byte[] digest(byte[])
*/
public void testDigestbyteArray() {
@@ -119,16 +101,6 @@
}
}
- /*
- * Class under test for String toString()
- */
- public void testToString() {
- MyMessageDigest1 md = new MyMessageDigest1("ABC");
- if (!"MESSAGE DIGEST ABC".equals(md.toString())) {
- fail("incorrect result");
- }
- }
-
public void testIsEqual() {
byte[] b1 = {1, 2, 3, 4};
byte[] b2 = {1, 2, 3, 4, 5};
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidParameterExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidParameterExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/InvalidParameterExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.InvalidParameterException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.KeyException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSPasswordProtectionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSPasswordProtectionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSPasswordProtectionTest.java (working copy)
@@ -19,9 +19,9 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
-
+import java.security.*;
import javax.security.auth.DestroyFailedException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java (working copy)
@@ -19,8 +19,10 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
+
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -57,26 +59,7 @@
}
}
-
- public final void testGetAlgorithmProperty() {
- if (Security.getAlgorithmProperty(null, "MyService") != null ||
- Security.getAlgorithmProperty("MyAlgorithm", null) != null) {
- fail("Incorrect result on null parameter");
- }
- if (Security.getAlgorithmProperty("MyAlgorithm", "MyService") != null) {
- fail("Incorrect result (provider not added)");
- }
- Provider p = new MyProvider();
- Security.addProvider(p);
- try {
- if (!"SomeClassName".equals(Security.getAlgorithmProperty("MyAlGoriThm", "MySerVicE"))) {
- fail("Incorrect result (provider added)");
- }
- } finally { //clean up
- Security.removeProvider(p.getName());
- }
- }
-
+
public final void testInsertProviderAt() {
Provider p = new MyProvider();
int position;
@@ -203,20 +186,6 @@
}
/*
- * Class under test for Provider[] getProviders()
- */
- public final void testGetProviders() {
- Provider[] providers;
-
- providers = Security.getProviders();
- for (int i = 0; i < providers.length; i++) {
- if (providers[i].getProviderNumber() != i+1) { // position is 1-based
- fail("Incorrect provider number");
- }
- }
- }
-
- /*
* Class under test for Provider getProvider(String)
*/
public final void testGetProvider() {
@@ -247,127 +216,6 @@
}
}
- /*
- * Class under test for Provider[] getProviders(String)
- */
- public final void testGetProvidersString() {
- Provider[] providers;
- try {
- Security.getProviders("");
- fail("No expected InvalidParameterException");
- } catch (InvalidParameterException e) {
- }
-
-
- try {
- Security.getProviders((String)null);
- fail("No expected NullPointerException");
- } catch (NullPointerException e) {
- }
-
- try {
- Security.getProviders("AAA.BBB CCC");
- fail("AAA.BBB CCC: No expected InvalidParameterException");
- } catch (InvalidParameterException e) {
- }
-
- Provider p = new MyProvider();
-
- try {
- Security.addProvider(p);
- providers = Security.getProviders("MyService.MyAlgorithm");
- if (providers == null ||
- providers.length != 1 ||
- providers[0] != p) {
- fail("fail for MyService.MyAlgorithm");
- }
-
- providers = Security.getProviders("MyService.MyAlgorithm KeySize:512");
- if (providers == null ||
- providers.length != 1 ||
- providers[0] != p) {
- fail("fail for MyService.MyAlgorithm KeySize:512");
- }
-
- providers = Security.getProviders("MyService.MyAlgorithm KeySize:1025");
- if (providers != null) {
- fail("fail for MyService.MyAlgorithm KeySize:1025");
- }
- } finally { //clean up
- Security.removeProvider(p.getName());
- }
- }
-
- /*
- * Class under test for Provider[] getProviders(Map)
- */
- public final void testGetProvidersMap() {
- Provider[] providers;
- Map m = new Properties();
- Security.getProviders(m);
- if (Security.getProviders(m) != null) {
- fail("Not null result on empty map");
- }
-
- try {
- Security.getProviders((Map)null);
- fail("No expected NullPointerException");
- } catch (NullPointerException e) {
- }
-
- m.clear();
- m.put("AAA.BBB CCC", "");
- m.put("AAA.BBB", "");
- try {
- Security.getProviders(m);
- fail("attribute value is empty string: No expected InvalidParameterException");
- } catch (InvalidParameterException e) {
- }
-
- m.clear();
- m.put("AAA.BBB.CCC", "aaaa");
- m.put("AAA.BBB", "");
- try {
- Security.getProviders(m);
- fail("value associated with the key is not an empty string: No expected InvalidParameterException");
- } catch (InvalidParameterException e) {
- }
-
- Provider p = new MyProvider();
- try {
- Security.addProvider(p);
- m.clear();
- m.put("MyService.MyAlgorithm", "");
- m.put("MessageDigest.SHA-1", "");
- providers = Security.getProviders(m);
- if (providers == null ||
- providers.length != 1 ||
- providers[0] != p) {
- fail("fail for MyService.MyAlgorithm");
- }
-
- m.clear();
- m.put("MyService.MyAlgorithm KeySize", "512");
- m.put("MessageDigest.SHA-1", "");
- providers = Security.getProviders(m);
- if (providers == null ||
- providers.length != 1 ||
- providers[0] != p) {
- fail("fail for MyService.MyAlgorithm KeySize:512");
- }
-
- m.clear();
- m.put("MyService.MyAlgorithm KeySize", "1025");
- m.put("MessageDigest.SHA-1", "");
- providers = Security.getProviders(m);
- if (providers != null) {
- fail("fail for MyService.MyAlgorithm KeySize:1025");
- }
- } finally { //clean up
- Security.removeProvider(p.getName());
- }
- }
-
public final void testSetGetProperty() {
try {
Security.getProperty(null);
@@ -398,37 +246,6 @@
}
}
-
- public final void testGetAlgorithms() {
- Set alg1;
- Set alg2;
-
- alg1 = Security.getAlgorithms("AAAAAAAAAAAAAAA");
- if (alg1 == null || alg1.size() != 0) {
- fail("fail for non-existent service");
- }
-
- alg1 = Security.getAlgorithms("SecureRandom");
- alg2 = Security.getAlgorithms("seCuReranDom");
- if (alg1.size() != alg2.size()) {
- fail("different size");
- }
- if (!alg2.containsAll(alg1)) {
- fail("different content");
- }
-
- Provider p = new MyProvider();
-
- try {
- Security.addProvider(p);
- alg1 = Security.getAlgorithms("MyService");
- if (alg1.size() != 1 || !alg1.contains("MyAlgorithm")) {
- fail("fail for MyService");
- }
- } finally { //clean up
- Security.removeProvider(p.getName());
- }
- }
class MyProvider extends Provider {
MyProvider() {
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -75,67 +75,6 @@
}
/**
- * A permission is implied by this collection, if either of the following is
- * true:
- *
- * - This collection contains AllPermission;
- *
- This collection has elements of the same type as the permission
- * being checked, and they imply it;
- *
- This collection has UnresolvedPermissions which can be resolved to
- * the checked type, and after resolving they imply the checked one.
- *
- * 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));
-
- assertFalse(ps.implies(null));
- ps.add(ap);
- for (int i = 0; i < arr.length; i++) {
- assertTrue(ps.implies(arr[i]));
- }
- assertTrue(ps.implies(null));
- }
-
- /**
* Should return non-null empty enumeration for empty collection. For
* non-empty collection, should always return enumeration over unique
* elements.
@@ -195,10 +134,9 @@
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {}
try {
- assertFalse(ps.implies(null));
- //fail("should throw NPE");
+ ps.implies(null);
+ fail("should throw NPE");
} catch (NullPointerException e){
- fail("implies() should not fail on null argument");
}
try {
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderServiceTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderServiceTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/ProviderServiceTest.java (working copy)
@@ -19,10 +19,14 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
+import java.security.Provider;
+import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
+import org.apache.harmony.security.tests.support.RandomImpl;
+
import junit.framework.TestCase;
@@ -110,52 +114,30 @@
fail("getAttribute(KeySize) failed");
}
}
-
- public void testNewInstance() {
- Provider p = new MyProvider();
- Provider.Service s = new Provider.Service(p,
- "SecureRandom", "algorithm", "java.security.RandomImpl", null, null);
- Object o = null;
- try {
- o = s.newInstance(null);
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- fail("newInstance() failed");
- }
- if (!(o instanceof RandomImpl)) {
- fail("incorrect instance");
- }
-
- try {
- o = s.newInstance(new Object());
- fail("No expected NoSuchAlgorithmException");
- } catch (NoSuchAlgorithmException e) {
- }
- }
-
- /*
- * Class under test for String toString()
- */
- public void testToString() {
- Provider p = new MyProvider();
- Provider.Service s = new Provider.Service(p,
- "type", "algorithm", "className", null, null);
- if (!s.toString().equals("Provider MyProvider Service type.algorithm className")) {
- fail("first toString() failed");
- }
-
- HashMap hm = new HashMap();
- hm.put("attribute", "value");
- hm.put("KeySize", "1024");
- hm.put("AAA", "BBB");
-
- s = new Provider.Service(p, "type", "algorithm", "className",
- null, hm);
- if (!s.toString().startsWith("Provider MyProvider Service type.algorithm className\n" +
- "Attributes ")) {
- fail("second toString() failed");
- }
- }
+
+ public void testNewInstance() {
+ Provider p = new MyProvider();
+ Provider.Service s = new Provider.Service(p, "SecureRandom",
+ "algorithm",
+ "org.apache.harmony.security.tests.support.RandomImpl",
+ null, null);
+ Object o = null;
+ try {
+ o = s.newInstance(null);
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ fail("newInstance() failed");
+ }
+ if (!(o instanceof RandomImpl)) {
+ fail("incorrect instance");
+ }
+
+ try {
+ o = s.newInstance(new Object());
+ fail("No expected NoSuchAlgorithmException");
+ } catch (NoSuchAlgorithmException e) {
+ }
+ }
class MyProvider extends Provider {
MyProvider() {
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSSecretKeyEntryTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSSecretKeyEntryTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KSSecretKeyEntryTest.java (working copy)
@@ -19,9 +19,9 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
-
+import java.security.*;
import javax.crypto.SecretKey;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator1Test.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator1Test.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator1Test.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
import org.apache.harmony.security.tests.support.MyAlgorithmParameterGeneratorSpi;
@@ -318,33 +318,6 @@
assertEquals("Incorrect algorithm", ap.getAlgorithm().toUpperCase(),
apg.getAlgorithm().toUpperCase());
}
-
- /**
- * Test for init(int size) and
- * init(int size, SecureRandom random methods
- * Assertion: throws InvalidParameterExceptiom when size is incorrect
- */
- public void testAlgorithmParameterGenerator11() throws InvalidParameterException {
- if (!DSASupported) {
- fail(validAlgName + " algorithm is not supported");
- return;
- }
- int [] keys = {-10000, -512, -1, 0, 10000};
- SecureRandom random = new SecureRandom();
- AlgorithmParameterGenerator[] apgs = createAPGen();
- assertNotNull("AlgorithmParameterGenerator objects were not created",
- apgs);
-
- for (int i = 0; i < apgs.length; i++) {
- for (int j = 0; j < keys.length; j++) {
- apgs[i].init(keys[j]);
- apgs[i].init(keys[j], random);
- apgs[i].init(keys[j], null);
- }
- apgs[i].init(1024);
- apgs[i].init(1024, random);
- }
- }
/**
* Test for init(AlgorithmParameterSpec param) and
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignatureExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignatureExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SignatureExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.SignatureException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java (working copy)
@@ -19,8 +19,10 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
+
import junit.framework.TestCase;
/**
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/IdentityScopeTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/IdentityScopeTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/IdentityScopeTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import org.apache.harmony.security.tests.support.IdentityScopeStub;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGeneratorSpiTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGeneratorSpiTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGeneratorSpiTest.java (working copy)
@@ -19,9 +19,9 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.java.security;
-
+import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
import org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PublicKeyTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PublicKeyTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PublicKeyTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.PublicKey;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.Key;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import junit.framework.TestCase;
/**
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.io.File;
import java.net.URL;
import java.net.InetAddress;
@@ -194,19 +194,6 @@
/**
* Test for equals(Object)
- * 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)
* Checks that both 'null' and not-null URLs are taken into account - properly.
*/
public void testEqualsObject_04() {
@@ -221,35 +208,6 @@
}
/**
- * Test for equals(Object)
- * 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));
- }
-
- /**
* Tests CodeSource.getCeritficates().
*/
public void testGetCertificates_00() {
@@ -389,126 +347,6 @@
}
/**
- * getCodeSigners() must not take into account non-X509 certificates.
- */
- public void testGetCodeSigners_01() {
- if (!has_15_features()) {
- return;
- }
- 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() {
- if (!has_15_features()) {
- return;
- }
- ArrayList al = new ArrayList();
- boolean noMoreFactories = false;
- try {
- // remove all providers for x509
- // 'for' loop here for the sake of avoding 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() {
- if (!has_15_features()) {
- return;
- }
-
- 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() {
- if (!has_15_features()) {
- return;
- }
- 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 CodeSource.getLocation()
*/
public void testGetLocation() {
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator2Test.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator2Test.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator2Test.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
import org.apache.harmony.security.tests.support.MyKeyPairGenerator1;
Index: modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestExceptionTest.java
===================================================================
--- modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestExceptionTest.java (revision 412994)
+++ modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestExceptionTest.java (working copy)
@@ -19,8 +19,8 @@
* @version $Revision$
*/
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
+import java.security.*;
import java.security.DigestException;
import junit.framework.TestCase;
Index: modules/security/src/test/api/java.injected/java/security/MessageDigestSpiTest.java
===================================================================
--- modules/security/src/test/api/java.injected/java/security/MessageDigestSpiTest.java (revision 412994)
+++ modules/security/src/test/api/java.injected/java/security/MessageDigestSpiTest.java (working copy)
@@ -65,33 +65,6 @@
}
/*
- * Class under test for int engineDigest(byte[], int, int)
- */
- public void testEngineDigestbyteArrayintint() {
- MyMessageDigest md = new MyMessageDigest();
- byte[] b = new byte[5];
- try {
- md.engineDigest(null, 1, 1);
- fail("No expected NullPointerException");
- } catch (NullPointerException e) {
- } catch (DigestException e) {
- fail(e.toString());
- }
- try {
- md.engineDigest(b, 3, 10);
- fail("No expected DigestException");
- } catch (DigestException e) {
- }
- try {
- if (md.engineDigest(b, 1, 3) != 0) {
- fail("incorrect result");
- }
- } catch (DigestException e) {
- fail(e.toString());
- }
- }
-
- /*
* Class under test for Object clone()
*/
public void testClone() {
Index: modules/security/src/test/api/java.injected/java/security/SignatureTest.java
===================================================================
--- modules/security/src/test/api/java.injected/java/security/SignatureTest.java (revision 412994)
+++ modules/security/src/test/api/java.injected/java/security/SignatureTest.java (working copy)
@@ -29,7 +29,7 @@
* Tests for Signature constructor and methods
*
*/
-public class Signature1Test extends TestCase {
+public class SignatureTest extends TestCase {
/*
* Class under test for Object clone()
@@ -177,49 +177,6 @@
}
/*
- * Class under test for int sign(byte[], int, int)
- */
- public void testSignbyteArrayintint() {
- MySignature1 s = new MySignature1("ABC");
- byte[] b = new byte[8];
- try {
- s.sign(b, 0, 5);
- fail("No expected SignatureException 1");
- } catch (SignatureException e) {
- }
-
- try {
- s.initVerify(new MyPublicKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
-
- try {
- s.sign(b, 0, 5);
- fail("No expected SignatureException 1");
- } catch (SignatureException e) {
- }
-
- try {
- s.initSign(new MyPrivateKey());
- } catch (InvalidKeyException e) {
- fail(e.toString());
- }
-
- try {
- s.sign(b, 0, 5);
- } catch (SignatureException e) {
- fail(e.toString());
- }
- if (s.getState() != Signature.SIGN) {
- fail("Incorrect state");
- }
- if (!s.runEngineSign) {
- fail("sign() failed");
- }
- }
-
- /*
* Class under test for boolean verify(byte[])
*/
public void testVerifybyteArray() {
@@ -439,16 +396,6 @@
}
/*
- * Class under test for String toString()
- */
- public void testToString() {
- MySignature1 s = new MySignature1("ABC");
- if (!"SIGNATURE ABC state: UNINITIALIZED".equals(s.toString())) {
- fail("toString() failed");
- }
- }
-
- /*
* Class under test for void setParameter(String, Object)
*/
public void testSetParameterStringObject() {
Index: modules/security/src/test/api/java.injected/java/security/SecureRandomTest.java
===================================================================
--- modules/security/src/test/api/java.injected/java/security/SecureRandomTest.java (revision 412994)
+++ modules/security/src/test/api/java.injected/java/security/SecureRandomTest.java (working copy)
@@ -21,13 +21,15 @@
package java.security;
+import org.apache.harmony.security.tests.support.RandomImpl;
+
import junit.framework.TestCase;
/**
* Tests for SecureRandom constructor and methods
*
*/
-public class SecureRandom1Test extends TestCase {
+public class SecureRandomTest extends TestCase {
/**
* SRProvider
@@ -120,15 +122,8 @@
/*
* Class under test for SecureRandom getInstance(String, String)
*/
- public final void testGetInstanceStringString() {
- SecureRandom sr = null;
- try {
- sr = SecureRandom.getInstance("someRandom", "SRProvider");
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- } catch (NoSuchProviderException e) {
- fail(e.toString());
- }
+ public final void testGetInstanceStringString() throws Exception {
+ SecureRandom sr = SecureRandom.getInstance("someRandom", "SRProvider");
if (sr.getProvider() != p || !"someRandom".equals(sr.getAlgorithm())) {
fail("getInstance failed");
}
@@ -137,17 +132,12 @@
/*
* Class under test for SecureRandom getInstance(String, Provider)
*/
- public final void testGetInstanceStringProvider() {
- SecureRandom sr = null;
+ public final void testGetInstanceStringProvider() throws Exception {
Provider p = new SRProvider();
- try {
- sr = SecureRandom.getInstance("someRandom", p);
- } catch (NoSuchAlgorithmException e) {
- fail(e.toString());
- }
- if (sr.getProvider() != p || !"someRandom".equals(sr.getAlgorithm())) {
- fail("getInstance failed");
- }
+ SecureRandom sr = SecureRandom.getInstance("someRandom", p);
+ if (sr.getProvider() != p || !"someRandom".equals(sr.getAlgorithm())) {
+ fail("getInstance failed");
+ }
}
/*
@@ -180,9 +170,10 @@
}
class SRProvider extends Provider {
- public SRProvider() {
- super("SRProvider", 1.0, "SRProvider for testing");
- put("SecureRandom.someRandom", "java.security.RandomImpl");
- }
+ public SRProvider() {
+ super("SRProvider", 1.0, "SRProvider for testing");
+ put("SecureRandom.someRandom",
+ "org.apache.harmony.security.tests.support.RandomImpl");
+ }
}
}
Index: modules/security/src/test/api/java.injected/java/security/ProviderTest.java
===================================================================
--- modules/security/src/test/api/java.injected/java/security/ProviderTest.java (revision 0)
+++ modules/security/src/test/api/java.injected/java/security/ProviderTest.java (revision 0)
@@ -0,0 +1,219 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package java.security;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.tests.support.SpiEngUtils;
+import org.apache.harmony.security.tests.support.TestUtils;
+
+
+/**
+ * Tests for Provider constructor and methods
+ *
+ */
+public class ProviderTest extends TestCase {
+
+ Provider p;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ p = new MyProvider();
+ }
+
+ /*
+ * Class under test for void load(InputStream)
+ */
+ public final void testLoadInputStream() {
+ FileInputStream fis = null;
+ String fileName = SpiEngUtils.getFileName(TestUtils.TEST_ROOT,
+ "java/security/Provider.prop.dat");
+ try {
+ fis = new FileInputStream(fileName);
+ } catch (FileNotFoundException e) {
+ fail(e.toString());
+ }
+ try {
+ p.load(fis);
+ } catch (IOException e) {
+ fail(e.toString());
+ }
+
+ if (!"value 1".equals(p.getProperty("Property 1").trim()) ||
+ !"className".equals(p.getProperty("serviceName.algName").trim()) ||
+ !"attrValue".equals(p.getProperty("serviceName.algName attrName").trim()) ||
+ !"stanbdardName".equals(p.getProperty("Alg.Alias.engineClassName.aliasName").trim()) ||
+ !String.valueOf(p.getName()).equals(p.getProperty("Provider.id name").trim()) ||
+ !String.valueOf(p.getVersion()).equals(p.getProperty("Provider.id version").trim()) ||
+ !String.valueOf(p.getInfo()).equals(p.getProperty("Provider.id info").trim()) ||
+ !p.getClass().getName().equals(p.getProperty("Provider.id className").trim()) ||
+ !"SomeClassName".equals(p.getProperty("MessageDigest.SHA-1").trim()) ) {
+ fail("Incorrect property value");
+ }
+ }
+
+ public final void testGetService() {
+ try {
+ p.getService(null, "algorithm");
+ fail("No expected NullPointerException");
+ } catch (NullPointerException e) {
+ }
+ try {
+ p.getService("type", null);
+ fail("No expected NullPointerException");
+ } catch (NullPointerException e) {
+ }
+
+ Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
+ "className", null, null);
+ p.putService(s);
+
+ if (p.getService("Type", "AlgoRithM") != s) {
+ fail("Case 1. getService() failed");
+ }
+
+ Provider.Service s1 = p.getService("MessageDigest", "AbC");
+ if (s1 == null) {
+ fail("Case 2. getService() failed");
+ }
+
+ s = new Provider.Service(p, "MessageDigest", "SHA-1",
+ "className", null, null);
+ p.putService(s);
+ if (s1 == p.getService("MessageDigest", "SHA-1")) {
+ fail("Case 3. getService() failed");
+ }
+
+ if (p.getService("MessageDigest", "SHA1") == null) {
+ fail("Case 4. getService() failed");
+ }
+ }
+
+ public final void testGetServices() {
+ Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
+ "className", null, null);
+
+ // incomplete services should be removed
+ p.put("serv.alg", "aaaaaaaaaaaaa");
+ p.put("serv.alg KeySize", "11111");
+ p.put("serv1.alg1 KeySize", "222222");
+ p.remove("serv.alg");
+
+ p.putService(s);
+ Set services = p.getServices();
+ if (services.size() != 3) {
+ fail("incorrect size");
+ }
+ for (Iterator it = services.iterator(); it.hasNext();) {
+ s = (Provider.Service)it.next();
+ if ("Type".equals(s.getType()) &&
+ "Algorithm".equals(s.getAlgorithm()) &&
+ "className".equals(s.getClassName())) {
+ continue;
+ }
+ if ("MessageDigest".equals(s.getType()) &&
+ "SHA-1".equals(s.getAlgorithm()) &&
+ "SomeClassName".equals(s.getClassName())) {
+ continue;
+ }
+ if ("MessageDigest".equals(s.getType()) &&
+ "abc".equals(s.getAlgorithm()) &&
+ "SomeClassName".equals(s.getClassName())) {
+ continue;
+ }
+ fail("Incorrect service");
+ }
+ }
+
+ public final void testPutService() {
+ HashMap hm = new HashMap();
+ hm.put("KeySize", "1024");
+ hm.put("AAA", "BBB");
+ Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
+ "className", null, hm);
+ p.putService(s);
+ if (s != p.getService("Type", "Algorithm")){
+ fail("putService failed");
+ }
+ if (!"className".equals(p.getProperty("Type.Algorithm"))) {
+ fail("incorrect className");
+ }
+ if (!"1024".equals(p.getProperty("Type.Algorithm KeySize"))) {
+ fail("incorrect attribute");
+ }
+ }
+
+ public final void testRemoveService() {
+ Provider.Service s = new Provider.Service(p, "Type", "Algorithm",
+ "className", null, null);
+ p.putService(s);
+ p.removeService(s);
+ Set services = p.getServices();
+ if (services.size() != 2) {
+ fail("incorrect size");
+ }
+
+ for (Iterator it = services.iterator(); it.hasNext();) {
+ s = (Provider.Service)it.next();
+ if ("MessageDigest".equals(s.getType()) &&
+ "SHA-1".equals(s.getAlgorithm()) &&
+ "SomeClassName".equals(s.getClassName())) {
+ continue;
+ }
+ if ("MessageDigest".equals(s.getType()) &&
+ "abc".equals(s.getAlgorithm()) &&
+ "SomeClassName".equals(s.getClassName())) {
+ continue;
+ }
+ fail("Incorrect service");
+ }
+
+ if (p.getProperty("Type.Algorithm") != null) {
+ fail("incorrect property");
+ }
+ }
+
+ class MyProvider extends Provider {
+ MyProvider() {
+ super("MyProvider", 1.0, "Provider for testing");
+ put("MessageDigest.SHA-1", "SomeClassName");
+ put("MessageDigest.abc", "SomeClassName");
+ put("Alg.Alias.MessageDigest.SHA1", "SHA-1");
+ }
+
+ MyProvider(String name, double version, String info) {
+ super(name, version, info);
+ }
+ }
+}
Index: modules/security/src/test/api/java.injected/java/security/UnresolvedPermissionTest.java
===================================================================
--- modules/security/src/test/api/java.injected/java/security/UnresolvedPermissionTest.java (revision 0)
+++ modules/security/src/test/api/java.injected/java/security/UnresolvedPermissionTest.java (revision 0)
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+* @author Alexey V. Varlamov
+* @version $Revision$
+*/
+
+package java.security;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for UnresolvedPermission class fields and methods
+ *
+ */
+
+public class UnresolvedPermissionTest extends TestCase {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(UnresolvedPermissionTest.class);
+ }
+
+ /**
+ * Constructor for UnresolvedPermissionTest.
+ * @param arg0
+ */
+ public UnresolvedPermissionTest(String arg0) {
+ super(arg0);
+ }
+
+ /**
+ * Creates an Object with given name, type, action, certificaties.
+ * 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("exception is not thrown on null type");
+ }
+ catch (Exception ok) {}
+ /*try {
+ new UnresolvedPermission("", name, action, null);
+ fail("exception is not thrown on empty type");
+ }
+ catch (Exception ok) {}*/
+ }
+
+ /**
+ * 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")));
+ }
+
+ /**
+ * newPermissionCollection() should return new BasicPermissionCollection on every invokation
+ */
+ 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);
+ }
+}
Index: modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/tmpCallbackHandler.java
===================================================================
--- modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/tmpCallbackHandler.java (revision 412994)
+++ modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/tmpCallbackHandler.java (working copy)
@@ -19,7 +19,7 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.support;
import java.io.IOException;
Index: modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/RandomImpl.java
===================================================================
--- modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/RandomImpl.java (revision 412994)
+++ modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/RandomImpl.java (working copy)
@@ -18,8 +18,10 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.support;
+import java.security.SecureRandomSpi;
+
/**
* Test implementation of SecureRandom
*
@@ -32,7 +34,6 @@
protected void engineSetSeed(byte[] seed) {
runEngineSetSeed = true;
-
}
protected void engineNextBytes(byte[] bytes) {
Index: modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/MyKeyStore.java
===================================================================
--- modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/MyKeyStore.java (revision 412994)
+++ modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/MyKeyStore.java (working copy)
@@ -19,7 +19,7 @@
* @version $Revision$
*/
-package java.security;
+package org.apache.harmony.security.tests.support;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -37,8 +37,6 @@
import java.util.Enumeration;
import java.util.Hashtable;
-import org.apache.harmony.security.tests.support.MyLoadStoreParams;
-
/**
* Additional class for KeyStoreSpi and KeyStore verification
*
@@ -113,7 +111,7 @@
if (Chain.containsKey(alias)) {
Chain.remove(alias);
}
- KeyStore1Test.MyPrivateKey keyK = new KeyStore1Test("proba").new MyPrivateKey(
+ KeyStoreTestSupport.MyPrivateKey keyK = new KeyStoreTestSupport.MyPrivateKey(
alias, alias, key);
Keys.put(alias, keyK);
if (chain != null) {
Index: modules/security/src/main/java/common/java/security/Permissions.java
===================================================================
--- modules/security/src/main/java/common/java/security/Permissions.java (revision 413000)
+++ modules/security/src/main/java/common/java/security/Permissions.java (working copy)
@@ -178,12 +178,13 @@
* java.security.Permission the permission to check
*/
public boolean implies(Permission permission) {
+ if (permission == null) {
+ // RI compartible
+ throw new NullPointerException("Null permission");
+ }
if (allEnabled) {
return true;
}
- if (permission == null) {
- return false;
- }
Class klass = permission.getClass();
PermissionCollection klassMates = null;