8156471: test/sun/security/krb5/auto/TestHosts should not be modified in-place
Reviewed-by: xuelei
--- a/jdk/test/sun/security/krb5/auto/KDC.java Fri Jun 17 09:46:36 2016 +0800
+++ b/jdk/test/sun/security/krb5/auto/KDC.java Fri Jun 17 10:53:13 2016 +0800
@@ -219,8 +219,10 @@
};
static {
- String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts";
- System.setProperty("jdk.net.hosts.file", hostsFileName);
+ if (System.getProperty("jdk.net.hosts.file") == null) {
+ String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts";
+ System.setProperty("jdk.net.hosts.file", hostsFileName);
+ }
}
/**
--- a/jdk/test/sun/security/krb5/auto/NoAddresses.java Fri Jun 17 09:46:36 2016 +0800
+++ b/jdk/test/sun/security/krb5/auto/NoAddresses.java Fri Jun 17 10:53:13 2016 +0800
@@ -25,9 +25,9 @@
* @test
* @bug 7032354
* @run main/othervm NoAddresses setup
- * @run main/othervm NoAddresses 1
- * @run main/othervm NoAddresses 2
- * @run main/othervm/fail NoAddresses 3
+ * @run main/othervm -Djdk.net.hosts.file=TestHosts NoAddresses 1
+ * @run main/othervm -Djdk.net.hosts.file=TestHosts NoAddresses 2
+ * @run main/othervm/fail -Djdk.net.hosts.file=TestHosts NoAddresses 3
* @summary no-addresses should not be used on acceptor side
*/
@@ -38,6 +38,7 @@
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.BufferedWriter;
+import java.nio.file.*;
public class NoAddresses {
@@ -49,9 +50,10 @@
InetAddress localHost = InetAddress.getLocalHost();
String localHostName = localHost.getHostName();
String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts";
+ String hostsFileNameLocal = "TestHosts";
String loopBackAddress = "127.0.0.1";
- System.setProperty("jdk.net.hosts.file", hostsFileName);
- addMappingToHostsFile(localHostName, loopBackAddress, hostsFileName, true);
+ Files.copy(Paths.get(hostsFileName), Paths.get(hostsFileNameLocal));
+ addMappingToHostsFile(localHostName, loopBackAddress, hostsFileNameLocal, true);
} else {
OneKDC kdc = new OneKDC(null);
kdc.writeJAASConf();