1 /* |
1 /* |
2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 /** |
23 /** |
24 * @test |
24 * @test |
25 * @bug 6581254 6986789 |
25 * @bug 6581254 6986789 7196009 |
26 * @summary Allow '~' and '+' in config file |
26 * @summary Allow '~', '+' and quoted paths in config file |
27 * @author Valerie Peng |
27 * @author Valerie Peng |
28 */ |
28 */ |
29 |
29 |
30 import java.security.*; |
30 import java.security.*; |
31 import java.io.*; |
31 import java.io.*; |
32 import java.lang.reflect.*; |
32 import java.lang.reflect.*; |
33 |
33 |
34 public class ConfigShortPath { |
34 public class ConfigShortPath { |
35 |
35 |
36 private static final String[] configNames = { "csp.cfg", "cspPlus.cfg" }; |
36 private static final String[] configNames = { |
|
37 "csp.cfg", "cspPlus.cfg", "cspQuotedPath.cfg" |
|
38 }; |
37 |
39 |
38 public static void main(String[] args) throws Exception { |
40 public static void main(String[] args) throws Exception { |
39 Constructor cons = null; |
41 Constructor cons = null; |
40 try { |
42 try { |
41 Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11"); |
43 Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11"); |
51 System.out.println("Testing against " + configFile); |
53 System.out.println("Testing against " + configFile); |
52 try { |
54 try { |
53 Object obj = cons.newInstance(configFile); |
55 Object obj = cons.newInstance(configFile); |
54 } catch (InvocationTargetException ite) { |
56 } catch (InvocationTargetException ite) { |
55 Throwable cause = ite.getCause(); |
57 Throwable cause = ite.getCause(); |
|
58 System.out.println(cause); |
56 if (cause instanceof ProviderException) { |
59 if (cause instanceof ProviderException) { |
57 String causeMsg = cause.getCause().getMessage(); |
60 while ((cause = cause.getCause()) != null) { |
58 // Indicate failure if due to parsing config |
61 System.out.println(cause); |
59 if (causeMsg.indexOf("Unexpected token") != -1) { |
62 String causeMsg = cause.getMessage(); |
60 throw (ProviderException) cause; |
63 // Indicate failure if due to parsing config |
|
64 if (causeMsg.indexOf("Unexpected") != -1) { |
|
65 throw (ProviderException) cause; |
|
66 } |
61 } |
67 } |
|
68 // Consider the test passes if the exception is |
|
69 // thrown after parsing, i.e. due to the absolute |
|
70 // path requirement or the non-existent path. |
|
71 } else { |
|
72 // unexpected exception |
|
73 throw new RuntimeException("Unexpected Exception", cause); |
62 } |
74 } |
63 } |
75 } |
64 } |
76 } |
65 } |
77 } |
66 } |
78 } |