SEC-1472: Add crypto wrappers for BCrypt

This commit is contained in:
Dave Syer
2011-11-02 17:58:06 +00:00
committed by Luke Taylor
parent 944d762da9
commit 8565116f20
3 changed files with 910 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.security.crypto.bcrypt;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* @author Dave Syer
*
*/
public class BCryptPasswordEncoderTests {
@Test
public void matches() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String result = encoder.encode("password");
assertFalse(result.equals("password"));
assertTrue(encoder.matches("password", result));
}
@Test
public void unicode() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String result = encoder.encode("passw\u9292rd");
assertFalse(encoder.matches("pass\u9292\u9292rd", result));
assertTrue(encoder.matches("passw\u9292rd", result));
}
@Test
public void matchesLengthChecked() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String result = encoder.encode("password");
assertFalse(encoder.matches("password", result.substring(0,result.length()-2)));
}
@Test
public void notMatches() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String result = encoder.encode("password");
assertFalse(encoder.matches("bogus", result));
}
}