Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/x509/GeneralName/DNSNameTest.java
41152 views
1
/*
2
* Copyright (c) 2018, 2020, 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
* @summary DNSName parsing tests
27
* @bug 8213952 8186143
28
* @modules java.base/sun.security.x509
29
* @run testng DNSNameTest
30
*/
31
32
import java.io.IOException;
33
import sun.security.x509.DNSName;
34
35
import org.testng.annotations.DataProvider;
36
import org.testng.annotations.Test;
37
38
import static org.testng.Assert.*;
39
40
public class DNSNameTest {
41
@DataProvider(name = "goodNames")
42
public Object[][] goodNames() {
43
Object[][] data = {
44
{"abc.com"},
45
{"ABC.COM"},
46
{"a12.com"},
47
{"a1b2c3.com"},
48
{"1abc.com"},
49
{"123.com"},
50
{"abc.com-"}, // end with hyphen
51
{"a-b-c.com"}, // hyphens
52
};
53
return data;
54
}
55
56
@DataProvider(name = "goodSanNames")
57
public Object[][] goodSanNames() {
58
Object[][] data = {
59
{"abc.com"},
60
{"ABC.COM"},
61
{"a12.com"},
62
{"a1b2c3.com"},
63
{"1abc.com"},
64
{"123.com"},
65
{"abc.com-"}, // end with hyphen
66
{"a-b-c.com"}, // hyphens
67
{"*.domain.com"}, // wildcard in 1st level subdomain
68
{"*.com"},
69
};
70
return data;
71
}
72
73
@DataProvider(name = "badNames")
74
public Object[][] badNames() {
75
Object[][] data = {
76
{" 1abc.com"}, // begin with space
77
{"1abc.com "}, // end with space
78
{"1a bc.com "}, // no space allowed
79
{"-abc.com"}, // begin with hyphen
80
{"a..b"}, // ..
81
{".a"}, // begin with .
82
{"a."}, // end with .
83
{""}, // empty
84
{" "}, // space only
85
{"*.domain.com"}, // wildcard not allowed
86
{"a*.com"}, // only allow letter, digit, or hyphen
87
};
88
return data;
89
}
90
91
@DataProvider(name = "badSanNames")
92
public Object[][] badSanNames() {
93
Object[][] data = {
94
{" 1abc.com"}, // begin with space
95
{"1abc.com "}, // end with space
96
{"1a bc.com "}, // no space allowed
97
{"-abc.com"}, // begin with hyphen
98
{"a..b"}, // ..
99
{".a"}, // begin with .
100
{"a."}, // end with .
101
{""}, // empty
102
{" "}, // space only
103
{"*"}, // wildcard only
104
{"*a.com"}, // partial wildcard disallowed
105
{"abc.*.com"}, // wildcard not allowed in 2nd level
106
{"*.*.domain.com"}, // double wildcard not allowed
107
{"a*.com"}, // only allow letter, digit, or hyphen
108
};
109
return data;
110
}
111
112
113
@Test(dataProvider = "goodNames")
114
public void testGoodDNSName(String dnsNameString) {
115
try {
116
DNSName dn = new DNSName(dnsNameString);
117
} catch (IOException e) {
118
fail("Unexpected IOException");
119
}
120
}
121
122
@Test(dataProvider = "goodSanNames")
123
public void testGoodSanDNSName(String dnsNameString) {
124
try {
125
DNSName dn = new DNSName(dnsNameString, true);
126
} catch (IOException e) {
127
fail("Unexpected IOException");
128
}
129
}
130
131
@Test(dataProvider = "badNames")
132
public void testBadDNSName(String dnsNameString) {
133
try {
134
DNSName dn = new DNSName(dnsNameString);
135
fail("IOException expected");
136
} catch (IOException e) {
137
if (!e.getMessage().contains("DNSName"))
138
fail("Unexpeceted message: " + e);
139
}
140
}
141
142
@Test(dataProvider = "badSanNames")
143
public void testBadSanDNSName(String dnsNameString) {
144
try {
145
DNSName dn = new DNSName(dnsNameString, true);
146
fail("IOException expected");
147
} catch (IOException e) {
148
if (!e.getMessage().contains("DNSName"))
149
fail("Unexpeceted message: " + e);
150
}
151
}
152
}
153
154