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
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
3334import java .io .IOException ;
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 /</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 }
0 commit comments