1
1
/*
2
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
24
24
/**
25
25
* @test
26
26
* @summary DNSName parsing tests
27
- * @bug 8213952
27
+ * @bug 8213952 8186143
28
28
* @modules java.base/sun.security.x509
29
29
* @run testng DNSNameTest
30
30
*/
@@ -53,6 +53,23 @@ public Object[][] goodNames() {
53
53
return data ;
54
54
}
55
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
+
56
73
@ DataProvider (name = "badNames" )
57
74
public Object [][] badNames () {
58
75
Object [][] data = {
@@ -65,10 +82,34 @@ public Object[][] badNames() {
65
82
{"a." }, // end with .
66
83
{"" }, // empty
67
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
68
108
};
69
109
return data ;
70
110
}
71
111
112
+
72
113
@ Test (dataProvider = "goodNames" )
73
114
public void testGoodDNSName (String dnsNameString ) {
74
115
try {
@@ -78,6 +119,15 @@ public void testGoodDNSName(String dnsNameString) {
78
119
}
79
120
}
80
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
+
81
131
@ Test (dataProvider = "badNames" )
82
132
public void testBadDNSName (String dnsNameString ) {
83
133
try {
@@ -88,4 +138,15 @@ public void testBadDNSName(String dnsNameString) {
88
138
fail ("Unexpeceted message: " + e );
89
139
}
90
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
+ }
91
152
}
0 commit comments