author | weijun |
Fri, 15 Nov 2019 09:06:58 +0800 | |
changeset 59104 | 046e4024e55a |
parent 54521 | 8de62c4af8c7 |
permissions | -rw-r--r-- |
54521
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
1 |
/* |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
4 |
* |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
8 |
* |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
14 |
* |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
18 |
* |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
21 |
* questions. |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
22 |
*/ |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
23 |
|
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
24 |
/* |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
25 |
* @test |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
26 |
* @bug 8022761 |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
27 |
* @summary regression: SecurityException is NOT thrown while trying |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
28 |
* to pack a wrongly signed Indexed Jar file |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
29 |
* @library /test/lib |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
30 |
*/ |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
31 |
|
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
32 |
import jdk.test.lib.SecurityTools; |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
33 |
import jdk.test.lib.util.JarUtils; |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
34 |
|
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
35 |
import java.nio.file.Files; |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
36 |
import java.nio.file.Path; |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
37 |
import java.util.List; |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
38 |
|
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
39 |
public class JvIndex { |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
40 |
public static void main(String[] args) throws Exception { |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
41 |
|
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
42 |
Files.write(Path.of("abcde"), List.of("12345")); |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
43 |
JarUtils.createJarFile(Path.of("jvindex.jar"), Path.of("."), |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
44 |
Path.of("abcde")); |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
45 |
SecurityTools.keytool("-storepass changeit -keypass changeit " |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
46 |
+ "-keystore ks -keyalg rsa -alias a -dname CN=a " |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
47 |
+ "-genkey -validity 300") |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
48 |
.shouldHaveExitValue(0); |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
49 |
SecurityTools.jarsigner("-keystore ks -storepass changeit jvindex.jar a") |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
50 |
.shouldHaveExitValue(0); |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
51 |
|
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
52 |
SecurityTools.jar("i jvindex.jar"); |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
53 |
|
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
54 |
// Make sure the $F line has "sm" (signed and in manifest) |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
55 |
SecurityTools.jarsigner("-keystore ks -storepass changeit -verify " |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
56 |
+ "-verbose jvindex.jar") |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
57 |
.shouldHaveExitValue(0) |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
58 |
.shouldMatch("sm.*abcde"); |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
59 |
} |
8de62c4af8c7
8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff
changeset
|
60 |
} |