Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/imageio/spi/AppletContextTest/BadPluginConfigurationTest.sh
38853 views
#!/bin/ksh -p1# Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.2# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3#4# This code is free software; you can redistribute it and/or modify it5# under the terms of the GNU General Public License version 2 only, as6# published by the Free Software Foundation.7#8# This code is distributed in the hope that it will be useful, but WITHOUT9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11# version 2 for more details (a copy is included in the LICENSE file that12# accompanied this code).13#14# You should have received a copy of the GNU General Public License version15# 2 along with this work; if not, write to the Free Software Foundation,16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17#18# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19# or visit www.oracle.com if you need additional information or have any20# questions.21#22# @test23#24# @bug 6342404 7078379 8167503 818335125#26# @summary Test verifies that incorrectly configured ImageIO plugin spi27# does not affect registration of other ImageIO plugin in the28# applet context.29#30#31# @compile IIOPluginTest.java32# @compile DummyReaderPluginSpi.java33# @run shell BadPluginConfigurationTest.sh3435# There are several resources which need to be present before many36# shell scripts can run. Following are examples of how to check for37# many common ones.38#39# Note that the shell used is the Korn Shell, KSH40#41# Also note, it is recommended that make files NOT be used. Rather,42# put the individual commands directly into this file. That way,43# it is possible to use command line arguments and other shell tech-44# niques to find the compiler, etc on different systems. For example,45# a different path could be used depending on whether this were a46# Solaris or Win32 machine, which is more difficult (if even possible)47# in a make file.484950# Beginning of subroutines:51status=15253#Call this from anywhere to fail the test with an error message54# usage: fail "reason why the test failed"55fail()56{ echo "The test failed :-("57echo "$*" 1>&258echo "exit status was $status"59clean60exit $status61} #end of fail()6263#Call this from anywhere to pass the test with a message64# usage: pass "reason why the test passed if applicable"65pass()66{ echo "The test passed!!!"67echo "$*" 1>&268clean69exit 070} #end of pass()7172#Clean up the test_ext directory (PLUGINDST_DIR) before leaving73clean()74{75echo "Removing PLUGINDST_DIR ${PLUGINDST_DIR}"76if [ -n "${PLUGINDST_DIR}" -a -d "${PLUGINDST_DIR}" ] ; then77rm -rf "${PLUGINDST_DIR}"78fi79}8081# end of subroutines828384# The beginning of the script proper8586# Checking for proper OS87OS=`uname -s`88case "$OS" in89SunOS | Linux | Darwin )90FILESEP="/"91PATHSEP=":"92TMP=`cd /tmp; pwd -P`93;;9495Windows* )96FILESEP="\\"97PATHSEP=";"98TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`99;;100101CYGWIN* )102FILESEP="/"103PATHSEP=";"104TMP="/tmp"105;;106107# catch all other OSs108* )109echo "Unrecognized system! $OS"110fail "Unrecognized system! $OS"111;;112esac113114# Want this test to run standalone as well as in the harness, so do the115# following to copy the test's directory into the harness's scratch directory116# and set all appropriate variables:117118if [ -z "${TESTJAVA}" ] ; then119# TESTJAVA is not set, so the test is running stand-alone.120# TESTJAVA holds the path to the root directory of the build of the JDK121# to be tested. That is, any java files run explicitly in this shell122# should use TESTJAVA in the path to the java interpreter.123# So, we'll set this to the JDK spec'd on the command line. If none124# is given on the command line, tell the user that and use a cheesy125# default.126# THIS IS THE JDK BEING TESTED.127if [ -n "$1" ] ;128then TESTJAVA=$1129else fail "no JDK specified on command line!"130fi131TESTSRC=.132TESTCLASSES=.133STANDALONE=1;134fi135echo "JDK under test is: $TESTJAVA"136137#Deal with .class files:138if [ -n "${STANDALONE}" ] ;139then140#if standalone, remind user to cd to dir. containing test before running it141echo "Just a reminder: cd to the dir containing this test when running it"142# then compile all .java files (if there are any) into .class files143if [ -a *.java ] ;144then echo "Reminder, this test should be in its own directory with all"145echo "supporting files it needs in the directory with it."146${COMPILEJAVA}/bin/javac ./*.java ;147fi148# else in harness so copy all the class files from where jtreg put them149# over to the scratch directory this test is running in.150else cp ${TESTCLASSES}/*.class . ;151fi152153#if in test harness, then copy the entire directory that the test is in over154# to the scratch directory. This catches any support files needed by the test.155if [ -z "${STANDALONE}" ] ;156then cp ${TESTSRC}/*.java .157fi158159#Just before executing anything, make sure it has executable permission!160chmod 777 ./*161162############### YOUR TEST CODE HERE!!!!!!! #############163164#All files required for the test should be in the same directory with165# this file. If converting a standalone test to run with the harness,166# as long as all files are in the same directory and it returns 0 for167# pass, you should be able to cut and paste it into here and it will168# run with the test harness.169170# This is an example of running something -- test171# The stuff below catches the exit status of test then passes or fails172# this shell test as appropriate ( 0 status is considered a pass here )173174echo175echo ------ PREPARE TEST PLUGIN ---------176177# note that we can not use some subdirectory of the178# scratch dir as the plugin dst dir because the test179# app have file read permission for all subdirs of the180# scratch dir181182PLUGINDST_DIR=$(mktemp -d ${TMP}/iio_test.XXXXXXXX)183echo "Created PLUGINDST_DIR as ${PLUGINDST_DIR}"184185TEST_PLUGIN=dummy.jar186187# remove old service declaration188if [ -d META-INF ] ; then189rm -rf META-INF190fi191192# generate the service declaration193if [ ! -d META_INF ] ; then194mkdir META-INF195mkdir META-INF/services196fi197198# add wrong record to the service configuration199echo "BadReaderPluginSpi" > META-INF/services/javax.imageio.spi.ImageReaderSpi200201echo "DummyReaderPluginSpi" >> META-INF/services/javax.imageio.spi.ImageReaderSpi202203204${TESTJAVA}/bin/jar -cvf ${TEST_PLUGIN} DummyReaderPluginSpi*.class META-INF/services/javax.imageio.spi.ImageReaderSpi205206echo ----- TEST PLUGIN IS READY --------207echo208echo ----- INSTALL PLUGIN --------209echo "Install test plugin to ${PLUGINDST_DIR}"210if [ -f ${PLUGINDST_DIR}/${TEST_PLUGIN} ] ; then211echo "Remove old plugin..."212rm -f ${PLUGINDST_DIR}/${TEST_PLUGIN}213fi214mv -f ${TEST_PLUGIN} ${PLUGINDST_DIR}215if [ -f ${PLUGINDST_DIR}/${TEST_PLUGIN} ] ; then216echo Test plugin is installed.217else218fail "Unable to install test plugin to $PLUGINDST_DIR"219fi220echo ----- PLUGIN IS INSTALLED ------221echo222echo ----- CLEAN PLUGIN TEMPORARY FILES -----223rm -rf DummyReaderPluginSpi*.class META-INF224echo ----- CLEANING IS COMPLETE -------225echo226227228case "$OS" in229CYGWIN* )230TEST_CODEBASE=$(cygpath -m ${PWD})231TEST_PLUGIN_JAR=$(cygpath -m ${PLUGINDST_DIR}${FILESEP}${TEST_PLUGIN})232;;233234# catch all other OSs235* )236TEST_CODEBASE=${PWD}237TEST_PLUGIN_JAR=${PLUGINDST_DIR}${FILESEP}${TEST_PLUGIN}238;;239esac240241242# Update policy file to grant read permission243echo "grant codeBase \"file:${TEST_CODEBASE}\" {" > classpath.policy244echo " permission java.io.FilePermission \"${TEST_PLUGIN_JAR}\", \"read\";" >> classpath.policy245echo " permission java.util.PropertyPermission \"test.5076692.property\", \"read\";" >> classpath.policy246echo "};" >> classpath.policy247echo "grant codeBase \"file:${TEST_PLUGIN_JAR}\" {" >> classpath.policy248echo " permission java.util.PropertyPermission \"test.5076692.property\", \"read\";" >> classpath.policy249echo "};" >> classpath.policy250251echo ---------------------252echo --- Applet policy ---253echo ---------------------254cat classpath.policy255echo ---------------------256echo257258echo -------------------------------259echo --- Applet Classpath Test ---260echo -------------------------------261#262# please note that we need to use "==" in setup of the java.security.policy263# property in order to overwrite policies defined in the user policy file264# For more details see:265# http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html)266#267268${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ".${PATHSEP}${TEST_PLUGIN_JAR}" \269-Djava.security.policy==classpath.policy \270-Djava.security.manager IIOPluginTest271272status=$?273274if [ $status -eq "0" ] ; then275pass ""276else277fail "Test failed due to test plugin was not found."278fi279280281282