01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Vera Y. Petrashkova
20: * @version $Revision$
21: */package org.apache.harmony.security.tests.java.security;
22:
23: import java.security.*;
24: import javax.security.auth.DestroyFailedException;
25:
26: import junit.framework.TestCase;
27:
28: /**
29: * Tests for <code>KeyStore.PasswordProtection</code> class constructor and methods
30: *
31: */
32:
33: public class KSPasswordProtectionTest extends TestCase {
34:
35: /**
36: * Constructor for KSPasswordProtectionTest.
37: * @param arg0
38: */
39: public KSPasswordProtectionTest(String arg0) {
40: super (arg0);
41: }
42:
43: /**
44: * Test for <code>KeyStore.PasswordProtection(char[] password)</code> constructor
45: * and the following methods
46: * <code>getPassword()<code>
47: * <code>destroy()<code>
48: * <code>isDestroyed()<code>
49: * Assertions: constructor created new PasswordProtection object
50: * getPassword() returns password or throws IllegalArgumentException
51: * if PasswordProtection is destroyed
52: */
53: public void testGetPassword() throws DestroyFailedException {
54: char[] pass = { 'a', 'b', 'c' };
55: KeyStore.PasswordProtection ksPWP = new KeyStore.PasswordProtection(
56: pass);
57: char[] rPass = ksPWP.getPassword();
58: assertFalse("PasswordProtection Should not be destroyed", ksPWP
59: .isDestroyed());
60: assertEquals("Incorrect password length", pass.length,
61: rPass.length);
62: for (int i = 0; i < pass.length; i++) {
63: assertEquals("Incorrect password (item: ".concat(
64: Integer.toString(i)).concat(")"), pass[i], rPass[i]);
65: }
66: ksPWP.destroy();
67: assertTrue("PasswordProtection must be destroyed", ksPWP
68: .isDestroyed());
69: try {
70: ksPWP.getPassword();
71: fail("IllegalStateException must be thrown because PasswordProtection is destroyed");
72: } catch (IllegalStateException e) {
73: }
74: }
75: }
|