From 1cdfb23bfab46fce422c3dd495386976794223fb Mon Sep 17 00:00:00 2001 From: donghae-kim Date: Fri, 6 Oct 2023 15:17:05 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthMemberPrincipalArgumentResolver.java | 31 +++++++++---------- .../application/ArticleServiceTest.java | 7 +++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/wooteco/prolog/login/ui/AuthMemberPrincipalArgumentResolver.java b/backend/src/main/java/wooteco/prolog/login/ui/AuthMemberPrincipalArgumentResolver.java index 0cd8261bd..c2e50a8b0 100644 --- a/backend/src/main/java/wooteco/prolog/login/ui/AuthMemberPrincipalArgumentResolver.java +++ b/backend/src/main/java/wooteco/prolog/login/ui/AuthMemberPrincipalArgumentResolver.java @@ -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); + } } } diff --git a/backend/src/test/java/wooteco/prolog/article/application/ArticleServiceTest.java b/backend/src/test/java/wooteco/prolog/article/application/ArticleServiceTest.java index b4381dcfa..897bb537e 100644 --- a/backend/src/test/java/wooteco/prolog/article/application/ArticleServiceTest.java +++ b/backend/src/test/java/wooteco/prolog/article/application/ArticleServiceTest.java @@ -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; @@ -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 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()); }