Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/rmi/transport/checkFQDN/CheckFQDN.java
41154 views
1
/*
2
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 4115683
26
* @summary Endpoint hostnames should always be fully qualified or
27
* should be an ip address. When references to remote
28
* objects are passed outside of the local domain their
29
* endpoints may contain hostnames that are not fully
30
* qualified. Hence remote clients won't be able to contact
31
* the referenced remote obect.
32
*
33
* @author Laird Dornin
34
*
35
* @library ../../testlibrary
36
* @modules java.rmi/sun.rmi.registry
37
* java.rmi/sun.rmi.server
38
* java.rmi/sun.rmi.transport
39
* java.rmi/sun.rmi.transport.tcp
40
* @build TestLibrary CheckFQDNClient CheckFQDN_Stub TellServerName
41
* @run main/othervm/timeout=120 CheckFQDN
42
*/
43
44
/**
45
* Get the hostname used by rmi using different rmi properities:
46
*
47
* if set java.rmi.server.hostname, hostname should equal this
48
* property.
49
*
50
* if set java.rmi.server.useLocalHostname, hostname must contain a '.'
51
*
52
* if set no properties hostname should be an ipaddress.
53
*
54
* if set java.rmi.server.hostname, hostname should equal this
55
* property even if set java.rmi.server.useLocalHostname is true.
56
*
57
*/
58
59
import java.rmi.*;
60
import java.rmi.registry.*;
61
import java.rmi.server.*;
62
import java.io.*;
63
64
/**
65
* Export a remote object through which the exec'ed client vm can
66
* inform the main test what its host name is.
67
*/
68
public class CheckFQDN extends UnicastRemoteObject
69
implements TellServerName {
70
public static int REGISTRY_PORT =-1;
71
static String propertyBeingTested = null;
72
static String propertyBeingTestedValue = null;
73
74
public static void main(String args[]) {
75
76
Object dummy = new Object();
77
CheckFQDN checkFQDN = null;
78
try {
79
checkFQDN = new CheckFQDN();
80
81
System.err.println
82
("\nRegression test for bug/rfe 4115683\n");
83
84
Registry registry = TestLibrary.createRegistryOnEphemeralPort();
85
REGISTRY_PORT = TestLibrary.getRegistryPort(registry);
86
registry.bind("CheckFQDN", checkFQDN);
87
88
/* test the host name scheme in different environments.*/
89
testProperty("java.rmi.server.useLocalHostname", "true", "");
90
testProperty("java.rmi.server.hostname", "thisIsJustAnRMITest", "");
91
testProperty("java.rmi.server.hostname", "thisIsJustAnRMITest",
92
" -Djava.rmi.server.useLocalHostname=true ");
93
testProperty("", "", "");
94
95
} catch (Exception e) {
96
TestLibrary.bomb(e);
97
} finally {
98
if (checkFQDN != null) {
99
TestLibrary.unexport(checkFQDN);
100
}
101
}
102
System.err.println("\nTest for bug/ref 4115683 passed.\n");
103
}
104
105
/**
106
* Spawn a vm and feed it a property which sets the client's rmi
107
* hostname.
108
*/
109
public static void testProperty(String property,
110
String propertyValue,
111
String extraProp)
112
{
113
JavaVM jvm = null;
114
try {
115
String propOption = "";
116
String equal = "";
117
if (!property.equals("")) {
118
propOption = " -D";
119
equal = "=";
120
}
121
122
// create a client to tell checkFQDN what its rmi name is.
123
jvm = new JavaVM("CheckFQDNClient",
124
propOption + property +
125
equal +
126
propertyValue + extraProp +
127
" --add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED" +
128
" --add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED" +
129
" --add-exports=java.rmi/sun.rmi.transport=ALL-UNNAMED" +
130
" --add-exports=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED" +
131
" -Drmi.registry.port=" +
132
REGISTRY_PORT,
133
"");
134
135
propertyBeingTested=property;
136
propertyBeingTestedValue=propertyValue;
137
138
if (jvm.execute() != 0) {
139
TestLibrary.bomb("Test failed, error in client.");
140
}
141
142
} catch (Exception e) {
143
TestLibrary.bomb(e);
144
} finally {
145
if (jvm != null) {
146
jvm.destroy();
147
}
148
}
149
}
150
151
CheckFQDN() throws RemoteException { }
152
153
/**
154
* Remote method to allow client vm to tell the main test what its
155
* host name is .
156
*/
157
public void tellServerName(String serverName)
158
throws RemoteException {
159
160
if (propertyBeingTested.equals("java.rmi.server.hostname")) {
161
if ( !propertyBeingTestedValue.equals(serverName)) {
162
TestLibrary.bomb(propertyBeingTested +
163
":\n Client rmi server name does " +
164
"not equal the one specified " +
165
"by java.rmi.server.hostname: " +
166
serverName +" != " +
167
propertyBeingTestedValue);
168
}
169
170
/** use local host name, must contain a '.' */
171
} else if (propertyBeingTested.equals
172
("java.rmi.server.useLocalHostname")) {
173
if (serverName.indexOf('.') < 0) {
174
TestLibrary.bomb(propertyBeingTested +
175
":\nThe client servername contains no '.'");
176
}
177
} else {
178
// no propety set, must be ip address
179
if ((serverName.indexOf('.') < 0) ||
180
(!Character.isDigit(serverName.charAt(0)))) {
181
TestLibrary.bomb("Default name scheme:\n"+
182
" The client servername contains no '.'"+
183
"or is not an ip address");
184
}
185
}
186
System.err.println("Servername used: " + serverName);
187
}
188
}
189
190