-
Notifications
You must be signed in to change notification settings - Fork 3
fix: 잘못된 비밀번호 검증 로직과 잘못된 비밀번호 테스트 수정 #467
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
40 changes: 40 additions & 0 deletions
40
backend/src/test/java/moadong/unit/user/PasswordValidatorTest.java
This file contains hidden or 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,40 @@ | ||
| package moadong.unit.user; | ||
|
|
||
| import moadong.fixture.UserFixture; | ||
| import moadong.global.validator.PasswordValidator; | ||
| import moadong.util.annotations.UnitTest; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| @UnitTest | ||
| public class PasswordValidatorTest { | ||
| private final PasswordValidator passwordValidator = new PasswordValidator(); | ||
|
|
||
| @Test | ||
| void 유효한_비밀번호는_유효하다() { | ||
| boolean isValid = passwordValidator.isValid(UserFixture.collectPassword, null); | ||
| Assertions.assertThat(isValid).isTrue(); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { | ||
| "short1!", // 7자 (길이 부족) | ||
| "longpassword1234567890!", // 21자 (길이 초과) | ||
| "abcdefgh", // 영문 소문자만 (숫자 없음) | ||
| "ABCDEFGH", // 영문 대문자만 (숫자 없음) | ||
| "12345678", // 숫자만 (영문 없음) | ||
| "Abcdefgh", // 영문만 (숫자 없음) | ||
| "abcd1234*", // 허용되지 않은 특수문자 `*` | ||
| "abc def123!", // 공백 포함 | ||
| "passWord!", // 특수문자 있음, 숫자 없음 | ||
| "1234!@#$", // 숫자 + 특수문자, 문자 없음 | ||
| "Abcdef12()", // 괄호 포함 (허용되지 않은 특수문자) | ||
| "ABCD1234~", // `~` 특수문자 허용 안됨 | ||
| }) | ||
| void 유효하지_않은_비밀번호는_실패한다(String password) { | ||
| boolean isValid = passwordValidator.isValid(password, null); | ||
| Assertions.assertThat(isValid).isFalse(); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
null과 빈 문자열에 대한 테스트 케이스를 추가하세요.
현재 테스트는 다양한 무효한 문자열 패턴을 다루고 있지만, 변경된 null/empty 처리 로직에 대한 명시적인 테스트가 누락되어 있습니다.
다음 테스트 케이스들을 추가하는 것을 권장합니다:
@ParameterizedTest @ValueSource(strings = { "short1!", // 7자 (길이 부족) "longpassword1234567890!", // 21자 (길이 초과) // ... 기존 케이스들 }) void 유효하지_않은_비밀번호는_실패한다(String password) { boolean isValid = passwordValidator.isValid(password, null); Assertions.assertThat(isValid).isFalse(); } +@Test +void null_또는_빈_비밀번호는_유효하지_않다() { + Assertions.assertThat(passwordValidator.isValid(null, null)).isFalse(); + Assertions.assertThat(passwordValidator.isValid("", null)).isFalse(); +}📝 Committable suggestion
🤖 Prompt for AI Agents