/** * Copyright (c) 2008-2011 Sonatype, Inc. * All rights reserved. Includes the third-party code listed at http://www.sonatype.com/products/nexus/attributions. * * This program is free software: you can redistribute it and/or modify it only under the terms of the GNU Affero General * Public License Version 3 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License Version 3 * for more details. * * You should have received a copy of the GNU Affero General Public License Version 3 along with this program. If not, see * http://www.gnu.org/licenses. * * Sonatype Nexus (TM) Open Source Version is available from Sonatype, Inc. Sonatype and Sonatype Nexus are trademarks of * Sonatype, Inc. Apache Maven is a trademark of the Apache Foundation. M2Eclipse is a trademark of the Eclipse Foundation. * All other trademarks are the property of their respective owners. */ package org.sonatype.security.ldap.dao.password; import junit.framework.Assert; import org.codehaus.plexus.PlexusTestCase; public class PasswordEcoderTest extends PlexusTestCase { private PasswordEncoderManager passwordEncoderManager; @Override public void setUp() throws Exception { super.setUp(); this.passwordEncoderManager = this.lookup( PasswordEncoderManager.class ); } public void testMD5() { // String cryptPassword = "{MD5}VtAV1lfgo6fnA60qDj64iA=="; generated by apacheds (for testing), uses hash String cryptPassword = "{MD5}56d015d657e0a3a7e703ad2a0e3eb888"; // just a simple md5 of the string String password = "md5123"; Assert.assertTrue( this.passwordEncoderManager.isPasswordValid( cryptPassword, password, null ) ); } public void testClear() { String cryptPassword = "clear123"; String password = "clear123"; Assert.assertTrue( this.passwordEncoderManager.isPasswordValid( cryptPassword, password, null ) ); Assert.assertTrue( this.passwordEncoderManager.isPasswordValid( "{CLEAR}"+cryptPassword, password, null ) ); } public void testCrypt() { // String cryptPassword = "{CRYPT}h/Uf.HBpLVxmY"; generated by apacheds (for testing) String cryptPassword = "{CRYPT}$1$SpIxKuJe$KTEcMasljm9eC3CfgE72t/"; // generated by MD5Crypt.class String password = "crypt123"; Assert.assertTrue( this.passwordEncoderManager.isPasswordValid( cryptPassword, password, null ) ); } public void testPlain() { String cryptPassword = "plain123"; String password = "plain123"; Assert.assertTrue( this.passwordEncoderManager.isPasswordValid( cryptPassword, password, null ) ); Assert.assertTrue( this.passwordEncoderManager.isPasswordValid( "{PLAIN}"+cryptPassword, password, null ) ); } public void testSha() { String cryptPassword = "{SHA}5Rs+hbtHUzvAhwkuaV5g7hW2KGc="; String password = "sha123"; Assert.assertTrue( this.passwordEncoderManager.isPasswordValid( cryptPassword, password, null ) ); } public void testSsha() { String cryptPassword = "{SSHA}JoYvOj2uRZsp5hPMVgWmuwh0CnDwSgiQXMwPkg=="; String password = "ssha123"; Assert.assertTrue( this.passwordEncoderManager.isPasswordValid( cryptPassword, password, null ) ); } public void testNull() { Assert.assertFalse( this.passwordEncoderManager.isPasswordValid( null, "non null string", null ) ); Assert.assertFalse( this.passwordEncoderManager.isPasswordValid( null, null, null ) ); } }