Skip to content

Comments

fix: 잘못된 비밀번호 검증 로직과 잘못된 비밀번호 테스트 수정#467

Merged
Zepelown merged 1 commit intodevelop/befrom
fix/#455/password-validation
Jun 4, 2025
Merged

fix: 잘못된 비밀번호 검증 로직과 잘못된 비밀번호 테스트 수정#467
Zepelown merged 1 commit intodevelop/befrom
fix/#455/password-validation

Conversation

@Zepelown
Copy link
Member

@Zepelown Zepelown commented Jun 1, 2025

#️⃣연관된 이슈

#455

📝작업 내용

  • 잘못된 비밀번호 테스트 코드 수정 : 올바른 비밀번호 테스트 케이스가 실패 케이스에 들어갔었습니다.
  • 비밀번호 검증 개선 : 정규표현식을 더 직관적인 것으로 교체하였습니다.

중점적으로 리뷰받고 싶은 부분(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

논의하고 싶은 부분(선택)

논의하고 싶은 부분이 있다면 작성해주세요.

🫡 참고사항

Summary by CodeRabbit

  • 버그 수정

    • 비밀번호 유효성 검사에서 공백이 포함된 비밀번호를 허용하지 않도록 개선되었습니다.
    • 비밀번호가 비어있거나 null인 경우 유효하지 않도록 동작이 변경되었습니다.
  • 테스트

    • 비밀번호 유효성 검사를 위한 단위 테스트가 추가되어 다양한 비밀번호 조건에 대해 검증이 강화되었습니다.
    • 회원가입 시 비밀번호 조건 테스트 케이스 일부가 조정되었습니다.

@Zepelown Zepelown added ✅ Test test 관련(storybook, jest...) 💾 BE Backend 🛠Fix 기능이 의도한 대로 동작하지 않는 버그를 수정 labels Jun 1, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 1, 2025

Walkthrough

비밀번호 유효성 검사 로직이 강화되어 공백 문자를 명시적으로 허용하지 않도록 정규식이 수정되었고, 숫자 매칭 표현이 변경되었습니다. 비밀번호 유효성 검사기의 null 또는 빈 문자열 처리 방식이 변경되었으며, 이에 맞춘 단위 테스트가 새로 추가되고 기존 테스트 케이스 일부가 조정되었습니다.

Changes

파일/경로 그룹 변경 요약
backend/src/main/java/moadong/global/validator/PasswordValidator.java 비밀번호 정규식에서 공백 미허용 추가, 숫자 매칭 방식 변경, null/빈값 처리 변경, 상수 분리, 파라미터명 변경
backend/src/test/java/moadong/unit/user/PasswordValidatorTest.java PasswordValidator의 다양한 유효/무효 케이스를 검증하는 단위 테스트 신규 추가
backend/src/test/java/moadong/unit/user/UserRegisterTest.java 비밀번호 유효성 실패 케이스에서 "abc1234^" 테스트 케이스 제거

Sequence Diagram(s)

sequenceDiagram
    participant 테스트 as PasswordValidatorTest
    participant Validator as PasswordValidator

    테스트->>Validator: isValid(비밀번호)
    alt 비밀번호가 null 또는 빈 문자열
        Validator-->>테스트: false 반환
    else 정규식 불일치
        Validator-->>테스트: false 반환
    else 정규식 일치
        Validator-->>테스트: true 반환
    end
Loading

Possibly related PRs

Suggested labels

📬 API

Suggested reviewers

  • Due-IT
  • lepitaaar
  • PororoAndFriends
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

github-actions bot commented Jun 1, 2025

Test Results

77 tests   77 ✅  2s ⏱️
12 suites   0 💤
12 files     0 ❌

Results for commit 69e2df0.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
backend/src/test/java/moadong/unit/user/PasswordValidatorTest.java (1)

15-19: 유효한 비밀번호 테스트가 적절합니다.

UserFixture.collectPassword를 사용하여 유효한 비밀번호를 테스트하는 것이 좋습니다. 하지만 테스트 안정성을 위해 고정된 유효한 비밀번호 값도 추가로 테스트하는 것을 고려해보세요.

추가 테스트 케이스 예시:

@Test
void 유효한_비밀번호는_유효하다() {
    boolean isValid = passwordValidator.isValid(UserFixture.collectPassword, null);
    Assertions.assertThat(isValid).isTrue();
+    
+    // 명시적인 유효한 비밀번호 테스트
+    boolean isValidExplicit = passwordValidator.isValid("Abcd1234!", null);
+    Assertions.assertThat(isValidExplicit).isTrue();
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b63016 and 69e2df0.

📒 Files selected for processing (3)
  • backend/src/main/java/moadong/global/validator/PasswordValidator.java (1 hunks)
  • backend/src/test/java/moadong/unit/user/PasswordValidatorTest.java (1 hunks)
  • backend/src/test/java/moadong/unit/user/UserRegisterTest.java (0 hunks)
💤 Files with no reviewable changes (1)
  • backend/src/test/java/moadong/unit/user/UserRegisterTest.java
🔇 Additional comments (3)
backend/src/main/java/moadong/global/validator/PasswordValidator.java (2)

10-11: 정규식 패턴이 크게 개선되었습니다!

새로운 정규식의 주요 개선사항:

  • (?!.*\\s) 추가로 공백 문자를 명시적으로 금지
  • \d[0-9]로 변경하여 더 명확한 숫자 매칭
  • 상수로 추출하여 코드 가독성과 유지보수성 향상

정규식 패턴이 보안 요구사항을 정확히 반영하고 있습니다.


14-16: null/empty 문자열 처리 로직이 올바르게 수정되었습니다.

이전에 null/empty 문자열에 대해 true를 반환했던 것을 false로 변경한 것은 보안상 올바른 결정입니다. 비밀번호 유효성 검사에서 null이나 빈 문자열은 유효하지 않은 입력으로 처리되어야 합니다.

backend/src/test/java/moadong/unit/user/PasswordValidatorTest.java (1)

21-39: 무효한 비밀번호 테스트 케이스가 매우 포괄적입니다!

테스트 케이스들이 정규식의 모든 검증 조건을 훌륭하게 다루고 있습니다:

  • 길이 제한 (너무 짧거나 긴 경우)
  • 문자 조합 요구사항 (영문, 숫자, 특수문자)
  • 공백 문자 금지
  • 허용되지 않은 특수문자 검증

테스트 커버리지가 우수하고 각 케이스에 명확한 주석이 포함되어 있어 이해하기 쉽습니다.

Comment on lines +21 to +39
@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();
}
Copy link
Contributor

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@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();
}
@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();
}
@Test
void null_또는_빈_비밀번호는_유효하지_않다() {
Assertions.assertThat(passwordValidator.isValid(null, null)).isFalse();
Assertions.assertThat(passwordValidator.isValid("", null)).isFalse();
}
🤖 Prompt for AI Agents
In backend/src/test/java/moadong/unit/user/PasswordValidatorTest.java around
lines 21 to 39, the test cases lack coverage for null and empty string inputs,
which are important for validating the updated null/empty handling logic. Add
parameterized test cases for null and empty strings to the existing invalid
password test method or create a separate test method to explicitly assert that
these inputs are considered invalid by the passwordValidator.isValid method.

Copy link
Collaborator

@PororoAndFriends PororoAndFriends left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다

Copy link
Collaborator

@Due-IT Due-IT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정규식을 사용한 검증과 java 함수를 사용한 검증의 차이는 무엇일까요? 왜 정규식을 선택하셨는지도 궁금하네요

@Zepelown
Copy link
Member Author

Zepelown commented Jun 4, 2025

정규식을 사용한 검증과 java 함수를 사용한 검증의 차이는 무엇일까요? 왜 정규식을 선택하셨는지도 궁금하네요

코드를 매우 간단히 만들고자 정규식을 사용하였습니다.
복잡한 패턴을 한 줄에 검사할 수 있다는 장점도 있고요.

@Zepelown Zepelown merged commit 2e36e93 into develop/be Jun 4, 2025
3 checks passed
@Zepelown Zepelown deleted the fix/#455/password-validation branch June 10, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💾 BE Backend 🛠Fix 기능이 의도한 대로 동작하지 않는 버그를 수정 ✅ Test test 관련(storybook, jest...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants