Path: blob/master/test/jdk/javax/imageio/spi/AppletContextTest/BadPluginConfigurationTest.sh
41154 views
#!/bin/ksh -p1# Copyright (c) 2005, 2020, 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`88MKTEMP="mktemp"89case "$OS" in90AIX )91FILESEP="/"92PATHSEP=":"93TMP=`cd /tmp; pwd -P`9495type ${MKTEMP} > /dev/null 2>&19697if ! [ $? -ne 0 ] ; then98MKTEMP="/opt/freeware/bin/mktemp"99fi100if ! [ -e ${MKTEMP} ] ; then101pass "Test skipped because no mktemp found on this machine"102fi103;;104105Darwin | Linux )106FILESEP="/"107PATHSEP=":"108TMP=`cd /tmp; pwd -P`109;;110111Windows* )112FILESEP="\\"113PATHSEP=";"114TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`115;;116117CYGWIN* )118FILESEP="/"119PATHSEP=";"120TMP="/tmp"121;;122123# catch all other OSs124* )125echo "Unrecognized system! $OS"126fail "Unrecognized system! $OS"127;;128esac129130# Want this test to run standalone as well as in the harness, so do the131# following to copy the test's directory into the harness's scratch directory132# and set all appropriate variables:133134if [ -z "${TESTJAVA}" ] ; then135# TESTJAVA is not set, so the test is running stand-alone.136# TESTJAVA holds the path to the root directory of the build of the JDK137# to be tested. That is, any java files run explicitly in this shell138# should use TESTJAVA in the path to the java interpreter.139# So, we'll set this to the JDK spec'd on the command line. If none140# is given on the command line, tell the user that and use a cheesy141# default.142# THIS IS THE JDK BEING TESTED.143if [ -n "$1" ] ;144then TESTJAVA=$1145else fail "no JDK specified on command line!"146fi147TESTSRC=.148TESTCLASSES=.149STANDALONE=1;150fi151echo "JDK under test is: $TESTJAVA"152153#Deal with .class files:154if [ -n "${STANDALONE}" ] ;155then156#if standalone, remind user to cd to dir. containing test before running it157echo "Just a reminder: cd to the dir containing this test when running it"158# then compile all .java files (if there are any) into .class files159if [ -a *.java ] ;160then echo "Reminder, this test should be in its own directory with all"161echo "supporting files it needs in the directory with it."162${COMPILEJAVA}/bin/javac ./*.java ;163fi164# else in harness so copy all the class files from where jtreg put them165# over to the scratch directory this test is running in.166else cp ${TESTCLASSES}/*.class . ;167fi168169#if in test harness, then copy the entire directory that the test is in over170# to the scratch directory. This catches any support files needed by the test.171if [ -z "${STANDALONE}" ] ;172then cp ${TESTSRC}/*.java .173fi174175#Just before executing anything, make sure it has executable permission!176chmod 777 ./*177178############### YOUR TEST CODE HERE!!!!!!! #############179180#All files required for the test should be in the same directory with181# this file. If converting a standalone test to run with the harness,182# as long as all files are in the same directory and it returns 0 for183# pass, you should be able to cut and paste it into here and it will184# run with the test harness.185186# This is an example of running something -- test187# The stuff below catches the exit status of test then passes or fails188# this shell test as appropriate ( 0 status is considered a pass here )189190echo191echo ------ PREPARE TEST PLUGIN ---------192193# note that we can not use some subdirectory of the194# scratch dir as the plugin dst dir because the test195# app have file read permission for all subdirs of the196# scratch dir197198PLUGINDST_DIR=$(${MKTEMP} -d ${TMP}/iio_test.XXXXXXXX)199echo "Created PLUGINDST_DIR as ${PLUGINDST_DIR}"200201TEST_PLUGIN=dummy.jar202203# remove old service declaration204if [ -d META-INF ] ; then205rm -rf META-INF206fi207208# generate the service declaration209if [ ! -d META_INF ] ; then210mkdir META-INF211mkdir META-INF/services212fi213214# add wrong record to the service configuration215echo "BadReaderPluginSpi" > META-INF/services/javax.imageio.spi.ImageReaderSpi216217echo "DummyReaderPluginSpi" >> META-INF/services/javax.imageio.spi.ImageReaderSpi218219220${TESTJAVA}/bin/jar -cvf ${TEST_PLUGIN} DummyReaderPluginSpi*.class META-INF/services/javax.imageio.spi.ImageReaderSpi221222echo ----- TEST PLUGIN IS READY --------223echo224echo ----- INSTALL PLUGIN --------225echo "Install test plugin to ${PLUGINDST_DIR}"226if [ -f ${PLUGINDST_DIR}/${TEST_PLUGIN} ] ; then227echo "Remove old plugin..."228rm -f ${PLUGINDST_DIR}/${TEST_PLUGIN}229fi230mv -f ${TEST_PLUGIN} ${PLUGINDST_DIR}231if [ -f ${PLUGINDST_DIR}/${TEST_PLUGIN} ] ; then232echo Test plugin is installed.233else234fail "Unable to install test plugin to $PLUGINDST_DIR"235fi236echo ----- PLUGIN IS INSTALLED ------237echo238echo ----- CLEAN PLUGIN TEMPORARY FILES -----239rm -rf DummyReaderPluginSpi*.class META-INF240echo ----- CLEANING IS COMPLETE -------241echo242243244case "$OS" in245CYGWIN* )246TEST_CODEBASE=$(cygpath -m ${PWD})247TEST_PLUGIN_JAR=$(cygpath -m ${PLUGINDST_DIR}${FILESEP}${TEST_PLUGIN})248;;249250# catch all other OSs251* )252TEST_CODEBASE=${PWD}253TEST_PLUGIN_JAR=${PLUGINDST_DIR}${FILESEP}${TEST_PLUGIN}254;;255esac256257258# Update policy file to grant read permission259echo "grant codeBase \"file:${TEST_CODEBASE}\" {" > classpath.policy260echo " permission java.io.FilePermission \"${TEST_PLUGIN_JAR}\", \"read\";" >> classpath.policy261echo " permission java.util.PropertyPermission \"test.5076692.property\", \"read\";" >> classpath.policy262echo "};" >> classpath.policy263echo "grant codeBase \"file:${TEST_PLUGIN_JAR}\" {" >> classpath.policy264echo " permission java.util.PropertyPermission \"test.5076692.property\", \"read\";" >> classpath.policy265echo "};" >> classpath.policy266267echo ---------------------268echo --- Applet policy ---269echo ---------------------270cat classpath.policy271echo ---------------------272echo273274echo -------------------------------275echo --- Applet Classpath Test ---276echo -------------------------------277#278# please note that we need to use "==" in setup of the java.security.policy279# property in order to overwrite policies defined in the user policy file280# For more details see:281# http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html)282#283284${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ".${PATHSEP}${TEST_PLUGIN_JAR}" \285-Djava.security.policy==classpath.policy \286-Djava.security.manager IIOPluginTest287288status=$?289290if [ $status -eq "0" ] ; then291pass ""292else293fail "Test failed due to test plugin was not found."294fi295296297298