Skip to content

Commit effe40a

Browse files
serhiysachkovjaikiran
authored andcommitted
8351843: change test/jdk/com/sun/net/httpserver/simpleserver/RootDirPermissionsTest.java to a manual test
Reviewed-by: dfuchs
1 parent 2fb3329 commit effe40a

File tree

3 files changed

+69
-25
lines changed

3 files changed

+69
-25
lines changed

test/jdk/TEST.groups

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ jdk_core_manual_no_input = \
625625
java/util/Vector/Bug8148174.java \
626626
com/sun/net/httpserver/simpleserver/CommandLinePortNotSpecifiedTest.java \
627627
com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePortNotSpecifiedTest.java \
628+
com/sun/net/httpserver/simpleserver/DocRootDirPermissionsWinTest.java \
628629
javax/xml/jaxp/datatype/8033980/GregorianCalAndDurSerDataUtil.java
629630

630631
jdk_security_manual_no_input = \

test/jdk/com/sun/net/httpserver/simpleserver/RootDirPermissionsTest.java renamed to test/jdk/com/sun/net/httpserver/simpleserver/DocRootDirPermissionsTest.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,10 +24,11 @@
2424
/*
2525
* @test
2626
* @summary Tests file permission checks during the creation of a `FileServerHandler`
27+
* @requires (os.family != "windows")
2728
* @library /test/lib
2829
* @build jdk.test.lib.net.URIBuilder
29-
* @run main/othervm -ea RootDirPermissionsTest true
30-
* @run main/othervm -ea RootDirPermissionsTest false
30+
* @run main/othervm -ea DocRootDirPermissionsTest true
31+
* @run main/othervm -ea DocRootDirPermissionsTest false
3132
*/
3233

