프로젝트 정리/스프링과 JPA 기반 웹 애플리케이션 개발
20. 로그인 / 로그아웃 테스트
JunGi Jeong
2021. 12. 10. 00:47
테스트 요점 정리
- 폼 서브밋 요청 (post)은 반드시 .with(csrf())를 추가할 것.
- .andExpect(authenticated()) 또는 .andExpect(unauthenticated())로 인증 여부를 확인할 수 있다.
- 리다이렉트 응답은 .andExpect(status().is3xxRedirection()) 로 확인한다.
- 리다이렉트 URL은 .andExpect(redirectedUrl()) 로 확인할 수 있다.
- JUnit 5의 @BeforeEach와 @AfterEach.
- 임의로 로그인 된 사용자가 필요한 경우에는 @WithMockUser.
spring security -> form 그냥 보내면 안됨 why?
csrf라는 protection활성화 token
param값을 다르게 주고 싶다면 securityConfig -> formLogin()
http.formLogin()
.usernameParameter("user")
.passwordParameter("pass")
이런식으로 변경 가능
// @WithMockUser -> SpringSecurity User Type에 해당하는 principal로 넣어줌
현재 코드에 버그가 있습니다만, 해당 버그는 ‘Open EntityManager In View” 수업에서 다룹니다.
실습
- 시작 커밋: https://github.com/devjun63/whiteship-studyolle/commit/4d986f049cebb3b748c2761c10a2f02369dbf2ed
- 완료 커밋: https://github.com/devjun63/whiteship-studyolle/commit/f2d307ce5861e52e0b87e25053bd27e886232ae7
로그인 로그아웃 테스트 · devjun63/whiteship-studyolle@f2d307c
Permalink This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. Browse files 로그인 로그아웃 테스트 Loading branch information Showing 13 changed files with 357 additions and 45 deletion
github.com
16. 첫 페이지 보완 & 17. 현재 인증된 사용자 정보 참조 & 18. 가입 확인 이메일 재전송 · devjun63/whit
16 - 네비게이션 바에 Fontawesome으로 아이콘 추가, 이메일 인증을 마치지 않은 사용자에게 메시지 보여주기, jdenticon으로 프로필 기본 이미지 생성하기 17 - 익명 인증인 경우에는 null로 설정하고,
github.com