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