Skip to content

Commit 7cd5cb2

Browse files
myankelevwangweij
authored andcommitted
8349532: Refactor ./util/Pem/encoding.sh to run in java
Reviewed-by: weijun
1 parent 86cec4e commit 7cd5cb2

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

test/jdk/sun/security/util/Pem/PemEncoding.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 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
@@ -21,14 +21,49 @@
2121
* questions.
2222
*/
2323

24+
/*
25+
* @test
26+
* @bug 8158633
27+
* @summary BASE64 encoded cert not correctly parsed with UTF-16
28+
* @library /test/lib
29+
*/
30+
31+
import jdk.test.lib.process.ProcessTools;
32+
2433
import java.io.FileInputStream;
34+
import java.nio.charset.Charset;
35+
import java.nio.file.Path;
2536
import java.security.cert.CertificateFactory;
2637

2738
public class PemEncoding {
2839
public static void main(String[] args) throws Exception {
29-
try (FileInputStream fis = new FileInputStream(args[0])) {
30-
CertificateFactory cf = CertificateFactory.getInstance("X.509");
31-
System.out.println(cf.generateCertificate(fis));
40+
41+
final var certPath = Path.of(System.getProperty("test.src", "."))
42+
.getParent()
43+
.resolve("HostnameChecker")
44+
.resolve("cert5.crt")
45+
.toString();
46+
47+
final var testCommand = new String[]{"-Dfile.encoding=UTF-16",
48+
PemEncoding.PemEncodingTest.class.getName(),
49+
certPath};
50+
51+
final var result = ProcessTools.executeTestJava(testCommand);
52+
result.shouldHaveExitValue(0);
53+
54+
}
55+
56+
static class PemEncodingTest {
57+
public static void main(String[] args) throws Exception {
58+
59+
try (FileInputStream fis = new FileInputStream(args[0])) {
60+
CertificateFactory cf = CertificateFactory.getInstance("X.509");
61+
System.out.println(cf.generateCertificate(fis));
62+
}
63+
64+
if (!"UTF-16".equals(Charset.defaultCharset().displayName())) {
65+
throw new RuntimeException("File encoding is not UTF-16");
66+
}
3267
}
3368
}
3469
}

test/jdk/sun/security/util/Pem/encoding.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)