Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/util/ManifestDigester/FindSections.java
41152 views
1
/*
2
* Copyright (c) 2019, 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
import sun.security.util.ManifestDigester;
25
import org.testng.annotations.Test;
26
27
import static java.nio.charset.StandardCharsets.UTF_8;
28
import static org.testng.Assert.*;
29
30
31
/**
32
* @test
33
* @bug 8217375
34
* @modules java.base/sun.security.util
35
* @run testng FindSections
36
* @summary Check {@link ManifestDigester#ManifestDigester} processing
37
* individual sections and particularly identifying their names correctly.
38
* Main attributes are not covered in this test.
39
* <p>
40
* See also {@link FindSection} for the {@link ManifestDigester#findSection}
41
* method specifically.
42
*/
43
public class FindSections {
44
45
static final String DEFAULT_MANIFEST = "Manifest-Version: 1.0\r\n\r\n";
46
47
void test(String manifest, String expectedSection) {
48
ManifestDigester md = new ManifestDigester(manifest.getBytes(UTF_8));
49
if (expectedSection != null) {
50
assertNotNull(md.get(expectedSection, false));
51
} else {
52
assertNull(md.get(expectedSection, false));
53
}
54
}
55
56
@Test
57
public void testNameNoSpaceAfterColon() throws Exception {
58
test(DEFAULT_MANIFEST + "Name:section\r\n\r\n", null);
59
}
60
61
@Test
62
public void testNameCase() throws Exception {
63
test(DEFAULT_MANIFEST + "nAME: section\r\n\r\n", "section");
64
}
65
66
@Test
67
public void testEmptyName() throws Exception {
68
test(DEFAULT_MANIFEST + "Name: \r\n\r\n", "");
69
}
70
71
@Test
72
public void testShortestInvalidSection() throws Exception {
73
test(DEFAULT_MANIFEST + "Name: ", null);
74
}
75
76
@Test
77
public void testMinimalValidSection() throws Exception {
78
test(DEFAULT_MANIFEST + "Name: \r", "");
79
}
80
81
@Test
82
public void testNameNotContinued() throws Exception {
83
test(DEFAULT_MANIFEST + "Name: FooBar\r\n", "FooBar");
84
}
85
86
@Test
87
public void testImmediatelyContinuedCrName() throws Exception {
88
test(DEFAULT_MANIFEST + "Name: \r FooBar\r\n", "FooBar");
89
}
90
91
@Test
92
public void testImmediatelyContinuedLfName() throws Exception {
93
test(DEFAULT_MANIFEST + "Name: \n FooBar\r\n", "FooBar");
94
}
95
96
@Test
97
public void testImmediatelyContinuedCrLfName() throws Exception {
98
test(DEFAULT_MANIFEST + "Name: \r\n FooBar\r\n", "FooBar");
99
}
100
101
@Test
102
public void testNameContinuedCr() throws Exception {
103
test(DEFAULT_MANIFEST + "Name: FooBar\r \r\n", "FooBar");
104
}
105
106
@Test
107
public void testNameContinuedLf() throws Exception {
108
test(DEFAULT_MANIFEST + "Name: FooBar\n \r\n", "FooBar");
109
}
110
111
@Test
112
public void testNameContinuedCrLf() throws Exception {
113
test(DEFAULT_MANIFEST + "Name: FooBar\r\n \r\n", "FooBar");
114
}
115
116
@Test
117
public void testNameContinuedCrIgnoreNextChar() throws Exception {
118
test(DEFAULT_MANIFEST + "Name: Foo\r: Bar\r\n", "Foo");
119
}
120
121
@Test
122
public void testNameContinuedCrIgnoreNextCharSpace() throws Exception {
123
test(DEFAULT_MANIFEST + "Name: Foo\r Bar\r\n", "Foo Bar");
124
}
125
126
@Test
127
public void testNameContinuedContinuedCr() throws Exception {
128
test(DEFAULT_MANIFEST + "Name: Fo\r\n oB\r ar\r\n", "FooBar");
129
}
130
131
@Test
132
public void testNameContinuedContinuedLf() throws Exception {
133
test(DEFAULT_MANIFEST + "Name: Fo\r\n oB\n ar\r\n", "FooBar");
134
}
135
136
@Test
137
public void testNameContinuedContinuedCrLf() throws Exception {
138
test(DEFAULT_MANIFEST + "Name: Fo\r\n oB\r\n ar\r\n", "FooBar");
139
}
140
141
@Test
142
public void testNameContinuedEndCr() throws Exception {
143
test(DEFAULT_MANIFEST + "Name: Foo\r\n Bar\r", "FooBar");
144
}
145
146
@Test
147
public void testNameContinuedEndLf() throws Exception {
148
test(DEFAULT_MANIFEST + "Name: Foo\r\n Bar\n", "FooBar");
149
}
150
151
@Test
152
public void testNameContinuedEndCrLf() throws Exception {
153
test(DEFAULT_MANIFEST + "Name: Foo\r\n Bar\r\n", "FooBar");
154
}
155
156
}
157
158