Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 메모이제이션
- 서비스 디스커버리
- 다익스트라
- 도커
- 완전 탐색
- 구간 트리
- 백트래킹
- 이분 탐색
- 게이트웨이
- 플로이드 와샬
- 달팽이
- Spring Cloud Config
- dp
- 비트마스킹
- 스프링 시큐리티
- BFS
- 구현
- Zuul
- ZuulFilter
- spring cloud
- 주울
- spring boot
- docker-compose
- 이분 매칭
- Gradle
- 유레카
- Logback
- 트리
- Java
- 스택
Archives
- Today
- Total
Hello, Freakin world!
DelegatingPasswordEncoder 단위테스트 케이스 본문
...
public class TestPasswordEncoder {
@Test
public void delegatingPasswordEncodingTest() {
//given
String givenPassword = "hello";
//when
PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
String encodedPassword = passwordEncoder.encode(givenPassword);
//then
assertThat(passwordEncoder.matches(givenPassword, encodedPassword)).isTrue() ;
}
@Test
public void defaultDelegatingPasswordEncoder(){
String givenPassword = "hello";
PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
String encodedPassword = passwordEncoder.encode(givenPassword);
assertThat(encodedPassword.startsWith("{bcrypt}")).isTrue();
}
@Test
public void bcrytPasswordEncoding_서로_다른_버전_인코딩() {
//given
String givenPassword = "hello";
//when
BCryptPasswordEncoder bCryptPasswordEncoder$2A = new BCryptPasswordEncoder(BCryptVersion.$2A);
String encodedPasswordVersion$2A = bCryptPasswordEncoder$2A.encode(givenPassword);
BCryptPasswordEncoder bCryptPasswordEncoder$2B = new BCryptPasswordEncoder(BCryptVersion.$2B);
String encodedPasswordVersion$2B = bCryptPasswordEncoder$2B.encode(givenPassword);
//then
assertThat(encodedPasswordVersion$2A).isNotEqualTo(encodedPasswordVersion$2B);
}
@Test
public void delegatingPasswordEncoding_서로_다른_버전_호환테스트() {
//given
String givenPassword = "hello";
String idForEncode = "bcrypt_2A";
Map encoders = new HashMap<>();
encoders.put(idForEncode, new BCryptPasswordEncoder(BCryptVersion.$2A));
encoders.put("bcrypt_2B", new BCryptPasswordEncoder(BCryptVersion.$2B));
DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder(idForEncode,encoders);
//when
PasswordEncoder otherPasswordEncoder = new BCryptPasswordEncoder(BCryptVersion.$2B);
String encodedPassword = "{bcrypt_2B}" + otherPasswordEncoder.encode(givenPassword);
//then
assertThat(delegatingPasswordEncoder.matches(givenPassword, encodedPassword)).isTrue();
}
@Test
public void delegatingPasswordEncoding_서로_다른_인코더_호환() {
//given
String givenPassword = "hello";
String idForEncode = "bcrypt";
Map encoders = new HashMap<>();
encoders.put(idForEncode, new BCryptPasswordEncoder());
encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder(idForEncode,encoders);
//when
PasswordEncoder otherPasswordEncoder = new Pbkdf2PasswordEncoder();
String encodedPassword = "{pbkdf2}" + otherPasswordEncoder.encode(givenPassword);
//then
assertThat(delegatingPasswordEncoder.matches(givenPassword, encodedPassword)).isTrue();
}
}
'Spring boot > Security' 카테고리의 다른 글
스프링 시큐리티 CORS 해결하기 (0) | 2021.04.19 |
---|---|
스프링 시큐리티, 스프링 MVC 통합 테스트 작성하기 (0) | 2021.04.18 |
[스프링 시큐리티] Username/Password 인증 구현하기 (0) | 2021.04.17 |
Comments