mirror of
https://github.com/openjdk/jdk.git
synced 2026-06-06 18:53:37 +00:00
8384371: CngCipher and DupAlias tests fail on Windows
Reviewed-by: weijun, myankelevich
This commit is contained in:
parent
34d9e38afc
commit
15f09ceaf9
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2026, 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
|
||||
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.util.FileUtils;
|
||||
import jdk.test.lib.SecurityTools;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -57,7 +58,7 @@ public class CngCipher {
|
||||
SecurityTools.keytool("-storetype Windows-MY -genkeypair -alias "
|
||||
+ PREFIX + "m -keyalg RSA -dname CN=" + PREFIX + "m");
|
||||
// This will generate a CNG key
|
||||
ProcessBuilder pb = new ProcessBuilder("powershell", "-Command",
|
||||
ProcessBuilder pb = new ProcessBuilder(FileUtils.powerShellPath(), "-Command",
|
||||
"New-SelfSignedCertificate", "-DnsName", PREFIX + "c",
|
||||
// -KeyAlgorithm not supported on Windows Server 2012
|
||||
//"-KeyAlgorithm", "RSA",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2023, 2026, 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
|
||||
@ -21,6 +21,7 @@
|
||||
* questions.
|
||||
*/
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.util.FileUtils;
|
||||
import sun.security.tools.keytool.CertAndKeyGen;
|
||||
import sun.security.x509.X500Name;
|
||||
|
||||
@ -83,7 +84,7 @@ public class DupAlias {
|
||||
}
|
||||
|
||||
static void ps(String f) throws Exception {
|
||||
ProcessBuilder pb = new ProcessBuilder("powershell", "-Command", f);
|
||||
ProcessBuilder pb = new ProcessBuilder(FileUtils.powerShellPath(), "-Command", f);
|
||||
pb.inheritIO();
|
||||
if (pb.start().waitFor() != 0) {
|
||||
throw new RuntimeException("Failed");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2025, 2026, 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
|
||||
@ -208,7 +208,7 @@ public final class WinExecutableIconVerifier {
|
||||
|
||||
Path extractedIcon = outputDir.resolve(extractedIconFilename + ".bmp");
|
||||
|
||||
Executor.of("powershell", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Unrestricted",
|
||||
Executor.of(WindowsHelper.PowerShellPath(), "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Unrestricted",
|
||||
"-File", EXTRACT_ICON_PS1.toString(),
|
||||
"-InputExecutable", executable.toAbsolutePath().normalize().toString(),
|
||||
"-OutputIcon", extractedIcon.toAbsolutePath().normalize().toString()
|
||||
|
||||
@ -306,7 +306,7 @@ public class WindowsHelper {
|
||||
}
|
||||
|
||||
public static String getExecutableDescription(Path pathToExeFile) {
|
||||
Executor exec = Executor.of("powershell",
|
||||
Executor exec = Executor.of(PowerShellPath(),
|
||||
"-NoLogo",
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
@ -455,7 +455,7 @@ public class WindowsHelper {
|
||||
;
|
||||
|
||||
Path getPath() {
|
||||
final var str = Executor.of("powershell", "-NoLogo", "-NoProfile",
|
||||
final var str = Executor.of(PowerShellPath(), "-NoLogo", "-NoProfile",
|
||||
"-NonInteractive", "-Command",
|
||||
String.format("[Environment]::GetFolderPath('%s')", name())
|
||||
).saveFirstLineOfOutput().execute().getFirstLineOfOutput();
|
||||
@ -661,4 +661,11 @@ public class WindowsHelper {
|
||||
private static final String USER_SHELL_FOLDERS_REGKEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
|
||||
|
||||
private static final int WIN_MAX_PATH = 260;
|
||||
|
||||
public static String PowerShellPath() {
|
||||
String systemRoot = System.getenv("SystemRoot");
|
||||
String suffix = "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
||||
String fullPath = systemRoot == null ? null : systemRoot + suffix;
|
||||
return (fullPath != null && Files.exists(Path.of(fullPath))) ? fullPath : "powershell";
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package jdk.jpackage.internal.util;
|
||||
|
||||
import jdk.jpackage.test.WindowsHelper;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static jdk.jpackage.internal.util.CommandOutputControlTestUtils.isInterleave;
|
||||
import static jdk.jpackage.internal.util.function.ThrowingConsumer.toConsumer;
|
||||
@ -1004,7 +1006,7 @@ public class CommandOutputControlTest {
|
||||
commandSeparator = " && ";
|
||||
}
|
||||
case POWERSHELL -> {
|
||||
commandline.addAll(List.of("powershell", "-NoProfile", "-Command"));
|
||||
commandline.addAll(List.of(WindowsHelper.PowerShellPath(), "-NoProfile", "-Command"));
|
||||
commandSeparator = "; ";
|
||||
}
|
||||
default -> {
|
||||
@ -1176,7 +1178,7 @@ public class CommandOutputControlTest {
|
||||
// It sends packets every second.
|
||||
// To wait N seconds, it should send N+1 packets.
|
||||
// The "timeout" command works only in a console.
|
||||
return String.format("(ping -n %d localhost > nul)", sleep.seconds() + 1);
|
||||
return String.format("(%%SystemRoot%%\\System32\\ping.exe -n %d localhost > nul)", sleep.seconds() + 1);
|
||||
}
|
||||
case POWERSHELL -> {
|
||||
return "Start-Sleep -Seconds " + sleep.seconds();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2025, 2026, 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
|
||||
@ -64,6 +64,9 @@ Add-Type @type
|
||||
|
||||
Set-PSDebug -Trace 2
|
||||
|
||||
# Ensure system directories are on the PATH for the child process.
|
||||
$env:Path = "$env:SystemRoot\System32;$env:SystemRoot;$env:Path"
|
||||
|
||||
# Launch the target executable.
|
||||
# `-NoNewWindow` parameter will attach the started process to the existing console.
|
||||
$childProc = Start-Process -PassThru -NoNewWindow $Executable
|
||||
|
||||
@ -23,6 +23,8 @@
|
||||
|
||||
import static jdk.jpackage.test.HelloApp.configureAndExecute;
|
||||
|
||||
import jdk.jpackage.test.WindowsHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -108,7 +110,7 @@ public class Win8365790Test {
|
||||
|
||||
var future = CompletableFuture.runAsync(() -> {
|
||||
TKit.withState(() -> {
|
||||
configureAndExecute(0, Executor.of("powershell", "-NonInteractive", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Unrestricted")
|
||||
configureAndExecute(0, Executor.of(WindowsHelper.PowerShellPath(), "-NonInteractive", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Unrestricted")
|
||||
.addArgument("-File").addArgument(TEST_PS1)
|
||||
.addArguments("-TimeoutSeconds", Long.toString(Duration.ofSeconds(5).getSeconds()))
|
||||
.addArgument("-Executable").addArgument(cmd.appLauncherPath(launcherName))
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2026, 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
|
||||
@ -475,4 +475,11 @@ public final class FileUtils {
|
||||
{"/sbin/lsof", "-p"},
|
||||
{"/usr/local/bin/lsof", "-p"},
|
||||
};
|
||||
|
||||
public static String powerShellPath() {
|
||||
String systemRoot = System.getenv("SystemRoot");
|
||||
String suffix = "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
||||
String fullPath = systemRoot == null ? null : systemRoot + suffix;
|
||||
return (fullPath != null && Files.exists(Path.of(fullPath))) ? fullPath : "powershell";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user