blob: 7cfda1fc03cea0d7b0a97860a0369b5b8d3c2d85 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 5097015
27 * @summary make sure we correctly treat Provider string entries as case insensitive
28 * @author Andreas Sterbenz
29 */
30
31import java.security.*;
32import java.security.Provider.*;
33
34public class CaseSensitiveServices extends Provider {
35 CaseSensitiveServices() {
36 super("Foo", 1.0d, null);
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}