3334
import java.io.IOException;
@@ -73,24 +74,28 @@
7374
* 2) reuses the test directory created in the previous run, revoking
7475
* read access.
7576
* */
76-
public class RootDirPermissionsTest {
77+
public class DocRootDirPermissionsTest {
7778

78-
static final Path CWD = Path.of(".").toAbsolutePath().normalize();
79-
static final Path TEST_DIR = CWD.resolve("RootDir");
80-
static final InetSocketAddress LOOPBACK_ADDR =
79+
private static final Path CWD = Path.of(".").toAbsolutePath().normalize();
80+
private static final Path TEST_DIR = CWD.resolve("RootDir");
81+
private static final InetSocketAddress LOOPBACK_ADDR =
8182
new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
8283

83-
static final boolean ENABLE_LOGGING = true;
84-
static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
84+
private static final boolean ENABLE_LOGGING = true;
85+
private static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
8586

86-
static boolean readPermitted;
87-
static String lastModifiedDir;
88-
static String lastModifiedFile;
87+
private static boolean readPermitted;
88+
private static String lastModifiedDir;
89+
private static String lastModifiedFile;
8990

90-
static Set<PosixFilePermission> posixPermissions;
91-
static List<AclEntry> acls;
91+
private static Set<PosixFilePermission> posixPermissions;
92+
private static List<AclEntry> acls;
9293

9394
public static void main(String[] args) throws Exception {
95+
new DocRootDirPermissionsTest().run(args);
96+
}
97+
98+
protected void run(String[] args) throws Exception{
9499
setupLogging();
95100
readPermitted = Boolean.parseBoolean(args[0]);
96101
if (readPermitted) {
@@ -107,7 +112,7 @@ public static void main(String[] args) throws Exception {
107112
}
108113
}
109114

110-
private static void revokePermissions() throws IOException {
115+
private void revokePermissions() throws IOException {
111116
if (!Files.isReadable(TEST_DIR)) {
112117
// good nothing to do:
113118
System.out.println("File is already not readable: nothing to do");
@@ -164,7 +169,7 @@ private static void revokePermissions() throws IOException {
164169
System.out.println("File is readable: " + Files.isReadable(TEST_DIR));
165170
}
166171

167-
private static void restorePermissions() throws IOException {
172+
private void restorePermissions() throws IOException {
168173
if (Files.getFileStore(TEST_DIR).supportsFileAttributeView("posix")) {
169174
if (posixPermissions != null) {
170175
System.out.println("Restoring original POSIX permissions");
@@ -181,7 +186,7 @@ private static void restorePermissions() throws IOException {
181186
}
182187
}
183188

184-
private static void setupLogging() {
189+
private void setupLogging() {
185190
if (ENABLE_LOGGING) {
186191
ConsoleHandler ch = new ConsoleHandler();
187192
LOGGER.setLevel(Level.ALL);
@@ -190,7 +195,7 @@ private static void setupLogging() {
190195
}
191196
}
192197

193-
private static void createTestDir() throws IOException {
198+
private void createTestDir() throws IOException {
194199
if (Files.exists(TEST_DIR)) {
195200
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
196201
}
@@ -200,7 +205,7 @@ private static void createTestDir() throws IOException {
200205
lastModifiedFile = getLastModified(file);
201206
}
202207

203-
private static void testDirectoryGET() throws Exception {
208+
private void testDirectoryGET() throws Exception {
204209
var expectedBody = openHTML + """
205210
<h1>Directory listing for &#x2F;</h1>
206211
<ul>
@@ -225,7 +230,7 @@ private static void testDirectoryGET() throws Exception {
225230
}
226231
}
227232

228-
private static void testFileGET() throws Exception {
233+
private void testFileGET() throws Exception {
229234
var expectedBody = "some text";
230235
var expectedLength = Integer.toString(expectedBody.getBytes(UTF_8).length);
231236
var server = SimpleFileServer.createFileServer(LOOPBACK_ADDR, TEST_DIR, OutputLevel.VERBOSE);
@@ -245,7 +250,7 @@ private static void testFileGET() throws Exception {
245250
}
246251
}
247252

248-
private static void testCreateHandler(){
253+
private void testCreateHandler(){
249254
try {
250255
SimpleFileServer.createFileServer(LOOPBACK_ADDR, TEST_DIR, OutputLevel.NONE);
251256
throw new RuntimeException("Handler creation expected to fail");
@@ -257,7 +262,7 @@ private static void testCreateHandler(){
257262
} catch (IllegalArgumentException expected) { }
258263
}
259264

260-
static final String openHTML = """
265+
private static final String openHTML = """
261266
<!DOCTYPE html>
262267
<html>
263268
<head>
@@ -266,12 +271,12 @@ private static void testCreateHandler(){
266271
<body>
267272
""";
268273

269-
static final String closeHTML = """
274+
private static final String closeHTML = """
270275
</body>
271276
</html>
272277
""";
273278

274-
static URI uri(HttpServer server, String path) {
279+
private URI uri(HttpServer server, String path) {
275280
return URIBuilder.newBuilder()
276281
.host("localhost")
277282
.port(server.getAddress().getPort())
@@ -280,7 +285,7 @@ static URI uri(HttpServer server, String path) {
280285
.buildUnchecked();
281286
}
282287

283-
static String getLastModified(Path path) throws IOException {
288+
private String getLastModified(Path path) throws IOException {
284289
return Files.getLastModifiedTime(path).toInstant().atZone(ZoneId.of("GMT"))
285290
.format(DateTimeFormatter.RFC_1123_DATE_TIME);
286291
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2025, 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+
/*
25+
* @test
26+
* @summary Tests file permission checks during the creation of a `FileServerHandler`
27+
* @requires (os.family == "windows")
28+
* @library /test/lib
29+
* @build jdk.test.lib.net.URIBuilder
30+
* @run main/manual/othervm -ea DocRootDirPermissionsWinTest true
31+
* @run main/manual/othervm -ea DocRootDirPermissionsWinTest false
32+
*/
33+
34+
public class DocRootDirPermissionsWinTest extends DocRootDirPermissionsTest{
35+
public static void main(String[] args) throws Exception {
36+
new DocRootDirPermissionsWinTest().run(args);
37+
}
38+
}

0 commit comments

Comments
 (0)