-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Kwoun Ki Ho <[email protected]>
- Loading branch information
1 parent
45273d9
commit 8397c42
Showing
13 changed files
with
437 additions
and
6 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
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
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/cruru/member/controller/request/EmailChangeRequest.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,10 @@ | ||
package com.cruru.member.controller.request; | ||
|
||
import jakarta.validation.constraints.Email; | ||
|
||
public record EmailChangeRequest( | ||
String email | ||
) { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/cruru/member/controller/request/PasswordChangeRequest.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,10 @@ | ||
package com.cruru.member.controller.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record PasswordChangeRequest( | ||
@NotBlank(message = "비밀번호를 입력해주세요.") | ||
String password | ||
) { | ||
|
||
} |
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
79 changes: 79 additions & 0 deletions
79
backend/src/test/java/com/cruru/member/acceptance/MemberAcceptanceTest.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,79 @@ | ||
package com.cruru.member.acceptance; | ||
|
||
import static org.mockito.Mockito.doNothing; | ||
|
||
import com.cruru.auth.service.AuthService; | ||
import com.cruru.club.domain.repository.ClubRepository; | ||
import com.cruru.email.service.EmailRedisClient; | ||
import com.cruru.member.controller.request.EmailChangeRequest; | ||
import com.cruru.member.controller.request.PasswordChangeRequest; | ||
import com.cruru.member.domain.Member; | ||
import com.cruru.member.domain.repository.MemberRepository; | ||
import com.cruru.util.AcceptanceTest; | ||
import com.cruru.util.fixture.ClubFixture; | ||
import com.cruru.util.fixture.MemberFixture; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
public class MemberAcceptanceTest extends AcceptanceTest { | ||
|
||
@MockBean | ||
private EmailRedisClient emailRedisClient; | ||
|
||
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
@Autowired | ||
private ClubRepository clubRepository; | ||
|
||
@Autowired | ||
private AuthService authService; | ||
|
||
private Member member; | ||
private String newToken; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
member = memberRepository.save(MemberFixture.DOBBY); | ||
clubRepository.save(ClubFixture.create(member)); | ||
newToken = authService.createAccessToken(member.getEmail(), member.getRole()).getToken(); | ||
} | ||
|
||
@DisplayName("사용자는 다른 사용자의 이메일을 변경할 수 없다.") | ||
@Test | ||
void userCannotChangeAnotherUsersEmail() { | ||
// given | ||
String changeEmail = "[email protected]"; | ||
EmailChangeRequest request = new EmailChangeRequest(changeEmail); | ||
doNothing().when(emailRedisClient).verifyEmail(request.email()); | ||
|
||
// when&then | ||
RestAssured.given().log().all() | ||
.contentType(ContentType.JSON) | ||
.cookie("accessToken", newToken) | ||
.body(request) | ||
.when().patch("/v1/members/{memberId}/email", defaultMember.getId()) | ||
.then().log().all().statusCode(403); | ||
} | ||
|
||
@DisplayName("사용자는 다른 사용자의 비밀번호를 변경할 수 없다.") | ||
@Test | ||
void userCannotChangeAnotherUsersPassword() { | ||
// given | ||
String changePassword = "NewPassword123!!"; | ||
PasswordChangeRequest request = new PasswordChangeRequest(changePassword); | ||
|
||
// when&then | ||
RestAssured.given().log().all() | ||
.contentType(ContentType.JSON) | ||
.cookie("accessToken", newToken) | ||
.body(request) | ||
.when().patch("/v1/members/{memberId}/password", defaultMember.getId()) | ||
.then().log().all().statusCode(403); | ||
} | ||
} |
Oops, something went wrong.