Skip to content

Commit

Permalink
hotfix: 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
donghae-kim committed Oct 6, 2023
1 parent 2fb80d1 commit 1cdfb23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ public LoginMember resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) {
return new LoginMember(1L, Authority.MEMBER);
// String credentials = AuthorizationExtractor
// .extract(webRequest.getNativeRequest(HttpServletRequest.class));
//
// if (credentials == null || credentials.isEmpty()) {
// memberAuthorityCache.setAuthority(Authority.ANONYMOUS);
// return new LoginMember(Authority.ANONYMOUS);
// }
//
// try {
// Long id = Long.parseLong(jwtTokenProvider.extractSubject(credentials));
// memberAuthorityCache.setAuthority(Authority.MEMBER);
// return new LoginMember(id, Authority.MEMBER);
// } catch (NumberFormatException e) {
// throw new BadRequestException(TOKEN_NOT_VALID);
// }
String credentials = AuthorizationExtractor
.extract(webRequest.getNativeRequest(HttpServletRequest.class));

if (credentials == null || credentials.isEmpty()) {
memberAuthorityCache.setAuthority(Authority.ANONYMOUS);
return new LoginMember(Authority.ANONYMOUS);
}

try {
Long id = Long.parseLong(jwtTokenProvider.extractSubject(credentials));
memberAuthorityCache.setAuthority(Authority.MEMBER);
return new LoginMember(id, Authority.MEMBER);
} catch (NumberFormatException e) {
throw new BadRequestException(TOKEN_NOT_VALID);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -320,13 +323,13 @@ void filter_isBookmarked() {
final Article article = new Article(member, new Title("title"), new Url("url"), new ImageUrl("imageUrl"));
final LoginMember loginMember = new LoginMember(1L, MEMBER);

when(articleRepository.findArticlesByCourseAndMember(any(), any(), any())).thenReturn(Arrays.asList(article));
when(articleRepository.findArticlesByCourseAndMember(anyString(), anyLong(), anyBoolean())).thenReturn(Arrays.asList(article));

//when
final List<ArticleResponse> articleResponses = articleService.getFilteredArticles(loginMember, ArticleFilterType.BACKEND, true);

//then
verify(articleRepository).findArticlesByCourseAndMember(any(), any(), any());
verify(articleRepository).findArticlesByCourseAndMember(anyString(), anyLong(), anyBoolean());
Assertions.assertThat(articleResponses.get(0).getTitle()).isEqualTo(article.getTitle().getTitle());
}

Expand Down

0 comments on commit 1cdfb23

Please sign in to comment.