jdk/test/sun/management/jmxremote/bootstrap/PasswordFilePermissionTest.sh
author alanb
Fri, 11 Jan 2013 20:19:55 +0000
changeset 15254 3997a6f357cb
parent 14786 a9f61e0cbe61
permissions -rw-r--r--
8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools Reviewed-by: chegar
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) 2004, 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 5008047
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
# @summary Check password 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 PasswordFilePermissionTest.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
createConfigFile() {
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.ssl=false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
com.sun.management.jmxremote.password.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
createPasswordFile() {
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
# jmxremote.password
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
EOF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
}
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
# Test not suitable for Windows as chmod may not be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
# security the password file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
os=`uname -s`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
if [ "$os" != "Linux" -a "$os" != "SunOS" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    echo "Test not designed to run on this operating system, skipping..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    exit 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
# Create configuration file and dummy password file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
LIBDIR=${TESTCLASSES}/lib
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
CONFIG=${LIBDIR}/management.properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
PASSWD=${LIBDIR}/jmxremote.password
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
rm -f ${CONFIG}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
rm -f ${PASSWD}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
mkdir ${LIBDIR} 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
createJavaFile ${TESTCLASSES} Null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
createConfigFile ${CONFIG} ${PASSWD}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
createPasswordFile ${PASSWD}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
# Compile test 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
15254
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 14786
diff changeset
    93
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${TESTCLASSES} ${TESTCLASSES}/Null.java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
JAVA=${TESTJAVA}/bin/java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
CLASSPATH=${TESTCLASSES}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
export CLASSPATH
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
failures=0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
mp=-Dcom.sun.management.config.file=${CONFIG}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
pp=-Dcom.sun.management.jmxremote.port=4888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
go() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    echo ''
14786
a9f61e0cbe61 8003890: corelibs test scripts should pass TESTVMOPTS
chegar
parents: 5506
diff changeset
   107
    sh -xc "$JAVA ${TESTVMOPTS} $1 $2 $3 $4 $5 $6 $7 $8" 2>&1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
# Test 1 - password file is secure - VM should start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
chmod 700 ${PASSWD}
14786
a9f61e0cbe61 8003890: corelibs test scripts should pass TESTVMOPTS
chegar
parents: 5506
diff changeset
   113
sh -xc "$JAVA ${TESTVMOPTS} $mp $pp Null" 2>&1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
# Test 2 - password file is not secure - VM should fail to start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
chmod o+rx ${PASSWD}
14786
a9f61e0cbe61 8003890: corelibs test scripts should pass TESTVMOPTS
chegar
parents: 5506
diff changeset
   118
sh -xc "$JAVA ${TESTVMOPTS} $mp $pp Null" 2>&1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
if [ $? = 0 ]; then failures=`expr $failures + 1`; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
# Reset the file permissions on the generated password file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
chmod 777 ${PASSWD}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
# Results
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
echo ''
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
if [ $failures -gt 0 ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  then echo "$failures test(s) failed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  else echo "All test(s) passed"; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
exit $failures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134