Author: markt Date: Thu Jul 31 12:39:49 2014 New Revision: 1614869 URL: http://svn.apache.org/r1614869 Log: Move methods that interact with OpenSSL binary to a separate class as they will be useful to other tests.
Added: tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TesterOpenSSL.java (with props) Modified: tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TestCipher.java Modified: tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TestCipher.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TestCipher.java?rev=1614869&r1=1614868&r2=1614869&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TestCipher.java (original) +++ tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TestCipher.java Thu Jul 31 12:39:49 2014 @@ -16,8 +16,6 @@ */ package org.apache.tomcat.util.net.jsse.openssl; -import java.io.InputStream; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -27,9 +25,6 @@ import java.util.Set; import org.junit.Assert; import org.junit.Test; -import org.apache.catalina.util.IOTools; -import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream; - public class TestCipher { /** @@ -39,7 +34,7 @@ public class TestCipher { */ @Test public void testAllOpenSSLCiphersMapped() throws Exception { - Set<String> openSSLCipherSuites = getOpenSSLCiphersAsSet("ALL:eNULL"); + Set<String> openSSLCipherSuites = TesterOpenSSL.getOpenSSLCiphersAsSet("ALL:eNULL"); for (String openSSLCipherSuite : openSSLCipherSuites) { List<String> jsseCipherSuites = @@ -75,7 +70,7 @@ public class TestCipher { */ @Test public void testOpenSSLCipherAvailability() throws Exception { - Set<String> availableCipherSuites = getOpenSSLCiphersAsSet("ALL:eNULL"); + Set<String> availableCipherSuites = TesterOpenSSL.getOpenSSLCiphersAsSet("ALL:eNULL"); Set<String> expectedCipherSuites = new HashSet<>(); for (Cipher cipher : Cipher.values()) { String openSSLAlias = cipher.getOpenSSLAlias(); @@ -162,43 +157,6 @@ public class TestCipher { } - private static Set<String> getOpenSSLCiphersAsSet(String specification) throws Exception { - String[] ciphers = getOpenSSLCiphersAsExpression(specification).trim().split(":"); - Set<String> result = new HashSet<>(ciphers.length); - for (String cipher : ciphers) { - result.add(cipher); - } - return result; - - } - - - private static String getOpenSSLCiphersAsExpression(String specification) throws Exception { - String openSSLPath = System.getProperty("tomcat.test.openssl.path"); - if (openSSLPath == null || openSSLPath.length() == 0) { - openSSLPath = "openssl"; - } - List<String> cmd = new ArrayList<>(); - cmd.add(openSSLPath); - cmd.add("ciphers"); - if (specification != null) { - cmd.add(specification); - } - Process process = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()])); - InputStream stderr = process.getErrorStream(); - InputStream stdout = process.getInputStream(); - - ByteArrayOutputStream stderrBytes = new ByteArrayOutputStream(); - IOTools.flow(stderr, stderrBytes); - //String errorText = stderrBytes.toString(); - //Assert.assertTrue(errorText, errorText.length() == 0); - - ByteArrayOutputStream stdoutBytes = new ByteArrayOutputStream(); - IOTools.flow(stdout, stdoutBytes); - return stdoutBytes.toString(); - } - - /** * These are all the Oracle standard Java names for cipher suites taken from * http://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#ciphersuites Added: tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TesterOpenSSL.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TesterOpenSSL.java?rev=1614869&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TesterOpenSSL.java (added) +++ tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TesterOpenSSL.java Thu Jul 31 12:39:49 2014 @@ -0,0 +1,73 @@ +/* + * 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.tomcat.util.net.jsse.openssl; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.catalina.util.IOTools; +import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream; + +public class TesterOpenSSL { + + private TesterOpenSSL() { + // Utility class. Hide default constructor. + } + + + public static Set<String> getOpenSSLCiphersAsSet(String specification) throws Exception { + String[] ciphers = getOpenSSLCiphersAsExpression(specification).trim().split(":"); + Set<String> result = new HashSet<>(ciphers.length); + for (String cipher : ciphers) { + result.add(cipher); + } + return result; + + } + + + public static String getOpenSSLCiphersAsExpression(String specification) throws Exception { + String openSSLPath = System.getProperty("tomcat.test.openssl.path"); + if (openSSLPath == null || openSSLPath.length() == 0) { + openSSLPath = "openssl"; + } + List<String> cmd = new ArrayList<>(); + cmd.add(openSSLPath); + cmd.add("ciphers"); + if (specification != null) { + cmd.add(specification); + } + Process process = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()])); + InputStream stderr = process.getErrorStream(); + InputStream stdout = process.getInputStream(); + + ByteArrayOutputStream stderrBytes = new ByteArrayOutputStream(); + IOTools.flow(stderr, stderrBytes); + //String errorText = stderrBytes.toString(); + //Assert.assertTrue(errorText, errorText.length() == 0); + + ByteArrayOutputStream stdoutBytes = new ByteArrayOutputStream(); + IOTools.flow(stdout, stdoutBytes); + return stdoutBytes.toString(); + } + + + +} Propchange: tomcat/trunk/test/org/apache/tomcat/util/net/jsse/openssl/TesterOpenSSL.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org