author | igerasim |
Wed, 16 Oct 2019 18:47:11 -0700 | |
changeset 58659 | 4113f16d5109 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
31718
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
1 |
/* |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
4 |
* |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
10 |
* |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
15 |
* accompanied this code). |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
16 |
* |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
20 |
* |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
23 |
* questions. |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
24 |
*/ |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
25 |
import java.security.KeyStore; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
26 |
import java.security.Security; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
27 |
import static java.lang.System.out; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
28 |
|
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
29 |
/** |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
30 |
* @test |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
31 |
* @bug 8048830 |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
32 |
* @summary Set up keystore.type secure property and check that |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
33 |
* KeyStore.getDefaultType() value is related to property value. Expect a full |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
34 |
* match the value 'keystore.type' and the value of the |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
35 |
* KeyStore.getDefaultType() |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
36 |
* @run main/othervm CheckDefaults |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
37 |
*/ |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
38 |
public class CheckDefaults { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
39 |
private static final String DEFAULT_KEY_STORE_TYPE = "pkcs12"; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
40 |
private static final String[] KEY_STORE_TYPES = {"jks", "pkcs12", "jceks", |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
41 |
"Unregistered_type_of_KS"}; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
42 |
|
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
43 |
private void runTest(String[] args) { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
44 |
if (!KeyStore.getDefaultType(). |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
45 |
equalsIgnoreCase(DEFAULT_KEY_STORE_TYPE)) { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
46 |
throw new RuntimeException(String.format("Default keystore type " |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
47 |
+ "Expected '%s' . Actual: '%s' ", DEFAULT_KEY_STORE_TYPE, |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
48 |
KeyStore.getDefaultType())); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
49 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
50 |
for (String ksDefaultType : KEY_STORE_TYPES) { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
51 |
Security.setProperty("keystore.type", ksDefaultType); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
52 |
if (!KeyStore.getDefaultType().equals(ksDefaultType)) { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
53 |
throw new RuntimeException(String.format( |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
54 |
"Keystore default type value: '%s' cannot be set up via" |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
55 |
+ " keystore.type " |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
56 |
+ "security property, Actual: '%s'", |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
57 |
ksDefaultType, KeyStore.getDefaultType())); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
58 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
59 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
60 |
out.println("Test Passed"); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
61 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
62 |
|
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
63 |
public static void main(String[] args) { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
64 |
CheckDefaults checkDefaultsTest = new CheckDefaults(); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
65 |
checkDefaultsTest.runTest(args); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
66 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
67 |
} |