blob: 06027302dacb3933a8c513427dfb8c4d5ce79909 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2006 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 6489721
27 * @summary keytool has not closed several file streams
28 * @author weijun.wang
29 *
30 * This test is only useful on Windows, which fails before the fix and succeeds
31 * after it. On other platforms, it always passes.
32 */
33
34import sun.security.tools.KeyTool;
35import java.io.*;
36
37public class CloseFile {
38 public static void main(String[] args) throws Exception {
39 remove("f0", false);
40 remove("f1", false);
41 run("-keystore f0 -storepass changeit -keypass changeit -genkeypair -dname CN=Haha");
42 run("-keystore f0 -storepass changeit -keypass changeit -certreq -file f2");
43 remove("f2", true);
44 run("-keystore f0 -storepass changeit -keypass changeit -exportcert -file f2");
45 remove("f2", true);
46 run("-keystore f0 -storepass changeit -keypass changeit -exportcert -file f2");
47 run("-keystore f0 -storepass changeit -keypass changeit -delete -alias mykey");
48 run("-keystore f0 -storepass changeit -keypass changeit -importcert -file f2 -noprompt");
49 remove("f2", true);
50 run("-keystore f0 -storepass changeit -keypass changeit -exportcert -file f2");
51 run("-printcert -file f2");
52 remove("f2", true);
53 remove("f0", true);
54 run("-keystore f0 -storepass changeit -keypass changeit -genkeypair -dname CN=Haha");
55 run("-importkeystore -srckeystore f0 -destkeystore f1 -srcstorepass changeit -deststorepass changeit");
56 remove("f0", true);
57 remove("f1", true);
58 }
59
60 static void run(String s) throws Exception {
61 KeyTool.main((s+" -debug").split(" "));
62 }
63 static void remove(String filename, boolean check) {
64 new File(filename).delete();
65 if (check && new File(filename).exists()) {
66 throw new RuntimeException("Error deleting " + filename);
67 }
68 }
69}