1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  @test
  26  @summary <rdar://problem/7481203> Default password for cacerts changed in Update 1
  27  @summary com.apple.junit.apple.crypto;
  28  @run junit DefaultKeyStorePasswordTest
  29  */
  30 
  31 import java.io.FileInputStream;
  32 import java.security.KeyStore;
  33 import junit.framework.*;
  34 
  35 public class DefaultKeyStorePasswordTest extends TestCase {
  36 
  37     public void testExistance() throws Exception {
  38         try {
  39             KeyStore trustStore = KeyStore.getInstance("jks");
  40             String javahome = System.getProperty("java.home");
  41             FileInputStream in = new FileInputStream(
  42                     javahome + "/lib/security/cacerts");
  43             trustStore.load(in, "changeit".toCharArray());
  44         } catch (Exception e) {
  45             e.printStackTrace();
  46             fail("Default password for cacerts should be \"changeit\"");
  47         }
  48 
  49     }
  50 
  51     public static Test suite() {
  52         return new TestSuite(DefaultKeyStorePasswordTest.class);
  53     }
  54 
  55     public static void main (String[] args) throws RuntimeException {
  56         TestResult tr = junit.textui.TestRunner.run(suite());
  57         if((tr.errorCount() != 0) || (tr.failureCount() != 0)) {
  58             throw new RuntimeException("### Unexpected JUnit errors or failures.");
  59         }
  60     }
  61 
  62 }