-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
해당 API에 토큰 기반 Authorization을 적용한다 #29
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 다른 코드에서 생성자에는 lombok을 쓰지 않고 있다. 일관성을 맞추기 위해 생성자를 직접 만들었다.
- accessTokenShouldBePublishedWhenJoinedUserLogin() 테스트 메서드는 두 가지를 검증한다. a) access token이 request body로 반환되는가, b) refresh token이 cookie에 저장되는가. - 테스트 메서드 하나에서 여러 항목을 검증하니까 테스트를 한 번에 이해하기 힘들고, 읽기도 어렵다. 추가로 검증할 항목이 생겨서 한 테스트 메서드에 다 몰아넣기보다는 동일한 요청에 대해 검증할 항목마다 테스트 메서드를 만드는 게 더 깔끔하다고 생각했다. 그래서 검증 항목별로 테스트를 나눴다.
- request body로 반환되는 access token은 다음 요청에 서버에서 접근할 수 없다. 따라서 authorization이 필요한 api 요청 시 access token을 쓰기 위해 추가로 응답의 authorization 헤더에 access token을 저장한다.
- 기존에 만든 컨트롤러 레이어 테스트에서 JwtAuthenticationFilter 빈을 자동으로 가져온다. 모든 컨트롤러 레이어 테스트에서 필터의 동작을 확인하기보다는 분리해서 테스트하는 것이 더 낫다고 판단했다.
- postman으로 테스트했을 때 필터를 적용하지 않을 URI를 제대로 잡아내지 않는 것을 확인했다. 올바로 작동하도록 고쳤다.
- 인증 필터를 추가하면서 기존 통합 테스트는 인증이 되지 않은 상태가 되어버려서 테스트가 모두 실패하는 문제가 생겼다. - AuthController를 의존 객체로 추가해 모든 테스트 전에 로그인해서 인증 과정을 거친 후 테스트를 실행하도록 해 해결했다.
- 각 테스트마다 로그인한 뒤 로그인의 응답으로 얻은 토큰을 Auth 헤더에 설정해 해결했다.
- 기존에는 권한이 필요한 API를 테스트하기 위해 API 호출로 인증 완료 상태를 만드는 로직을 추가했다. - 하지만 HTTP 요청이 상태를 가지지 않음을 고려하면, 강제로 서버에서 인증 완료 상태를 가지고 있게 만드는 건 적절하지 않아 보인다. 그래서 인증과 관련된 부분을 모두 지웠다.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
작업 내용
요청의 토큰 정보 소유 여부가 테스트 결과에 영향을 미치지 않도록 했다.
http request는 stateless하기 때문이다.
생각하기 때문이다. 먼저 로그인을 요청하고, 이에 따라 만들어진 토큰 정보를 인증이 필요한 API 호출에 쓴다.
적절하지 않다고 보이고, 따라서 테스트 방식 개선이 필요해보인다.
추가할 이슈
그에 따라 바뀌어야할 테고, 결과적으로 테스트가 변화에 유연해지지 않게 될 것 같다.
연관 이슈(ex. #x)