KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldastudio > browser > core > model > PasswordTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldastudio.browser.core.model;
22
23 import org.apache.directory.ldapstudio.browser.core.model.Password;
24
25 import junit.framework.TestCase;
26
27 /**
28  * Test all the encryption algorithmes
29  *
30  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
31  * @version $Rev$, $Date$
32  */

33 public class PasswordTest extends TestCase
34 {
35     /**
36      * Null Password should not be accepted
37      */

38     public void testNullPassword()
39     {
40         try
41         {
42             new Password( (String JavaDoc)null );
43             fail();
44         }
45         catch ( IllegalArgumentException JavaDoc iae )
46         {
47             assertTrue( true );
48         }
49     }
50     
51     
52     /**
53      *
54      */

55     public void testPasswordSHAEncrypted()
56     {
57         Password password = new Password( "{SHA}5en6G6MezRroT3XKqkdPOmY/BfQ=" );
58             
59         assertTrue( password.verify( "secret" ) );
60     }
61
62     /**
63      *
64      */

65     public void testPasswordSSHAEncrypted()
66     {
67         Password password = new Password( "{SSHA}mjVVxasFkk59wMW4L1Ldt+YCblfhULHs03WW7g==" );
68             
69         assertTrue( password.verify( "secret" ) );
70     }
71
72     /**
73      *
74      */

75     public void testPasswordMD5Encrypted()
76     {
77         Password password = new Password( "{MD5}Xr4ilOzQ4PCOq3aQ0qbuaQ==" );
78             
79         assertTrue( password.verify( "secret" ) );
80     }
81
82     /**
83      *
84      */

85     public void testPasswordSMD5Encrypted()
86     {
87         Password password = new Password( "{SMD5}tQ9wo/VBuKsqBtylMMCcORbnYOJFMyDJ" );
88             
89         assertTrue( password.verify( "secret" ) );
90     }
91
92     /**
93      *
94      */

95     public void testPasswordCRYPTEncrypted()
96     {
97         Password password = new Password( "{CRYPT}qFkH8Z1woBlXw" );
98             
99         assertTrue( password.verify( "secret" ) );
100     }
101
102     /**
103      *
104      */

105     public void testPasswordBadAlgorithm()
106     {
107         Password password = new Password( "{CRYPTE}qFkH8Z1woBlXw" );
108
109         assertFalse( password.verify( "secret" ) );
110     }
111 }
112
Popular Tags