author | igerasim |
Wed, 16 Oct 2019 18:47:11 -0700 | |
changeset 58659 | 4113f16d5109 |
parent 51687 | 1e39953aaed8 |
permissions | -rw-r--r-- |
31718
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
1 |
/* |
51675 | 2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
31718
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 |
|
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
26 |
import java.io.File; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
27 |
import java.security.Key; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
28 |
import java.security.KeyStore; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
29 |
import java.security.KeyStoreException; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
30 |
import java.security.NoSuchAlgorithmException; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
31 |
import java.security.PrivateKey; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
32 |
import java.security.UnrecoverableKeyException; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
33 |
import java.security.cert.Certificate; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
34 |
import java.io.IOException; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
35 |
import java.security.cert.CertificateException; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
36 |
import static java.lang.System.out; |
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 |
/** |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
39 |
* @test |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
40 |
* @bug 8048830 |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
41 |
* @summary Entry's attribute set should be empty |
51687
1e39953aaed8
8182404: remove jdk.testlibrary.JDKToolFinder and JDKToolLauncher
iignatyev
parents:
51675
diff
changeset
|
42 |
* @library ../ |
51675 | 43 |
* @library /test/lib |
31718
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
44 |
* @run main MetadataEmptyTest |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
45 |
*/ |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
46 |
public class MetadataEmptyTest { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
47 |
private static final char[] PASSWORD = "passwd".toCharArray(); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
48 |
private static final String ALIAS = "testkey"; |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
49 |
private static final String KEYSTORE_PATH = System.getProperty( |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
50 |
"test.classes" + File.separator + "ks.pkcs12", |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
51 |
"." + File.separator + "ks.pkcs12"); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
52 |
|
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
53 |
private void runTest() throws IOException, KeyStoreException, |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
54 |
NoSuchAlgorithmException, CertificateException, |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
55 |
UnrecoverableKeyException { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
56 |
KeyStore ks = Utils.loadKeyStore(KEYSTORE_PATH, |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
57 |
Utils.KeyStoreType.pkcs12, PASSWORD); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
58 |
Key key = ks.getKey(ALIAS, PASSWORD); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
59 |
Certificate cert = ks |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
60 |
.getCertificate(ALIAS); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
61 |
KeyStore.Entry entry = new KeyStore.PrivateKeyEntry( |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
62 |
(PrivateKey) key, |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
63 |
new Certificate[]{cert}); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
64 |
if (!entry.getAttributes().isEmpty()) { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
65 |
throw new RuntimeException("Entry's attributes set " |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
66 |
+ "must be empty"); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
67 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
68 |
out.println("Test Passed"); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
69 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
70 |
|
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
71 |
public static void main(String[] args) throws Exception{ |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
72 |
MetadataEmptyTest test = new MetadataEmptyTest(); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
73 |
test.setUp(); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
74 |
test.runTest(); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
75 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
76 |
|
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
77 |
private void setUp() { |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
78 |
Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS); |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
79 |
} |
c10ac6f1e391
8048830: Implement tests for new functionality provided in JEP 166
vinnie
parents:
diff
changeset
|
80 |
} |