annotate test/sun/management/jmxremote/bootstrap/SSLConfigFilePermissionTest.sh @ 6252:ae5d04dbacd6

8003890: corelibs test scripts should pass TESTVMOPTS Reviewed-by: chegar, alanb Contributed-by: Mark Sheppard <mark.sheppard@oracle.com>
author chegar
date Thu, 13 Dec 2012 14:47:35 +0000
parents 00cd9dc3c2b5
children 7da291690aa0
rev   line source
duke@0 1 #!/bin/sh
duke@0 2
duke@0 3 #
ohair@2362 4 # Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
duke@0 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 6 #
duke@0 7 # This code is free software; you can redistribute it and/or modify it
duke@0 8 # under the terms of the GNU General Public License version 2 only, as
duke@0 9 # published by the Free Software Foundation.
duke@0 10 #
duke@0 11 # This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 # version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 # accompanied this code).
duke@0 16 #
duke@0 17 # You should have received a copy of the GNU General Public License version
duke@0 18 # 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 #
ohair@2362 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 # or visit www.oracle.com if you need additional information or have any
ohair@2362 23 # questions.
duke@0 24 #
duke@0 25
duke@0 26
duke@0 27 # @test
duke@0 28 # @bug 6557093
duke@0 29 # @summary Check SSL config file permission for out-of-the-box management
duke@0 30 #
duke@0 31 # @run shell SSLConfigFilePermissionTest.sh
duke@0 32
duke@0 33 createJavaFile()
duke@0 34 {
duke@0 35 cat << EOF > $1/$2.java
duke@0 36 class $2 {
duke@0 37 public static void main(String[] args) {
duke@0 38 System.out.println("Inside main method...");
duke@0 39 }
duke@0 40 }
duke@0 41 EOF
duke@0 42 }
duke@0 43
duke@0 44 createManagementConfigFile() {
duke@0 45 cat << EOF > $1
duke@0 46 # management.properties
duke@0 47 com.sun.management.jmxremote.authenticate=false
duke@0 48 com.sun.management.jmxremote.ssl.config.file=$2
duke@0 49 EOF
duke@0 50 }
duke@0 51
duke@0 52 createSSLConfigFile() {
duke@0 53 if [ -f "$1" ] ; then
duke@0 54 rm -f $1 || echo WARNING: $1 already exists - unable to remove old copy
duke@0 55 fi
duke@0 56 cat << EOF > $1
duke@0 57 javax.net.ssl.keyStore=$2
duke@0 58 javax.net.ssl.keyStorePassword=password
duke@0 59 EOF
duke@0 60 }
duke@0 61
duke@0 62 # Check we are run from jtreg
duke@0 63 if [ -z "${TESTCLASSES}" ]; then
duke@0 64 echo "Test is designed to be run from jtreg only"
duke@0 65 exit 0
duke@0 66 fi
duke@0 67
duke@0 68 # Test not suitable for Windows as chmod may not be able to
duke@0 69 # security the password file.
duke@0 70
duke@0 71 os=`uname -s`
duke@0 72 if [ "$os" != "Linux" -a "$os" != "SunOS" ]; then
duke@0 73 echo "Test not designed to run on this operating system, skipping..."
duke@0 74 exit 0
duke@0 75 fi
duke@0 76
duke@0 77 # Create management and SSL configuration files
duke@0 78
duke@0 79 LIBDIR=${TESTCLASSES}/lib
duke@0 80 MGMT=${LIBDIR}/management.properties
duke@0 81 SSL=${LIBDIR}/jmxremote.ssl.config
duke@0 82 rm -f ${MGMT}
duke@0 83 rm -f ${SSL}
duke@0 84 mkdir ${LIBDIR} 2>&1
duke@0 85 createJavaFile ${TESTCLASSES} Dummy
duke@0 86 createManagementConfigFile ${MGMT} ${SSL}
duke@0 87 createSSLConfigFile ${SSL} ${TESTSRC}/ssl/keystore
duke@0 88
duke@0 89 # Compile test
duke@0 90
duke@0 91 ${TESTJAVA}/bin/javac -d ${TESTCLASSES} ${TESTCLASSES}/Dummy.java
duke@0 92
duke@0 93 JAVA=${TESTJAVA}/bin/java
duke@0 94 CLASSPATH=${TESTCLASSES}
duke@0 95 export CLASSPATH
duke@0 96
duke@0 97 failures=0
duke@0 98
duke@0 99 mp=-Dcom.sun.management.config.file=${MGMT}
duke@0 100 pp=-Dcom.sun.management.jmxremote.port=4999
duke@0 101
duke@0 102 go() {
duke@0 103 echo ''
chegar@6252 104 sh -xc "$JAVA ${TESTVMOPTS} $1 $2 $3 $4 $5 $6 $7 $8" 2>&1
duke@0 105 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
duke@0 106 }
duke@0 107
duke@0 108 # Test 1 - SSL config file is secure - VM should start
duke@0 109 chmod 700 ${SSL}
chegar@6252 110 sh -xc "$JAVA ${TESTVMOPTS} $mp $pp Dummy" 2>&1
duke@0 111 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
duke@0 112
duke@0 113 # Test 2 - SSL config file is not secure - VM should fail to start
duke@0 114 chmod o+rx ${SSL}
chegar@6252 115 sh -xc "$JAVA ${TESTVMOPTS} $mp $pp Dummy" 2>&1
duke@0 116 if [ $? = 0 ]; then failures=`expr $failures + 1`; fi
duke@0 117
duke@0 118 # Reset the file permissions on the generated SSL config file
duke@0 119 chmod 777 ${SSL}
duke@0 120
duke@0 121 #
duke@0 122 # Results
duke@0 123 #
duke@0 124 echo ''
duke@0 125 if [ $failures -gt 0 ];
duke@0 126 then echo "$failures test(s) failed";
duke@0 127 else echo "All test(s) passed"; fi
duke@0 128 exit $failures