author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 40416 | jdk/test/java/security/Provider/CaseSensitiveServices.java@5d91b2fd668c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
5506
diff
changeset
|
26 |
* @bug 5097015 8130181 |
2 | 27 |
* @summary make sure we correctly treat Provider string entries as case insensitive |
28 |
* @author Andreas Sterbenz |
|
29 |
*/ |
|
30 |
||
31 |
import java.security.*; |
|
32 |
import java.security.Provider.*; |
|
33 |
||
34 |
public class CaseSensitiveServices extends Provider { |
|
35 |
CaseSensitiveServices() { |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
5506
diff
changeset
|
36 |
super("Foo", "1.0", null); |
2 | 37 |
put("MessageDigest.Foo", "com.Foo"); |
38 |
put("mESSAGEdIGEST.fOO xYz", "aBc"); |
|
39 |
put("ALg.aliaS.MESSAGEdigest.Fu", "FoO"); |
|
40 |
put("messageDigest.Bar", "com.Bar"); |
|
41 |
put("MESSAGEDIGEST.BAZ", "com.Baz"); |
|
42 |
} |
|
43 |
||
44 |
public static void main(String[] args) throws Exception { |
|
45 |
Provider p = new CaseSensitiveServices(); |
|
46 |
System.out.println(p.getServices()); |
|
47 |
if (p.getServices().size() != 3) { |
|
48 |
throw new Exception("services.size() should be 3"); |
|
49 |
} |
|
50 |
Service s = testService(p, "MessageDigest", "fOO"); |
|
51 |
String val = s.getAttribute("Xyz"); |
|
52 |
if ("aBc".equals(val) == false) { |
|
53 |
throw new Exception("Wrong value: " + val); |
|
54 |
} |
|
55 |
testService(p, "MessageDigest", "fU"); |
|
56 |
testService(p, "MessageDigest", "BAR"); |
|
57 |
testService(p, "MessageDigest", "baz"); |
|
58 |
System.out.println("OK"); |
|
59 |
} |
|
60 |
||
61 |
private static Service testService(Provider p, String type, String alg) throws Exception { |
|
62 |
System.out.println("Getting " + type + "." + alg + "..."); |
|
63 |
Service s = p.getService(type, alg); |
|
64 |
System.out.println(s); |
|
65 |
if (s == null) { |
|
66 |
throw new Exception("Lookup failed for: " + type + "." + alg); |
|
67 |
} |
|
68 |
return s; |
|
69 |
} |
|
70 |
||
71 |
} |