Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/transport/checkFQDN/CheckFQDN.java
38828 views
/*1* Copyright (c) 1998, 2013, 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*/2223/* @test24* @bug 411568325* @summary Endpoint hostnames should always be fully qualified or26* should be an ip address. When references to remote27* objects are passed outside of the local domain their28* endpoints may contain hostnames that are not fully29* qualified. Hence remote clients won't be able to contact30* the referenced remote obect.31*32* @author Laird Dornin33*34* @library ../../testlibrary35* @build TestLibrary CheckFQDNClient CheckFQDN_Stub TellServerName36* @run main/othervm/timeout=120 CheckFQDN37*/3839/**40* Get the hostname used by rmi using different rmi properities:41*42* if set java.rmi.server.hostname, hostname should equal this43* property.44*45* if set java.rmi.server.useLocalHostname, hostname must contain a '.'46*47* if set no properties hostname should be an ipaddress.48*49* if set java.rmi.server.hostname, hostname should equal this50* property even if set java.rmi.server.useLocalHostname is true.51*52*/5354import java.rmi.*;55import java.rmi.registry.*;56import java.rmi.server.*;57import java.io.*;5859/**60* Export a remote object through which the exec'ed client vm can61* inform the main test what its host name is.62*/63public class CheckFQDN extends UnicastRemoteObject64implements TellServerName {65public static int REGISTRY_PORT =-1;66static String propertyBeingTested = null;67static String propertyBeingTestedValue = null;6869public static void main(String args[]) {7071Object dummy = new Object();72CheckFQDN checkFQDN = null;73try {74checkFQDN = new CheckFQDN();7576System.err.println77("\nRegression test for bug/rfe 4115683\n");7879Registry registry = TestLibrary.createRegistryOnUnusedPort();80REGISTRY_PORT = TestLibrary.getRegistryPort(registry);81registry.bind("CheckFQDN", checkFQDN);8283/* test the host name scheme in different environments.*/84testProperty("java.rmi.server.useLocalHostname", "true", "");85testProperty("java.rmi.server.hostname", "thisIsJustAnRMITest", "");86testProperty("java.rmi.server.hostname", "thisIsJustAnRMITest",87" -Djava.rmi.server.useLocalHostname=true ");88testProperty("", "", "");8990} catch (Exception e) {91TestLibrary.bomb(e);92} finally {93if (checkFQDN != null) {94TestLibrary.unexport(checkFQDN);95}96}97System.err.println("\nTest for bug/ref 4115683 passed.\n");98}99100/**101* Spawn a vm and feed it a property which sets the client's rmi102* hostname.103*/104public static void testProperty(String property,105String propertyValue,106String extraProp)107{108try {109String propOption = "";110String equal = "";111if (!property.equals("")) {112propOption = " -D";113equal = "=";114}115116// create a client to tell checkFQDN what its rmi name is.117JavaVM jvm = new JavaVM("CheckFQDNClient",118propOption + property +119equal +120propertyValue + extraProp +121" -Drmi.registry.port=" +122REGISTRY_PORT,123"");124125propertyBeingTested=property;126propertyBeingTestedValue=propertyValue;127128if (jvm.execute() != 0) {129TestLibrary.bomb("Test failed, error in client.");130}131132} catch (Exception e) {133TestLibrary.bomb(e);134}135}136137CheckFQDN() throws RemoteException { }138139/**140* Remote method to allow client vm to tell the main test what its141* host name is .142*/143public void tellServerName(String serverName)144throws RemoteException {145146if (propertyBeingTested.equals("java.rmi.server.hostname")) {147if ( !propertyBeingTestedValue.equals(serverName)) {148TestLibrary.bomb(propertyBeingTested +149":\n Client rmi server name does " +150"not equal the one specified " +151"by java.rmi.server.hostname: " +152serverName +" != " +153propertyBeingTestedValue);154}155156/** use local host name, must contain a '.' */157} else if (propertyBeingTested.equals158("java.rmi.server.useLocalHostname")) {159if (serverName.indexOf('.') < 0) {160TestLibrary.bomb(propertyBeingTested +161":\nThe client servername contains no '.'");162}163} else {164// no propety set, must be ip address165if ((serverName.indexOf('.') < 0) ||166(!Character.isDigit(serverName.charAt(0)))) {167TestLibrary.bomb("Default name scheme:\n"+168" The client servername contains no '.'"+169"or is not an ip address");170}171}172System.err.println("Servername used: " + serverName);173}174}175176177