You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/02/04 09:10:11 UTC
svn commit: r503371 [2/5] - in
/harmony/enhanced/classlib/trunk/modules/x-net: ./ META-INF/
src/main/java/org/apache/harmony/xnet/provider/jsse/
src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/
src/test/impl/java.injected/org/apache/harmo...
Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory1Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory1Test.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory1Test.java (added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory1Test.java Sun Feb 4 00:10:09 2007
@@ -0,0 +1,453 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.tests.javax.net.ssl;
+
+import java.security.InvalidAlgorithmParameterException;
+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 javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.TrustManagerFactorySpi;
+
+import org.apache.harmony.security.tests.support.SpiEngUtils;
+import org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi;
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>TrustManagerFactory</code> class constructors and methods.
+ *
+ */
+
+public class TrustManagerFactory1Test extends TestCase {
+
+ private static final String srvTrustManagerFactory = "TrustManagerFactory";
+
+ private static String defaultAlgorithm = null;
+
+ private static String defaultProviderName = null;
+
+ private static Provider defaultProvider = null;
+
+ private static boolean DEFSupported = false;
+
+ private static final String NotSupportedMsg = "There is no suitable provider for TrustManagerFactory";
+
+ private static final String[] invalidValues = SpiEngUtils.invalidValues;
+
+ private static String[] validValues = new String[3];
+ static {
+ defaultAlgorithm = Security
+ .getProperty("ssl.TrustManagerFactory.algorithm");
+ if (defaultAlgorithm != null) {
+ defaultProvider = SpiEngUtils.isSupport(defaultAlgorithm,
+ srvTrustManagerFactory);
+ DEFSupported = (defaultProvider != null);
+ defaultProviderName = (DEFSupported ? defaultProvider.getName()
+ : null);
+ validValues[0] = defaultAlgorithm;
+ validValues[1] = defaultAlgorithm.toUpperCase();
+ validValues[2] = defaultAlgorithm.toLowerCase();
+ }
+ }
+
+ protected TrustManagerFactory[] createTMFac() {
+ if (!DEFSupported) {
+ fail(defaultAlgorithm + " algorithm is not supported");
+ return null;
+ }
+ TrustManagerFactory[] tMF = new TrustManagerFactory[3];
+ try {
+ tMF[0] = TrustManagerFactory.getInstance(defaultAlgorithm);
+ tMF[1] = TrustManagerFactory.getInstance(defaultAlgorithm,
+ defaultProvider);
+ tMF[2] = TrustManagerFactory.getInstance(defaultAlgorithm,
+ defaultProviderName);
+ return tMF;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Test for <code>getDefaultAlgorithm()</code> method
+ * Assertion: returns value which is specifoed in security property
+ */
+ public void testGetDefaultAlgorithm() {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ String def = TrustManagerFactory.getDefaultAlgorithm();
+ if (defaultAlgorithm == null) {
+ assertNull("DefaultAlgorithm must be null", def);
+ } else {
+ assertEquals("Invalid default algorithm", def, defaultAlgorithm);
+ }
+ String defA = "Proba.trustmanagerfactory.defaul.type";
+ Security.setProperty("ssl.TrustManagerFactory.algorithm", defA);
+ assertEquals("Incorrect defaultAlgorithm",
+ TrustManagerFactory.getDefaultAlgorithm(), defA);
+ if (def == null) {
+ def = "";
+ }
+ Security.setProperty("ssl.TrustManagerFactory.algorithm", def);
+ assertEquals("Incorrect defaultAlgorithm",
+ TrustManagerFactory.getDefaultAlgorithm(), def);
+ }
+ /**
+ * Test for <code>getInstance(String algorithm)</code> method
+ * Assertions: returns security property "ssl.TrustManagerFactory.algorithm";
+ * returns instance of TrustManagerFactory
+ */
+ public void testTrustManagerFactory01() throws NoSuchAlgorithmException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ TrustManagerFactory trustMF;
+ for (int i = 0; i < validValues.length; i++) {
+ trustMF = TrustManagerFactory.getInstance(validValues[i]);
+ assertTrue("Not TrustManagerFactory object",
+ trustMF instanceof TrustManagerFactory);
+ assertEquals("Invalid algorithm", trustMF.getAlgorithm(),
+ validValues[i]);
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm)</code> method
+ * Assertion:
+ * throws NullPointerException when algorithm is null;
+ * throws NoSuchAlgorithmException when algorithm is not correct;
+ */
+ public void testTrustManagerFactory02() {
+ try {
+ TrustManagerFactory.getInstance(null);
+ fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
+ } catch (NoSuchAlgorithmException e) {
+ } catch (NullPointerException e) {
+ }
+ for (int i = 0; i < invalidValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(invalidValues[i]);
+ fail("NoSuchAlgorithmException was not thrown as expected for algorithm: "
+ .concat(invalidValues[i]));
+ } catch (NoSuchAlgorithmException e) {
+ }
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, String provider)</code>
+ * method
+ * Assertion: throws IllegalArgumentException when provider is null
+ * or empty
+ */
+ public void testTrustManagerFactory03() throws NoSuchProviderException,
+ NoSuchAlgorithmException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ String provider = null;
+ for (int i = 0; i < validValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(validValues[i], provider);
+ fail("IllegalArgumentException must be thrown when provider is null");
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ TrustManagerFactory.getInstance(validValues[i], "");
+ fail("IllegalArgumentException must be thrown when provider is empty");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, String provider)</code>
+ * method
+ * Assertion:
+ * throws NullPointerException when algorithm is null;
+ * throws NoSuchAlgorithmException when algorithm is not correct;
+ */
+ public void testTrustManagerFactory04() throws NoSuchProviderException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ try {
+ TrustManagerFactory.getInstance(null, defaultProviderName);
+ fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
+ } catch (NoSuchAlgorithmException e) {
+ } catch (NullPointerException e) {
+ }
+ for (int i = 0; i < invalidValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(invalidValues[i],
+ defaultProviderName);
+ fail("NoSuchAlgorithmException must be thrown (algorithm: "
+ .concat(invalidValues[i]).concat(")"));
+ } catch (NoSuchAlgorithmException e) {
+ }
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, String provider)</code>
+ * method
+ * Assertion: throws NoSuchProviderException when provider has
+ * invalid value
+ */
+ public void testTrustManagerFactory05() throws NoSuchAlgorithmException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ for (int i = 1; i < invalidValues.length; i++) {
+ for (int j = 0; j < validValues.length; j++) {
+ try {
+ TrustManagerFactory.getInstance(validValues[j],
+ invalidValues[i]);
+ fail("NuSuchProviderException must be thrown (algorithm: "
+ .concat(validValues[j]).concat(" provider: ")
+ .concat(invalidValues[i]).concat(")"));
+ } catch (NoSuchProviderException e) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, String provider)</code>
+ * method
+ * Assertion: returns instance of TrustManagerFactory
+ */
+ public void testTrustManagerFactory06() throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ TrustManagerFactory trustMF;
+ for (int i = 0; i < validValues.length; i++) {
+ trustMF = TrustManagerFactory.getInstance(validValues[i],
+ defaultProviderName);
+ assertTrue("Not TrustManagerFactory object",
+ trustMF instanceof TrustManagerFactory);
+ assertEquals("Invalid algorithm", trustMF.getAlgorithm(),
+ validValues[i]);
+ assertEquals("Invalid provider", trustMF.getProvider(),
+ defaultProvider);
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, Provider provider)</code>
+ * method
+ * Assertion: throws IllegalArgumentException when provider is null
+ */
+ public void testTrustManagerFactory07() throws NoSuchAlgorithmException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ Provider provider = null;
+ for (int i = 0; i < validValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(validValues[i], provider);
+ fail("IllegalArgumentException must be thrown when provider is null");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, Provider provider)</code>
+ * method
+ * Assertion:
+ * throws NullPointerException when algorithm is null;
+ * throws NoSuchAlgorithmException when algorithm is not correct;
+ */
+ public void testTrustManagerFactory08() {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ try {
+ TrustManagerFactory.getInstance(null, defaultProvider);
+ fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
+ } catch (NoSuchAlgorithmException e) {
+ } catch (NullPointerException e) {
+ }
+ for (int i = 0; i < invalidValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(invalidValues[i],
+ defaultProvider);
+ fail("NoSuchAlgorithmException must be thrown (algorithm: "
+ .concat(invalidValues[i]).concat(")"));
+ } catch (NoSuchAlgorithmException e) {
+ }
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, Provider provider)</code>
+ * method
+ * Assertion: returns instance of TrustManagerFactory
+ */
+ public void testTrustManagerFactory09() throws NoSuchAlgorithmException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ TrustManagerFactory trustMF;
+ for (int i = 0; i < validValues.length; i++) {
+ trustMF = TrustManagerFactory.getInstance(validValues[i],
+ defaultProvider);
+ assertTrue("Not TrustManagerFactory object",
+ trustMF instanceof TrustManagerFactory);
+ assertEquals("Invalid algorithm", trustMF.getAlgorithm(),
+ validValues[i]);
+ assertEquals("Invalid provider", trustMF.getProvider(),
+ defaultProvider);
+ }
+ }
+
+ /**
+ * Test for
+ * <code>TrustManagerFactory(TrustManagerFactorySpi impl, Provider prov, String algoriyjm) </code>
+ * constructor
+ * Assertion: created new TrustManagerFactory object
+ */
+ public void testTrustManagerFactory10() throws NoSuchAlgorithmException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ TrustManagerFactorySpi spi = new MyTrustManagerFactorySpi();
+ TrustManagerFactory tmF = new myTrustManagerFactory(spi, defaultProvider,
+ defaultAlgorithm);
+ assertTrue("Not CertStore object", tmF instanceof TrustManagerFactory);
+ assertEquals("Incorrect algorithm", tmF.getAlgorithm(),
+ defaultAlgorithm);
+ assertEquals("Incorrect provider", tmF.getProvider(), defaultProvider);
+ assertNull("Incorrect result", tmF.getTrustManagers());
+
+ tmF = new myTrustManagerFactory(null, null, null);
+ assertTrue("Not CertStore object", tmF instanceof TrustManagerFactory);
+ assertNull("Provider must be null", tmF.getProvider());
+ assertNull("Algorithm must be null", tmF.getAlgorithm());
+ try {
+ tmF.getTrustManagers();
+ fail("NullPointerException must be thrown");
+ } catch (NullPointerException e) {
+ }
+ }
+
+ /**
+ * Test for <code>init(KeyStore keyStore)</code> and
+ * <code>getTrustManagers()</code>
+ * Assertion: returns not empty TrustManager array
+ */
+ public void testTrustManagerFactory11() throws NoSuchAlgorithmException,
+ KeyStoreException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ KeyStore ks;
+ KeyStore ksNull = null;
+ try {
+ ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(null, null);
+ } catch (KeyStoreException e) {
+ fail(e.toString() + "default KeyStore type is not supported");
+ return;
+ } catch (Exception e) {
+ fail("Unexpected: " + e.toString());
+ return;
+ }
+ TrustManager[] tm;
+ TrustManagerFactory[] trustMF = createTMFac();
+ assertNotNull("TrustManagerFactory objects were not created", trustMF);
+ for (int i = 0; i < trustMF.length; i++) {
+ try {
+ trustMF[i].init(ksNull);
+ } catch (KeyStoreException e) {
+ }
+ trustMF[i].init(ks);
+ tm = trustMF[i].getTrustManagers();
+ assertNotNull("Result has not be null", tm);
+ assertTrue("Length of result TrustManager array should not be 0",
+ (tm.length > 0));
+ }
+ }
+
+ /**
+ * Test for <code>init(ManagerFactoryParameters params)</code>
+ * Assertion:
+ * throws InvalidAlgorithmParameterException when params is null
+ */
+ public void testTrustManagerFactory12() throws NoSuchAlgorithmException,
+ KeyStoreException, InvalidAlgorithmParameterException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
+ return;
+ }
+ ManagerFactoryParameters par = null;
+ ManagerFactoryParameters par1 = new myManagerFactoryParam();
+ TrustManagerFactory[] trustMF = createTMFac();
+ assertNotNull("TrustManagerFactory objects were not created", trustMF);
+ for (int i = 0; i < trustMF.length; i++) {
+ try {
+ trustMF[i].init(par);
+ fail("InvalidAlgorithmParameterException must be thrown");
+ } catch (InvalidAlgorithmParameterException e) {
+ }
+ try {
+ trustMF[i].init(par1);
+ fail("InvalidAlgorithmParameterException must be thrown");
+ } catch (InvalidAlgorithmParameterException e) {
+ }
+ }
+ }
+
+}
+
+/**
+ * Addifional class to verify TrustManagerFactory constructor
+ */
+
+class myTrustManagerFactory extends TrustManagerFactory {
+ public myTrustManagerFactory(TrustManagerFactorySpi spi, Provider prov,
+ String alg) {
+ super(spi, prov, alg);
+ }
+}
+
+class myManagerFactoryParam implements ManagerFactoryParameters {
+
+}
\ No newline at end of file
Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory1Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory2Test.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory2Test.java (added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory2Test.java Sun Feb 4 00:10:09 2007
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.tests.javax.net.ssl;
+
+import java.security.InvalidAlgorithmParameterException;
+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 javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.harmony.security.tests.support.SpiEngUtils;
+import org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi;
+import junit.framework.TestCase;
+
+/**
+ * Tests for TrustManagerFactory class constructors and methods
+ *
+ */
+
+public class TrustManagerFactory2Test extends TestCase {
+ private static final String srvTrustManagerFactory = "TrustManagerFactory";
+ private static final String defaultAlg = "TMF";
+ private static final String TrustManagerFactoryProviderClass = "org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi";
+
+ private static final String[] invalidValues = SpiEngUtils.invalidValues;
+
+ private static final String[] validValues;
+
+ static {
+ validValues = new String[4];
+ validValues[0] = defaultAlg;
+ validValues[1] = defaultAlg.toLowerCase();
+ validValues[2] = "Tmf";
+ validValues[3] = "tMF";
+ }
+
+ Provider mProv;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mProv = (new SpiEngUtils()).new MyProvider("MyTMFProvider",
+ "Provider for testing", srvTrustManagerFactory.concat(".")
+ .concat(defaultAlg), TrustManagerFactoryProviderClass);
+ Security.insertProviderAt(mProv, 1);
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ Security.removeProvider(mProv.getName());
+ }
+
+ private void checkResult(TrustManagerFactory tmf) throws InvalidAlgorithmParameterException {
+ KeyStore kStore = null;
+ ManagerFactoryParameters mfp = null;
+
+ try {
+ tmf.init(kStore);
+ fail("KeyStoreException must be thrown");
+ } catch (KeyStoreException e) {
+ }
+ try {
+ tmf.init(mfp);
+ fail("InvalidAlgorithmParameterException must be thrown");
+ } catch (InvalidAlgorithmParameterException e) {
+ }
+ assertNull("getTrustManagers() should return null object", tmf
+ .getTrustManagers());
+
+ try {
+ kStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ kStore.load(null, null);
+ } catch (KeyStoreException e) {
+ fail("default keystore is not supported");
+ return;
+ } catch (Exception e) {
+ fail("Unexpected: "+e.toString());
+ return;
+ }
+ try {
+ tmf.init(kStore);
+ } catch (KeyStoreException e) {
+ fail("Unexpected KeyStoreException was thrown");
+ }
+ mfp = (ManagerFactoryParameters) new MyTrustManagerFactorySpi.Parameters(null);
+ try {
+ tmf.init(mfp);
+ fail("RuntimeException must be thrown");
+ } catch (RuntimeException e) {
+ assertTrue("Incorrect exception", e.getCause() instanceof KeyStoreException);
+ }
+ mfp = (ManagerFactoryParameters) new MyTrustManagerFactorySpi.Parameters(kStore);
+ tmf.init(mfp);
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm)</code> method
+ * Assertions:
+ * throws NullPointerException when algorithm is null;
+ * throws NoSuchAlgorithmException when algorithm is not correct;
+ * returns TrustManagerFactory object
+ */
+ public void testGetInstance01() throws NoSuchAlgorithmException,
+ InvalidAlgorithmParameterException {
+ try {
+ TrustManagerFactory.getInstance(null);
+ fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
+ } catch (NoSuchAlgorithmException e) {
+ } catch (NullPointerException e) {
+ }
+ for (int i = 0; i < invalidValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(invalidValues[i]);
+ fail("NoSuchAlgorithmException must be thrown (algorithm: "
+ .concat(invalidValues[i]).concat(")"));
+ } catch (NoSuchAlgorithmException e) {
+ }
+ }
+ TrustManagerFactory tmf;
+ for (int i = 0; i < validValues.length; i++) {
+ tmf = TrustManagerFactory.getInstance(validValues[i]);
+ assertTrue("Not instanceof TrustManagerFactory object",
+ tmf instanceof TrustManagerFactory);
+ assertEquals("Incorrect algorithm", tmf.getAlgorithm(),
+ validValues[i]);
+ assertEquals("Incorrect provider", tmf.getProvider(), mProv);
+ checkResult(tmf);
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, String provider)</code>
+ * method
+ * Assertions:
+ * throws NullPointerException when algorithm is null;
+ * throws NoSuchAlgorithmException when algorithm is not correct;
+ * throws IllegalArgumentException when provider is null or empty;
+ * throws NoSuchProviderException when provider is available;
+ * returns TrustManagerFactory object
+ */
+ public void testGetInstance02() throws NoSuchAlgorithmException,
+ NoSuchProviderException, IllegalArgumentException,
+ InvalidAlgorithmParameterException {
+ try {
+ TrustManagerFactory.getInstance(null, mProv.getName());
+ fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
+ } catch (NoSuchAlgorithmException e) {
+ } catch (NullPointerException e) {
+ }
+ for (int i = 0; i < invalidValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(invalidValues[i], mProv
+ .getName());
+ fail("NoSuchAlgorithmException must be thrown (algorithm: "
+ .concat(invalidValues[i]).concat(")"));
+ } catch (NoSuchAlgorithmException e) {
+ }
+ }
+ String prov = null;
+ for (int i = 0; i < validValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(validValues[i], prov);
+ fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+ .concat(invalidValues[i]).concat(")"));
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ TrustManagerFactory.getInstance(validValues[i], "");
+ fail("IllegalArgumentException must be thrown when provider is empty (algorithm: "
+ .concat(invalidValues[i]).concat(")"));
+ } catch (IllegalArgumentException e) {
+ }
+ }
+ for (int i = 0; i < validValues.length; i++) {
+ for (int j = 1; j < invalidValues.length; j++) {
+ try {
+ TrustManagerFactory.getInstance(validValues[i],
+ invalidValues[j]);
+ fail("NoSuchProviderException must be thrown (algorithm: "
+ .concat(invalidValues[i]).concat(" provider: ")
+ .concat(invalidValues[j]).concat(")"));
+ } catch (NoSuchProviderException e) {
+ }
+ }
+ }
+ TrustManagerFactory tmf;
+ for (int i = 0; i < validValues.length; i++) {
+ tmf = TrustManagerFactory.getInstance(validValues[i], mProv
+ .getName());
+ assertTrue("Not instanceof TrustManagerFactory object",
+ tmf instanceof TrustManagerFactory);
+ assertEquals("Incorrect algorithm", tmf.getAlgorithm(),
+ validValues[i]);
+ assertEquals("Incorrect provider", tmf.getProvider().getName(),
+ mProv.getName());
+ checkResult(tmf);
+ }
+ }
+
+ /**
+ * Test for <code>getInstance(String algorithm, Provider provider)</code>
+ * method
+ * Assertions:
+ * throws NullPointerException when algorithm is null;
+ * throws NoSuchAlgorithmException when algorithm is not correct;
+ * throws IllegalArgumentException when provider is null;
+ * returns TrustManagerFactory object
+ */
+ public void testGetInstance03() throws NoSuchAlgorithmException,
+ IllegalArgumentException,
+ InvalidAlgorithmParameterException {
+ try {
+ TrustManagerFactory.getInstance(null, mProv);
+ fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
+ } catch (NoSuchAlgorithmException e) {
+ } catch (NullPointerException e) {
+ }
+ for (int i = 0; i < invalidValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(invalidValues[i], mProv);
+ fail("NoSuchAlgorithmException must be thrown (algorithm: "
+ .concat(invalidValues[i]).concat(")"));
+ } catch (NoSuchAlgorithmException e) {
+ }
+ }
+ Provider prov = null;
+ for (int i = 0; i < validValues.length; i++) {
+ try {
+ TrustManagerFactory.getInstance(validValues[i], prov);
+ fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+ .concat(invalidValues[i]).concat(")"));
+ } catch (IllegalArgumentException e) {
+ }
+ }
+ TrustManagerFactory tmf;
+ for (int i = 0; i < validValues.length; i++) {
+ tmf = TrustManagerFactory.getInstance(validValues[i], mProv);
+ assertTrue("Not instanceof TrustManagerFactory object",
+ tmf instanceof TrustManagerFactory);
+ assertEquals("Incorrect algorithm", tmf.getAlgorithm(),
+ validValues[i]);
+ assertEquals("Incorrect provider", tmf.getProvider(), mProv);
+ checkResult(tmf);
+ }
+ }
+}
\ No newline at end of file
Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/TrustManagerFactory2Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java Sun Feb 4 00:10:09 2007
@@ -0,0 +1,475 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>CipherSuite</code> constructor and methods
+ *
+ */
+public class CipherSuiteTest extends TestCase {
+
+ public void testEquals() {
+ CipherSuite c1 = new CipherSuite("CipherSuite1", false, 0, "", "",
+ new byte[] { 10, 10 });
+ CipherSuite c2 = new CipherSuite("CipherSuite2", false, 0, "", "",
+ new byte[] { 10, 10 });
+ CipherSuite c3 = new CipherSuite("CipherSuite3", false, 0, "", "",
+ new byte[] { 10, 11 });
+ CipherSuite c4 = new CipherSuite("CipherSuite4", false, 0, "", "",
+ new byte[] { 11, 10 });
+ if (!c1.equals(c2) || c1.equals(c3) || c4.equals(c1) || c4.equals(c3)) {
+ fail("testEquals failed");
+ }
+ }
+
+ public void testToString() {
+ CipherSuite c1 = new CipherSuite("CipherSuite1", false, 0, "", "",
+ new byte[] { 10, 10 });
+ assertEquals("testToString failed", "CipherSuite1: 10 10",
+ c1.toString());
+ }
+
+ public void testGetByName() {
+ CipherSuite[] suites = CipherSuite.getSupported();
+ for (int i = 0; i < suites.length; i++) {
+ assertEquals("incorrect cipher suite returned", suites[i],
+ CipherSuite.getByName(suites[i].getName()));
+ }
+ assertNull("non null cipher suite returned for name: SomeName",
+ CipherSuite.getByName("SomeName"));
+ }
+
+ /*
+ * Class under test for CipherSuite getByCode(byte, byte)
+ */
+ public void testGetByCodebytebyte() {
+ CipherSuite[] suites = CipherSuite.getSupported();
+ for (int i = 0; i < suites.length; i++) {
+ byte[] code = suites[i].toBytes();
+ assertEquals("incorrect cipher suite returned", suites[i],
+ CipherSuite.getByCode(code[0], code[1]));
+ }
+ assertEquals("incorrect cipher suite returned for code: 10 10",
+ new CipherSuite("UNKNOUN_10_10", false, 0, "", "", new byte[] {
+ 10, 10 }), CipherSuite.getByCode((byte) 10, (byte) 10));
+ }
+
+ /*
+ * Class under test for CipherSuite getByCode(byte, byte, byte)
+ */
+ public void testGetByCodebytebytebyte() {
+ CipherSuite[] suites = CipherSuite.getSupported();
+ for (int i = 0; i < suites.length; i++) {
+ byte[] code = suites[i].toBytes();
+ assertEquals("incorrect cipher suite returned", suites[i],
+ CipherSuite.getByCode((byte) 0, (byte) 0, code[1]));
+ }
+ assertEquals("incorrect cipher suite returned for code: 10 10 10",
+ new CipherSuite("UNKNOUN_10_10_10", false, 0, "", "",
+ new byte[] { 10, 10, 10 }),
+ CipherSuite.getByCode((byte) 10, (byte) 10, (byte) 10));
+ }
+
+ public void testIsAnonymous() {
+ CipherSuite c1 = new CipherSuite("CipherSuite1", false,
+ CipherSuite.KeyExchange_DH_anon, "", "", new byte[] { 10, 10 });
+ CipherSuite c2 = new CipherSuite("CipherSuite2", false,
+ CipherSuite.KeyExchange_DH_anon_EXPORT, "", "", new byte[] { 9,
+ 10 });
+ CipherSuite c3 = new CipherSuite("CipherSuite3", false,
+ CipherSuite.KeyExchange_DH_DSS, "", "", new byte[] { 10, 11 });
+ CipherSuite c4 = new CipherSuite("CipherSuite4", false,
+ CipherSuite.KeyExchange_DH_RSA, "", "", new byte[] { 11, 10 });
+ assertTrue(c1.isAnonymous());
+ assertTrue(c1.isAnonymous());
+ assertFalse(c3.isAnonymous());
+ assertFalse(c4.isAnonymous());
+ }
+
+ public void testGetSupported() {
+ CipherSuite[] suites = CipherSuite.getSupported();
+ for (int i = 0; i < suites.length; i++) {
+ assertTrue(suites[i].supported);
+ }
+ }
+
+ public void testGetSupportedCipherSuiteNames() {
+ CipherSuite[] suites = CipherSuite.getSupported();
+ String[] names = CipherSuite.getSupportedCipherSuiteNames();
+ for (int i = 0; i < suites.length; i++) {
+ assertEquals(suites[i].getName(), names[i]);
+ }
+ }
+
+ public void testGetBulkEncryptionAlgorithm() {
+ assertEquals(CipherSuite.TLS_NULL_WITH_NULL_NULL
+ .getBulkEncryptionAlgorithm(), null);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_MD5
+ .getBulkEncryptionAlgorithm(), null);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_SHA
+ .getBulkEncryptionAlgorithm(), null);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5
+ .getBulkEncryptionAlgorithm(), "RC4");
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_MD5
+ .getBulkEncryptionAlgorithm(), "RC4");
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_SHA
+ .getBulkEncryptionAlgorithm(), "RC4");
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
+ .getBulkEncryptionAlgorithm(), "RC2/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_RSA_WITH_IDEA_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "IDEA/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_RSA_WITH_DES_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DESede/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_DES_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DESede/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_DES_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DESede/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_DES_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DESede/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_DES_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DESede/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
+ .getBulkEncryptionAlgorithm(), "RC4");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5
+ .getBulkEncryptionAlgorithm(), "RC4");
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_DES_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DES/CBC/NoPadding");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
+ .getBulkEncryptionAlgorithm(), "DESede/CBC/NoPadding");
+ }
+
+ public void testGetBlockSize() {
+ assertEquals(CipherSuite.TLS_NULL_WITH_NULL_NULL
+ .getBlockSize(), 0);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_MD5
+ .getBlockSize(), 0);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_SHA
+ .getBlockSize(), 0);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5
+ .getBlockSize(), 0);
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_MD5
+ .getBlockSize(), 0);
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_SHA
+ .getBlockSize(), 0);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_RSA_WITH_IDEA_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_RSA_WITH_DES_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_DES_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_DES_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_DES_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_DES_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
+ .getBlockSize(), 0);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5
+ .getBlockSize(), 0);
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_DES_CBC_SHA
+ .getBlockSize(), 8);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
+ .getBlockSize(), 8);
+ }
+
+ public void testGetHmacName() {
+ assertEquals(CipherSuite.TLS_NULL_WITH_NULL_NULL
+ .getHmacName(), null);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_MD5
+ .getHmacName(), "HmacMD5");
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5
+ .getHmacName(), "HmacMD5");
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_MD5
+ .getHmacName(), "HmacMD5");
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
+ .getHmacName(), "HmacMD5");
+ assertEquals(CipherSuite.TLS_RSA_WITH_IDEA_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_RSA_WITH_DES_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_DES_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_DES_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_DES_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_DES_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
+ .getHmacName(), "HmacMD5");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5
+ .getHmacName(), "HmacMD5");
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_DES_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
+ .getHmacName(), "HmacSHA1");
+ }
+
+ public void testGetHashName() {
+ assertEquals(CipherSuite.TLS_NULL_WITH_NULL_NULL
+ .getHashName(), null);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_MD5
+ .getHashName(), "MD5");
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5
+ .getHashName(), "MD5");
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_MD5
+ .getHashName(), "MD5");
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
+ .getHashName(), "MD5");
+ assertEquals(CipherSuite.TLS_RSA_WITH_IDEA_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_RSA_WITH_DES_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_DES_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_DES_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_DES_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_DES_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
+ .getHashName(), "MD5");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5
+ .getHashName(), "MD5");
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_DES_CBC_SHA
+ .getHashName(), "SHA-1");
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
+ .getHashName(), "SHA-1");
+ }
+
+ public void testGetMACLength() {
+ assertEquals(CipherSuite.TLS_NULL_WITH_NULL_NULL
+ .getMACLength(), 0);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_MD5
+ .getMACLength(), 16);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5
+ .getMACLength(), 16);
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_MD5
+ .getMACLength(), 16);
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
+ .getMACLength(), 16);
+ assertEquals(CipherSuite.TLS_RSA_WITH_IDEA_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_RSA_WITH_DES_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_DES_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_DES_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_DES_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_DES_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
+ .getMACLength(), 16);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5
+ .getMACLength(), 16);
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_DES_CBC_SHA
+ .getMACLength(), 20);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
+ .getMACLength(), 20);
+ }
+
+ public void testIsExportable() {
+ assertEquals(CipherSuite.TLS_NULL_WITH_NULL_NULL
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_MD5
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_RSA_WITH_NULL_SHA
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_MD5
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_RSA_WITH_RC4_128_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_RSA_WITH_IDEA_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_RSA_WITH_DES_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_DES_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_DES_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_DES_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_DES_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
+ .isExportable(), true);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_DES_CBC_SHA
+ .isExportable(), false);
+ assertEquals(CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
+ .isExportable(), false);
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DelegatedTaskTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DelegatedTaskTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DelegatedTaskTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DelegatedTaskTest.java Sun Feb 4 00:10:09 2007
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.security.KeyManagementException;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>DelegatedTask</code> constructor and methods
+ *
+ */
+public class DelegatedTaskTest extends TestCase {
+
+ public void testDelegatedTask() throws Exception {
+ HandshakeProtocol protocol = new ClientHandshakeImpl(new SSLEngineImpl(
+ new SSLParameters(null, null, null,
+ new SSLSessionContextImpl(),
+ new SSLSessionContextImpl())));
+
+ DelegatedTask task = new DelegatedTask(null, protocol, null);
+ task.run();
+ assertTrue(protocol.delegatedTaskErr instanceof NullPointerException);
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DelegatedTaskTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DigitalSignatureTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DigitalSignatureTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DigitalSignatureTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DigitalSignatureTest.java Sun Feb 4 00:10:09 2007
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.security.KeyStore;
+import java.security.MessageDigest;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>DigitalSignature</code> constructor and methods
+ *
+ */
+public class DigitalSignatureTest extends TestCase {
+
+ private PrivateKey key;
+ private Certificate cert;
+
+ public void setUp() throws Exception {
+
+ char[] pwd = JSSETestData.KS_PASSWORD;
+ KeyStore ks = JSSETestData.getKeyStore();
+ KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) ks
+ .getEntry("ssl_test_store",
+ new KeyStore.PasswordProtection(pwd));
+ key = entry.getPrivateKey();
+ cert = entry.getCertificate();
+ }
+
+ public void testDigitalSignature_1() throws Exception {
+
+ MessageDigest md5 = null;
+ MessageDigest sha = null;
+
+ md5 = MessageDigest.getInstance("MD5");
+ sha = MessageDigest.getInstance("SHA-1");
+
+ DigitalSignature ds_sign = new DigitalSignature(
+ CipherSuite.KeyExchange_RSA_EXPORT);
+ DigitalSignature ds_verify = new DigitalSignature(
+ CipherSuite.KeyExchange_RSA_EXPORT);
+ ds_sign.init(key);
+ // use pivateKeyEncoding as signed data
+ byte[] pivateKeyEncoding = key.getEncoded();
+ ds_sign.update(pivateKeyEncoding);
+ byte[] hash = ds_sign.sign();
+
+ // verify
+ byte[] md5_hash = new byte[16];
+ byte[] sha_hash = new byte[20];
+ sha.update(pivateKeyEncoding);
+ md5.update(pivateKeyEncoding);
+
+ sha.digest(sha_hash, 0, sha_hash.length);
+ md5.digest(md5_hash, 0, md5_hash.length);
+
+ ds_verify.init(cert);
+ ds_verify.setMD5(md5_hash);
+ ds_verify.setSHA(sha_hash);
+
+ assertTrue(ds_verify.verifySignature(hash));
+ }
+
+ public void testDigitalSignature_2() throws Exception {
+
+ DigitalSignature ds_sign = new DigitalSignature(
+ CipherSuite.KeyExchange_RSA_EXPORT);
+ DigitalSignature ds_verify = new DigitalSignature(
+ CipherSuite.KeyExchange_RSA_EXPORT);
+ ds_sign.init(key);
+
+ byte[] md5_hash = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16 };
+ byte[] sha_hash = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 18, 19, 20 };
+ ds_sign.setMD5(md5_hash);
+ ds_sign.setSHA(sha_hash);
+ byte[] hash = ds_sign.sign();
+
+ // verify
+ ds_verify.init(cert);
+ ds_verify.setMD5(md5_hash);
+ ds_verify.setSHA(sha_hash);
+ assertTrue(ds_verify.verifySignature(hash));
+ }
+
+}
\ No newline at end of file
Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/DigitalSignatureTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/HandshakeProtocolTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/HandshakeProtocolTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/HandshakeProtocolTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/HandshakeProtocolTest.java Sun Feb 4 00:10:09 2007
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.security.KeyManagementException;
+import java.security.KeyPairGenerator;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+
+import javax.net.ssl.SSLEngineResult;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>HandshakeProtocol</code> constructor and methods
+ *
+ */
+public class HandshakeProtocolTest extends TestCase {
+
+ public void testGetStatus() throws Exception {
+ HandshakeProtocol protocol = new ClientHandshakeImpl(new SSLEngineImpl(
+ new SSLParameters(null, null, null,
+ new SSLSessionContextImpl(),
+ new SSLSessionContextImpl())));
+
+ assertEquals(protocol.getStatus(),
+ SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING);
+
+ protocol.status = HandshakeProtocol.NEED_UNWRAP;
+ assertEquals(protocol.getStatus(),
+ SSLEngineResult.HandshakeStatus.NEED_UNWRAP);
+
+ protocol.status = HandshakeProtocol.FINISHED;
+ assertEquals(protocol.getStatus(),
+ SSLEngineResult.HandshakeStatus.FINISHED);
+ assertEquals(protocol.status, HandshakeProtocol.NOT_HANDSHAKING);
+
+ protocol.delegatedTaskErr = new Exception();
+ assertEquals(protocol.getStatus(),
+ SSLEngineResult.HandshakeStatus.NEED_WRAP);
+ protocol.delegatedTaskErr = null;
+
+ protocol.delegatedTasks.add(new DelegatedTask(null, null, null));
+ assertEquals(protocol.getStatus(),
+ SSLEngineResult.HandshakeStatus.NEED_TASK);
+ protocol.delegatedTasks.clear();
+
+ protocol.io_stream.write(new byte[] { 1, 2, 3 });
+ assertEquals(protocol.getStatus(),
+ SSLEngineResult.HandshakeStatus.NEED_WRAP);
+ }
+
+ public void testSendChangeCipherSpec() throws Exception {
+ HandshakeProtocol protocol = new ServerHandshakeImpl(new SSLEngineImpl(
+ new SSLParameters(null, null, null,
+ new SSLSessionContextImpl(),
+ new SSLSessionContextImpl())));
+
+ protocol.sendChangeCipherSpec();
+ assertEquals(protocol.getStatus(),
+ SSLEngineResult.HandshakeStatus.NEED_WRAP);
+ }
+
+ public void testWrap() throws Exception {
+ HandshakeProtocol protocol = new ClientHandshakeImpl(new SSLEngineImpl(
+ new SSLParameters(null, null, null,
+ new SSLSessionContextImpl(),
+ new SSLSessionContextImpl())));
+
+ assertEquals(protocol.wrap(), null);
+
+ protocol.delegatedTaskErr = new Exception();
+ try {
+ protocol.wrap();
+ fail("No expected AlertException");
+ } catch (AlertException e) {
+ assertEquals(e.getDescriptionCode(),
+ AlertProtocol.HANDSHAKE_FAILURE);
+ assertEquals(protocol.delegatedTaskErr, null);
+ }
+ }
+
+ public void testcomputerVerifyDataTLS() throws Exception {
+ HandshakeProtocol hs_protocol = new ClientHandshakeImpl(
+ new SSLEngineImpl(new SSLParameters(null, null, null,
+ new SSLSessionContextImpl(),
+ new SSLSessionContextImpl())));
+
+ SecureRandom sr = new SecureRandom();
+ SSLSessionImpl ses = new SSLSessionImpl(sr);
+ hs_protocol.session = ses;
+ hs_protocol.session.protocol = ProtocolVersion.TLSv1;
+ assertSame(hs_protocol.getSession(), ses);
+
+ hs_protocol.clientHello = new ClientHello(
+ sr,
+ hs_protocol.session.protocol.version,
+ hs_protocol.session.id,
+ new CipherSuite[] { CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA });
+ hs_protocol.serverHello = new ServerHello(sr,
+ hs_protocol.session.protocol.version, hs_protocol.session.id,
+ CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA, (byte) 0);
+
+ hs_protocol.preMasterSecret = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+ hs_protocol.computerMasterSecret();
+ assertEquals(hs_protocol.preMasterSecret, null);
+ assertEquals(hs_protocol.session.master_secret.length, 48);
+
+ hs_protocol.send(hs_protocol.clientHello);
+ hs_protocol.send(hs_protocol.serverHello);
+
+ hs_protocol.computerReferenceVerifyDataTLS("test");
+
+ byte[] data = new byte[12];
+ hs_protocol.computerVerifyDataTLS("test", data);
+
+ hs_protocol.verifyFinished(data);
+
+ try {
+ hs_protocol.verifyFinished(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 0, 1, 2 });
+ fail("No expected AlertException");
+ } catch (AlertException e) {
+ }
+ }
+
+ public void testComputerReferenceVerifyDataSSLv3() throws Exception {
+ HandshakeProtocol hs_protocol = new ClientHandshakeImpl(
+ new SSLEngineImpl(new SSLParameters(null, null, null,
+ new SSLSessionContextImpl(),
+ new SSLSessionContextImpl())));
+
+ SecureRandom sr = new SecureRandom();
+ SSLSessionImpl ses = new SSLSessionImpl(sr);
+ hs_protocol.session = ses;
+ hs_protocol.session.protocol = ProtocolVersion.SSLv3;
+ assertSame(hs_protocol.getSession(), ses);
+
+ hs_protocol.clientHello = new ClientHello(
+ sr,
+ hs_protocol.session.protocol.version,
+ hs_protocol.session.id,
+ new CipherSuite[] { CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA });
+ hs_protocol.serverHello = new ServerHello(sr,
+ hs_protocol.session.protocol.version, hs_protocol.session.id,
+ CipherSuite.TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA, (byte) 0);
+
+ hs_protocol.preMasterSecret = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+ hs_protocol.computerMasterSecret();
+ assertEquals(hs_protocol.preMasterSecret, null);
+ assertEquals(hs_protocol.session.master_secret.length, 48);
+
+ hs_protocol.send(hs_protocol.clientHello);
+ hs_protocol.send(hs_protocol.serverHello);
+
+ hs_protocol.computerReferenceVerifyDataSSLv3(SSLv3Constants.client);
+
+ byte[] data = new byte[36];
+ hs_protocol.computerVerifyDataSSLv3(SSLv3Constants.client, data);
+
+ hs_protocol.verifyFinished(data);
+
+ try {
+ hs_protocol.verifyFinished(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 0, 1, 2 });
+ fail("No expected AlertException");
+ } catch (AlertException e) {
+ }
+ }
+
+ public void testUnexpectedMessage() throws Exception {
+ HandshakeProtocol protocol = new ClientHandshakeImpl(new SSLEngineImpl(
+ new SSLParameters(null, null, null,
+ new SSLSessionContextImpl(),
+ new SSLSessionContextImpl())));
+ try {
+ protocol.unexpectedMessage();
+ fail("No expected AlertException");
+ } catch (AlertException e) {
+ assertEquals(e.getDescriptionCode(),
+ AlertProtocol.UNEXPECTED_MESSAGE);
+ }
+ }
+
+ public void testGetTask() throws Exception {
+ HandshakeProtocol protocol = new ClientHandshakeImpl(new SSLEngineImpl(
+ new SSLParameters(null, null, null,
+ new SSLSessionContextImpl(),
+ new SSLSessionContextImpl())));
+
+ DelegatedTask task = new DelegatedTask(null, null, null);
+ protocol.delegatedTasks.add(task);
+ assertSame(protocol.getTask(), task);
+ assertEquals(protocol.getTask(), null);
+ }
+
+ public void testGetRSAKeyLength() throws Exception {
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
+ kpg.initialize(512);
+ PublicKey key = kpg.genKeyPair().getPublic();
+
+ assertEquals(HandshakeProtocol.getRSAKeyLength(key), 512);
+ }
+
+}
\ No newline at end of file
Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/HandshakeProtocolTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/KeyManagerImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/KeyManagerImplTest.java?view=auto&rev=503371
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/KeyManagerImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/KeyManagerImplTest.java Sun Feb 4 00:10:09 2007
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.Socket;
+import java.security.KeyStore;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>KeyManagerImpl</code> constructor and methods
+ *
+ */
+public class KeyManagerImplTest extends TestCase {
+
+ public void testKeyManagerImpl1() throws Exception {
+ KeyStore ks = null;
+ ks = KeyStore.getInstance("BKS");
+ ks.load(null, null);
+
+ KeyManagerImpl km = new KeyManagerImpl(ks, new char[0]);
+ String[] keyType = {"RSA", "DSA"};
+ String al = km.chooseClientAlias(keyType, null, new Socket());
+ assertEquals(al, null);
+
+ al = km.chooseEngineClientAlias(keyType, null, new SSLEngineImpl(null));
+ assertEquals(al, null);
+
+ al = km.chooseEngineServerAlias("RSA", null, new SSLEngineImpl(null));
+ assertEquals(al, null);
+
+ al = km.chooseServerAlias("RSA", null, new Socket());
+ assertEquals(al, null);
+
+ assertEquals(km.getClientAliases("RSA", null), null);
+
+ assertEquals(km.getServerAliases("RSA", null), null);
+
+ assertEquals(km.getCertificateChain("alias"), null);
+ assertEquals(km.getPrivateKey("alias"), null);
+ }
+
+ public void testKeyManagerImpl2() throws Exception {
+
+ KeyStore ks = JSSETestData.getKeyStore();
+ char[] pwd = JSSETestData.KS_PASSWORD;
+
+ KeyManagerImpl km = new KeyManagerImpl(ks, pwd);
+ String[] keyType = { "RSA", "DSA" };
+ String al = km.chooseClientAlias(keyType, null, new Socket());
+ assertEquals(al, "ssl_test_store");
+
+ al = km.chooseEngineClientAlias(keyType, null, new SSLEngineImpl(null));
+ assertEquals(al, "ssl_test_store");
+
+ al = km.chooseEngineServerAlias("RSA", null, new SSLEngineImpl(null));
+ assertEquals(al, "ssl_test_store");
+
+ al = km.chooseServerAlias("RSA", null, new Socket());
+ assertEquals(al, "ssl_test_store");
+
+ assertTrue(km.getCertificateChain("ssl_test_store") != null);
+ assertTrue(km.getPrivateKey("ssl_test_store") != null);
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/KeyManagerImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native