Skip to content

Commit 3e6ffc3

Browse files
committed
VerifyMissingAttributes test added.
Backport-Of: bb99c53d44b74a818b84542cdf00a145a3d973a2
1 parent 93c7f76 commit 3e6ffc3

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2022, Red Hat, Inc.
3+
*
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
import java.security.Provider;
26+
import java.security.Security;
27+
import java.util.HashMap;
28+
import java.util.Map;
29+
30+
/*
31+
* @test
32+
* @bug 9999999
33+
* @requires (jdk.version.major >= 8)
34+
* @run main/othervm/timeout=30 Main
35+
* @author Martin Balao ([email protected])
36+
*/
37+
38+
public final class VerifyMissingAttributes {
39+
40+
private static final String[] svcAlgImplementedIn = {
41+
"AlgorithmParameterGenerator.DSA",
42+
"AlgorithmParameters.DSA",
43+
"CertificateFactory.X.509",
44+
"KeyStore.JKS",
45+
"KeyStore.CaseExactJKS",
46+
"KeyStore.DKS",
47+
"CertStore.Collection",
48+
"CertStore.com.sun.security.IndexedCollection"
49+
};
50+
51+
public static void main(String[] args) throws Throwable {
52+
Map<String, String> attrs = new HashMap<>();
53+
Provider sunProvider = Security.getProvider("SUN");
54+
for (String svcAlg : svcAlgImplementedIn) {
55+
attrs.clear();
56+
attrs.put(svcAlg + " ImplementedIn", "Software");
57+
doQuery(sunProvider, attrs);
58+
}
59+
if (Double.parseDouble(
60+
System.getProperty("java.specification.version")) >= 17) {
61+
attrs.clear();
62+
attrs.put("KeyFactory.RSASSA-PSS SupportedKeyClasses",
63+
"java.security.interfaces.RSAPublicKey" +
64+
"|java.security.interfaces.RSAPrivateKey");
65+
doQuery(Security.getProvider("SunRsaSign"), attrs);
66+
}
67+
System.out.println("TEST PASS - OK");
68+
}
69+
70+
private static void doQuery(Provider expectedProvider,
71+
Map<String, String> attrs) throws Exception {
72+
if (expectedProvider == null) {
73+
throw new Exception("Provider not found.");
74+
}
75+
Provider[] providers = Security.getProviders(attrs);
76+
if (providers == null || providers.length != 1 ||
77+
providers[0] != expectedProvider) {
78+
StringBuffer sb = new StringBuffer();
79+
attrs.entrySet().stream().forEach(ent -> {
80+
sb.append(ent.getKey());
81+
sb.append(": ");
82+
sb.append(ent.getValue());
83+
sb.append(System.lineSeparator());
84+
});
85+
throw new Exception("Failure retrieving the provider with this" +
86+
" query: " + sb.toString());
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)