test/jdk/sun/net/www/protocol/http/NoNTLM.java
changeset 55522 b2cbe2f674f0
parent 54314 46cf212cdcca
--- a/test/jdk/sun/net/www/protocol/http/NoNTLM.java	Fri Jun 28 17:10:22 2019 +0300
+++ b/test/jdk/sun/net/www/protocol/http/NoNTLM.java	Fri Jun 28 15:58:10 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
  * @modules java.base/sun.net.www
  *          java.base/sun.net.www.protocol.http:open
  * @run main/othervm NoNTLM
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true NoNTLM
  */
 
 import java.io.IOException;
@@ -155,8 +156,8 @@
         System.out.println("====================================");
         System.out.println("Expect client to choose: " + expected);
         System.out.println(reply);
-
-        try (ServerSocket ss = new ServerSocket(0)) {
+        InetAddress loopback = InetAddress.getLoopbackAddress();
+        try (ServerSocket ss = new ServerSocket(0, 0, loopback)) {
             Client.start(ss.getLocalPort());
 
             // client ---- GET ---> server
@@ -198,7 +199,8 @@
         System.out.println("Expect client to fail with 401 Unauthorized");
         System.out.println(reply);
 
-        try (ServerSocket ss = new ServerSocket(0)) {
+        InetAddress loopback = InetAddress.getLoopbackAddress();
+        try (ServerSocket ss = new ServerSocket(0, 0, loopback)) {
             Client client = new Client(ss.getLocalPort());
             Thread thr = new Thread(client);
             thr.start();
@@ -225,13 +227,14 @@
     }
 
     public static void main(String[] args) throws Exception {
+        boolean ntlmSupported = false;
         try {
             Class<?> ntlmProxyClass = Class.forName("sun.net.www.protocol.http.NTLMAuthenticationProxy", true, NoNTLM.class.getClassLoader());
             Field ntlmSupportedField = ntlmProxyClass.getDeclaredField("supported");
             ntlmSupportedField.setAccessible(true);
             if (ntlmSupportedField.getBoolean(null)) {
-                System.out.println("NTLM is supported. Nothing to do. Exiting.");
-                return;
+                System.out.println("NTLM is supported.");
+                ntlmSupported = true;
             }
         } catch (ClassNotFoundException okay) { }
 
@@ -247,15 +250,26 @@
         test("Basic");
         test("Digest");
         test("Basic", "Digest");
-        test("Basic", "NTLM");
+
+        if (ntlmSupported) {
+            System.out.println("====================================");
+            System.out.println("NTLM is supported: client would select NTLM: skipping `test(\"Basic\", \"NTLM\")`..");
+        } else {
+            test("Basic", "NTLM");
+        }
+
         test("Digest", "NTLM");
         test("Basic", "Digest", "NTLM");
 
-        // test NTLM only, this should fail with "401 Unauthorized"
-        testNTLM();
+        if (ntlmSupported) {
+            System.out.println("====================================");
+            System.out.println("NTLM is supported: client would select NTLM: skipping `testNTLM()`..");
+        } else {
+            // test NTLM only, this should fail with "401 Unauthorized"
+            testNTLM();
+        }
 
         System.out.println();
         System.out.println("TEST PASSED");
     }
 }
-