jdk/test/sun/net/InetAddress/nameservice/dns/cname.sh
changeset 45505 ca0e16b2d5d6
parent 45504 ea7475564d07
parent 45495 8f5dd0fb0a6d
child 45506 790c716da86b
equal deleted inserted replaced
45504:ea7475564d07 45505:ca0e16b2d5d6
     1 #!/bin/sh
       
     2 
       
     3 #
       
     4 # Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
       
     5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     6 #
       
     7 # This code is free software; you can redistribute it and/or modify it
       
     8 # under the terms of the GNU General Public License version 2 only, as
       
     9 # published by the Free Software Foundation.
       
    10 #
       
    11 # This code is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14 # version 2 for more details (a copy is included in the LICENSE file that
       
    15 # accompanied this code).
       
    16 #
       
    17 # You should have received a copy of the GNU General Public License version
       
    18 # 2 along with this work; if not, write to the Free Software Foundation,
       
    19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20 #
       
    21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22 # or visit www.oracle.com if you need additional information or have any
       
    23 # questions.
       
    24 #
       
    25 
       
    26 
       
    27 # @test
       
    28 # @bug 4763315
       
    29 # @modules java.naming
       
    30 # @build CanonicalName Lookup
       
    31 # @run shell/timeout=120 cname.sh
       
    32 # @summary Test DNS provider's handling of CNAME records
       
    33 
       
    34 
       
    35 # The host that we try to resolve
       
    36 
       
    37 HOST=www-proxy.us.oracle.com
       
    38 
       
    39 # fail gracefully if DNS is not configured or there
       
    40 # isn't a CNAME record.
       
    41 
       
    42 CLASSPATH=${TESTCLASSES}
       
    43 export CLASSPATH
       
    44 JAVA="${TESTJAVA}/bin/java"
       
    45 
       
    46 sh -xc "$JAVA ${TESTVMOPTS} CanonicalName $HOST" 2>&1
       
    47 if [ $? != 0 ]; then
       
    48     echo "DNS not configured or host doesn't resolve to CNAME record"
       
    49     exit 0
       
    50 fi
       
    51 
       
    52 failures=0
       
    53 
       
    54 go() {
       
    55     echo ''
       
    56     sh -xc "$JAVA ${TESTVMOPTS} $1 Lookup $2" 2>&1
       
    57     if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
       
    58 }
       
    59 
       
    60 # Tests - with & without security manager
       
    61 
       
    62 POLICY=java.policy
       
    63 echo "grant {" > ${POLICY}
       
    64 echo " permission java.net.SocketPermission \"${HOST}\", \"resolve\";" >> ${POLICY}
       
    65 echo "};" >> ${POLICY}
       
    66 
       
    67 np="-Dsun.net.spi.nameservice.provider.1=dns,sun"
       
    68 sm="-Djava.security.manager -Djava.security.policy=${POLICY}"
       
    69 
       
    70 go "" "$HOST"
       
    71 go "$sm" "$HOST"
       
    72 
       
    73 
       
    74 #
       
    75 # Results
       
    76 #
       
    77 echo ''
       
    78 if [ $failures -gt 0 ];
       
    79   then echo "$failures test(s) failed";
       
    80   else echo "All test(s) passed"; fi
       
    81 exit $failures