Skip to content

Commit 58252ff

Browse files
authored
Merge pull request #168 from upa-r-upa/fix/sign-up-rule
회원가입 시 비밀번호에 특수문자도 가능하도록 수정
2 parents 3bd8c75 + 0e56ef8 commit 58252ff

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

app/schemas/auth.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
)
1111
from app.schemas.user import UserData
1212

13+
USERNAME_PATTERN = r"^[A-Za-z0-9]+$"
14+
PASSWORD_PATTERN = r"^.+$"
15+
1316

1417
class SignupInput(BaseModel):
1518
username: str
@@ -30,7 +33,7 @@ def username_length(cls: "SignupInput", v: str):
3033
raise ValueError(VALUE_TOO_SHORT)
3134
elif len(v) > 20:
3235
raise ValueError(VALUE_TOO_LONG)
33-
elif not re.match("^[A-Za-z][A-Za-z0-9]*$", v):
36+
elif not re.match(USERNAME_PATTERN, v):
3437
raise ValueError(VALUE_MUST_BE_ALPHANUM)
3538
return v
3639

@@ -40,7 +43,7 @@ def password_length(cls: "SignupInput", v: str):
4043
raise ValueError(VALUE_TOO_SHORT)
4144
elif len(v) > 20:
4245
raise ValueError(VALUE_TOO_LONG)
43-
elif not re.match("^[A-Za-z][A-Za-z0-9]*$", v):
46+
elif not re.match(PASSWORD_PATTERN, v):
4447
raise ValueError(VALUE_MUST_BE_ALPHANUM)
4548
return v
4649

tests/api/endpoints/auth/test_auth.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,60 @@ def test_signup(client: TestClient, session: Session, user_data: UserBase):
2828
assert user.nickname == data.nickname
2929

3030

31+
def test_signup_starting_with_number(client: TestClient, session: Session):
32+
data = SignupInput(
33+
username="123user",
34+
password="123P@ss!",
35+
password_confirm="123P@ss!",
36+
37+
nickname="123닉네임",
38+
)
39+
40+
response = client.post("/auth/signup", json=data.dict())
41+
42+
assert response.status_code == 201
43+
44+
user = session.query(User).filter_by(username=data.username).first()
45+
46+
assert user.username == data.username
47+
assert user.email == data.email
48+
assert user.nickname == data.nickname
49+
50+
51+
def test_signup_with_special_password(client: TestClient, session: Session):
52+
data = SignupInput(
53+
username="testuser",
54+
password="P@ssw0rd!",
55+
password_confirm="P@ssw0rd!",
56+
57+
nickname="닉네임_!@#$%",
58+
)
59+
60+
response = client.post("/auth/signup", json=data.dict())
61+
62+
assert response.status_code == 201
63+
64+
user = session.query(User).filter_by(username=data.username).first()
65+
66+
assert user.username == data.username
67+
assert user.email == data.email
68+
assert user.nickname == data.nickname
69+
70+
71+
def test_signup_with_special_character_in_username_fails(client: TestClient):
72+
data = dict(
73+
username="test!user",
74+
password="password123",
75+
password_confirm="password123",
76+
77+
nickname="테스트유저",
78+
)
79+
80+
response = client.post("/auth/signup", json=data)
81+
82+
assert response.status_code == 422
83+
84+
3185
def test_login(client: TestClient, user_data: UserBase, add_user: User):
3286
data = dict(
3387
username=add_user.username,

0 commit comments

Comments
 (0)