Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/SSLLogger/LoggingFormatConsistency.java
41152 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 8211227
27
* @library /test/lib /javax/net/ssl/templates ../../
28
* @summary Tests for consistency in logging format of TLS Versions
29
* @run main/othervm LoggingFormatConsistency
30
*/
31
32
/*
33
* This test runs in another process so we can monitor the debug
34
* results. The OutputAnalyzer must see correct debug output to return a
35
* success.
36
*/
37
38
import jdk.test.lib.process.ProcessTools;
39
import jdk.test.lib.security.SecurityUtils;
40
41
import java.net.InetAddress;
42
43
public class LoggingFormatConsistency extends SSLSocketTemplate {
44
45
LoggingFormatConsistency () {
46
serverAddress = InetAddress.getLoopbackAddress();
47
SecurityUtils.removeFromDisabledTlsAlgs("TLSv1", "TLSv1.1");
48
}
49
50
public static void main(String[] args) throws Exception {
51
if (args.length != 0) {
52
// A non-empty set of arguments occurs when the "runTest" argument
53
// is passed to the test via ProcessTools::executeTestJvm.
54
//
55
// This is done because an OutputAnalyzer is unable to read
56
// the output of the current running JVM, and must therefore create
57
// a test JVM. When this case occurs, it will inherit all specified
58
// properties passed to the test JVM - debug flags, tls version, etc.
59
new LoggingFormatConsistency().run();
60
} else {
61
// We are in the test JVM that the test is being ran in.
62
var testSrc = "-Dtest.src=" + System.getProperty("test.src");
63
var javaxNetDebug = "-Djavax.net.debug=all";
64
65
var correctTlsVersionsFormat = new String[]{"TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"};
66
var incorrectTLSVersionsFormat = new String[]{"TLS10", "TLS11", "TLS12", "TLS13"};
67
68
for (var i = 0; i < correctTlsVersionsFormat.length; i++) {
69
var expectedTLSVersion = correctTlsVersionsFormat[i];
70
var incorrectTLSVersion = incorrectTLSVersionsFormat[i];
71
72
System.out.println("TESTING " + expectedTLSVersion);
73
var activeTLSProtocol = "-Djdk.tls.client.protocols=" + expectedTLSVersion;
74
var output = ProcessTools.executeTestJvm(
75
testSrc,
76
activeTLSProtocol,
77
javaxNetDebug,
78
"LoggingFormatConsistency",
79
"runTest"); // Ensuring args.length is greater than 0 when test JVM starts
80
81
output.asLines()
82
.stream()
83
.filter(line -> line.startsWith("Connecting to"))
84
.forEach(System.out::println); // prints connection info from test jvm output
85
86
if (output.getExitValue() != 0) {
87
output.asLines().forEach(System.out::println);
88
throw new RuntimeException("Test JVM process failed");
89
}
90
91
output.shouldContain(expectedTLSVersion);
92
output.shouldNotContain(incorrectTLSVersion);
93
}
94
}
95
}
96
}
97
98