-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from tukcomCD2024/test#59/feature-backend-tests
Test#59/feature backend tests
- Loading branch information
Showing
13 changed files
with
360 additions
and
55 deletions.
There are no files selected for viewing
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
38 changes: 21 additions & 17 deletions
38
backend/memetory/src/main/java/com/example/memetory/domain/member/controller/MemberApi.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
package com.example.memetory.domain.member.controller; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import com.example.memetory.domain.member.dto.MemberSignUpRequest; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
@Tag(name = "Member") | ||
public interface MemberApi { | ||
|
||
@Operation( | ||
summary = "회원가입", | ||
description = "첫 소셜로그인 후 추가 정보 기입", | ||
security = {@SecurityRequirement(name = "access_token")} | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "회원가입 성공!" | ||
) | ||
}) | ||
ResponseEntity<HttpStatus> register( | ||
MemberSignUpRequest memberSignUpRequest, | ||
@Parameter(hidden = true) String email | ||
); | ||
@Operation( | ||
summary = "회원가입", | ||
description = "첫 소셜로그인 후 추가 정보 기입", | ||
security = {@SecurityRequirement(name = "access_token")} | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "회원가입 성공!" | ||
) | ||
}) | ||
ResponseEntity<HttpStatus> register( | ||
HttpServletResponse response, | ||
MemberSignUpRequest memberSignUpRequest, | ||
@Parameter(hidden = true) String email | ||
); | ||
} |
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
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
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
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
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
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
52 changes: 52 additions & 0 deletions
52
backend/memetory/src/test/java/com/example/memetory/config/SecurityTestConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.example.memetory.config; | ||
|
||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.crypto.factory.PasswordEncoderFactories; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.authentication.logout.LogoutFilter; | ||
|
||
import com.example.memetory.domain.member.repository.MemberRepository; | ||
import com.example.memetory.global.security.jwt.filter.JwtAuthenticationProcessingFilter; | ||
import com.example.memetory.global.security.jwt.refresh.service.RefreshTokenService; | ||
import com.example.memetory.global.security.jwt.service.JwtService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@TestConfiguration | ||
@RequiredArgsConstructor | ||
public class SecurityTestConfig { | ||
private final JwtService jwtService; | ||
private final MemberRepository memberRepository; | ||
private final RefreshTokenService refreshTokenService; | ||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
http.formLogin(AbstractHttpConfigurer::disable) // 기본 제공하는 로그인 Form 사용 X | ||
.httpBasic(AbstractHttpConfigurer::disable) // Bearer방식이기 때문에 httpBasic 사용 X | ||
.csrf(AbstractHttpConfigurer::disable) //csrf 보안 사용 X | ||
.sessionManagement((sessionManagement) -> // 세션은 사용하지 않기 때문에 stateless 설정 | ||
sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
.authorizeHttpRequests(authorizeRequests // 개발을 진행하기 위해 일단 모든 url 허용 | ||
-> authorizeRequests.anyRequest().permitAll()); | ||
|
||
http.addFilterAfter(jwtAuthenticationProcessingFilter(), LogoutFilter.class); | ||
|
||
return http.build(); | ||
} | ||
|
||
@Bean | ||
public PasswordEncoder passwordEncoder() { | ||
return PasswordEncoderFactories.createDelegatingPasswordEncoder(); | ||
} | ||
|
||
@Bean | ||
public JwtAuthenticationProcessingFilter jwtAuthenticationProcessingFilter() { | ||
return new JwtAuthenticationProcessingFilter(jwtService, memberRepository, refreshTokenService); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
backend/memetory/src/test/java/com/example/memetory/domain/member/MemberFixture.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.example.memetory.domain.member; | ||
|
||
import com.example.memetory.domain.member.dto.MemberServiceDto; | ||
import com.example.memetory.domain.member.entity.Member; | ||
import com.example.memetory.domain.member.entity.Role; | ||
import com.example.memetory.domain.member.entity.SocialType; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class MemberFixture { | ||
public final static Member MEMBER = Member.builder() | ||
.email("[email protected]") | ||
.role(Role.USER) | ||
.imageUrl("imageUrl") | ||
.nickname("이준우") | ||
.socialType(SocialType.GOOGLE) | ||
.socialId("-1") | ||
.build(); | ||
|
||
public final static Member GUEST_MEMBER = Member.builder() | ||
.email("[email protected]") | ||
.role(Role.GUEST) | ||
.imageUrl("imageUrl") | ||
.nickname("이준우") | ||
.socialType(SocialType.GOOGLE) | ||
.socialId("-1") | ||
.build(); | ||
|
||
public final static MemberServiceDto MEMBER_SERVICE_DTO = MemberServiceDto.builder() | ||
.imageUrl("imageUrl") | ||
.nickname("junRain") | ||
.email("[email protected]") | ||
.build(); | ||
} |
Oops, something went wrong.