feat: 댓글 신고·차단·약관 동의(관리 스크립트 포함), 구글 로그인(서버·웹·안드로이드 앱), 앱 패키지 kr.o2o.nalssigak·versionCode 1000

This commit is contained in:
minaChoi committed 2026-10-26 09:45:00 +09:00
1 parent fbebdcb796
commit 3f3a3ea039
35 files changed
+1723 -115

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ def anyio_backend():
_VOLATILE = (
"weather_hourly", "weather_daily", "cloud_hourly", "openmeteo_hourly", "air_station", "air_quality", "weather_warning", "sun_time",
"sky_score", "index_score", "post", "post_like", "post_save", "comment", "comment_like", "holiday", "solar_term", "users",
"sky_score", "index_score", "post", "post_like", "post_save", "comment", "comment_like", "comment_report", "user_block", "holiday", "solar_term", "users",
)
+93 -2
View File
@@ -10,8 +10,12 @@ def client():
return AsyncClient(transport=ASGITransport(app=app), base_url="http://test")
async def _signup(c, login_id="mina_01", nickname="망원동주민"):
return (await c.post("/v1/auth/signup", json={"login_id": login_id, "password": "password1", "nickname": nickname})).json()
async def _signup(c, login_id="mina_01", nickname="망원동주민", agree=True):
"""가입하고, 댓글을 쓸 수 있게 이용약관에도 동의한다 (agree=False 면 안 함)."""
body = (await c.post("/v1/auth/signup", json={"login_id": login_id, "password": "password1", "nickname": nickname})).json()
if agree and body.get("access_token"):
await c.post("/v1/auth/terms", headers={"Authorization": f"Bearer {body['access_token']}"})
return body
@pytest.mark.anyio
@@ -149,3 +153,90 @@ async def test_withdraw_deletes_account_and_reactions(offline):
assert p["like_count"] == 0 and p["comment_count"] == 1
# 같은 아이디로 다시 가입할 수 있다
assert (await _signup(c, login_id="mina_bye"))["result"]["success"] is True
def _h(body):
return {"Authorization": f"Bearer {body['access_token']}"}
async def _comment(c, post_id, h, text):
return (await c.post(f"/v1/reaction/post/{post_id}/comment", headers=h, json={"body": text})).json()
async def _bodies(c, post_id, h=None):
return [x["body"] for x in (await c.get(f"/v1/reaction/post/{post_id}/comment/list", headers=h or {})).json()["comments"]]
@pytest.mark.anyio
async def test_comment_needs_terms_agreement(offline):
async with client() as c:
h = _h(await _signup(c, agree=False))
post_id = (await c.get("/v1/feed", params={"region": REGION})).json()["posts"][0]["post_id"]
assert (await c.get("/v1/auth/me", headers=h)).json()["me"]["terms_agreed"] is False
assert (await _comment(c, post_id, h, "안녕"))["result"]["desc"] == "TERMS_REQUIRED"
assert (await c.post("/v1/auth/terms", headers=h)).json()["me"]["terms_agreed"] is True
assert (await _comment(c, post_id, h, "안녕"))["comment"]["body"] == "안녕"
@pytest.mark.anyio
async def test_report_hides_for_reporter_then_for_all_at_three(offline):
async with client() as c:
writer = _h(await _signup(c, "writer_1", "쓴사람"))
r = [_h(await _signup(c, f"reporter_{i}", f"신고자{i}")) for i in range(3)]
post_id = (await c.get("/v1/feed", params={"region": REGION})).json()["posts"][0]["post_id"]
bad = (await _comment(c, post_id, writer, "광고입니다"))["comment"]
url = f"/v1/reaction/comment/{bad['comment_id']}/report"
assert (await c.post(url, headers=writer, json={"reason": 2})).json()["result"]["desc"] == "INVALID_INPUT"
assert (await c.post(url, headers=r[0], json={"reason": 9})).status_code == 422
assert (await c.post(url, headers=r[0], json={"reason": 2})).json()["result"]["success"] is True
assert (await c.post(url, headers=r[0], json={"reason": 2})).json()["result"]["success"] is True # 두 번 신고해도 한 번
assert await _bodies(c, post_id, r[0]) == [] and await _bodies(c, post_id, r[1]) == ["광고입니다"]
await c.post(url, headers=r[1], json={"reason": 1})
assert await _bodies(c, post_id) == ["광고입니다"]
await c.post(url, headers=r[2], json={"reason": 1})
assert await _bodies(c, post_id) == [] and await _bodies(c, post_id, writer) == []
p = next(x for x in (await c.get("/v1/feed", params={"region": REGION})).json()["posts"] if x["post_id"] == post_id)
assert p["comment_count"] == 0
# 숨긴 댓글을 지워도 댓글 수가 한 번 더 줄지 않는다
assert (await c.delete(f"/v1/reaction/comment/{bad['comment_id']}", headers=writer)).json()["result"]["success"] is True
p = next(x for x in (await c.get("/v1/feed", params={"region": REGION})).json()["posts"] if x["post_id"] == post_id)
assert p["comment_count"] == 0
@pytest.mark.anyio
async def test_block_hides_author_comments_and_can_be_undone(offline):
async with client() as c:
me = _h(await _signup(c))
other = _h(await _signup(c, "rude_1", "무례한"))
post_id = (await c.get("/v1/feed", params={"region": REGION})).json()["posts"][0]["post_id"]
rude = (await _comment(c, post_id, other, "흥"))["comment"]
mine = (await _comment(c, post_id, me, "좋아요"))["comment"]
assert (await c.post(f"/v1/reaction/comment/{mine['comment_id']}/block", headers=me)).json()["result"]["desc"] == "INVALID_INPUT"
assert (await c.post(f"/v1/reaction/comment/{rude['comment_id']}/block")).status_code == 401
assert (await c.post(f"/v1/reaction/comment/{rude['comment_id']}/block", headers=me)).json()["result"]["success"] is True
assert await _bodies(c, post_id, me) == ["좋아요"] and await _bodies(c, post_id) == ["흥", "좋아요"]
blocked = (await c.get("/v1/reaction/block/list", headers=me)).json()["users"]
assert [u["nickname"] for u in blocked] == ["무례한"]
assert (await c.delete(f"/v1/reaction/block/{blocked[0]['user_id']}", headers=me)).json()["result"]["success"] is True
assert (await c.delete(f"/v1/reaction/block/{blocked[0]['user_id']}", headers=me)).json()["result"]["desc"] == "NOT_FOUND"
assert await _bodies(c, post_id, me) == ["흥", "좋아요"]
@pytest.mark.anyio
async def test_withdraw_removes_reports_and_blocks(offline):
async with client() as c:
leaver = _h(await _signup(c, "leaver_1", "떠날사람"))
stay = _h(await _signup(c, "stay_1", "남는사람"))
post_id = (await c.get("/v1/feed", params={"region": REGION})).json()["posts"][0]["post_id"]
kept = (await _comment(c, post_id, stay, "남아요"))["comment"]
gone = (await _comment(c, post_id, leaver, "떠나요"))["comment"]
await c.post(f"/v1/reaction/comment/{kept['comment_id']}/report", headers=leaver, json={"reason": 4})
await c.post(f"/v1/reaction/comment/{kept['comment_id']}/block", headers=leaver)
await c.post(f"/v1/reaction/comment/{gone['comment_id']}/block", headers=stay)
assert (await c.delete("/v1/auth/me", headers=leaver)).json()["result"]["success"] is True
assert (await c.get("/v1/reaction/block/list", headers=stay)).json()["users"] == []
assert await _bodies(c, post_id, stay) == ["남아요"]
+80
View File
@@ -0,0 +1,80 @@
import time
import pytest
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from httpx import ASGITransport, AsyncClient
from jose import jwk, jwt
import common.google_id as google_id
import services.auth_service as auth_service
from config.settings import settings
from router.router import app
CLIENT_ID = "test-client.apps.googleusercontent.com"
def client():
return AsyncClient(transport=ASGITransport(app=app), base_url="http://test")
@pytest.fixture
def google_keys(monkeypatch):
"""가짜 구글 서명키. 공개키는 _keys 대신 돌려준다."""
monkeypatch.setattr(settings, "google_client_id", CLIENT_ID)
key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
pem = key.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption())
public = jwk.construct(key.public_key().public_bytes(serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo), "RS256").to_dict()
public["kid"] = "k1"
async def keys(force: bool = False):
return [public]
monkeypatch.setattr(google_id, "_keys", keys)
def sign(**over):
claims = {"iss": "https://accounts.google.com", "aud": CLIENT_ID, "sub": "1234567890", "exp": int(time.time()) + 600, "iat": int(time.time()), "name": "홍길동", "email": "a@example.com"}
claims.update(over)
return jwt.encode(claims, pem, algorithm="RS256", headers={"kid": "k1"})
return sign
@pytest.mark.anyio
async def test_verify_accepts_only_our_valid_tokens(google_keys):
assert await google_id.verify(google_keys()) == "1234567890"
assert await google_id.verify(google_keys(aud="other.apps.googleusercontent.com")) is None
assert await google_id.verify(google_keys(iss="https://evil.example")) is None
assert await google_id.verify(google_keys(exp=int(time.time()) - 10)) is None
assert await google_id.verify(google_keys()[:-4] + "abcd") is None
@pytest.mark.anyio
async def test_google_login_creates_once_with_auto_nickname_and_no_real_name(google_keys):
async with client() as c:
first = (await c.post("/v1/auth/google", json={"credential": google_keys()})).json()
assert first["access_token"] and first["me"]["provider"] == 2
nick = first["me"]["nickname"]
assert "홍길동" not in nick and "@" not in nick
again = (await c.post("/v1/auth/google", json={"credential": google_keys()})).json()
assert again["me"]["nickname"] == nick and again["me"]["login_id"] == first["me"]["login_id"]
other = (await c.post("/v1/auth/google", json={"credential": google_keys(sub="999")})).json()
assert other["me"]["login_id"] != first["me"]["login_id"]
bad = (await c.post("/v1/auth/google", json={"credential": google_keys(aud="x")})).json()
assert bad["result"]["desc"] == "AUTH_FAILED"
me = (await c.get("/v1/auth/me", headers={"Authorization": f"Bearer {first['access_token']}"})).json()["me"]
assert me["nickname"] == nick
@pytest.mark.anyio
async def test_config_exposes_client_id_only_when_set(monkeypatch):
async with client() as c:
monkeypatch.setattr(settings, "google_client_id", "")
assert "google_client_id" not in (await c.get("/v1/auth/config")).json()
monkeypatch.setattr(settings, "google_client_id", CLIENT_ID)
assert (await c.get("/v1/auth/config")).json()["google_client_id"] == CLIENT_ID
def test_auto_nickname_fits_nickname_rule():
for _ in range(50):
assert auth_service.NICKNAME.match(auth_service.auto_nickname())
+1
View File
@@ -84,6 +84,7 @@ async def test_like_in_one_sido_not_seen_in_another(offline):
async with client() as c:
token = (await c.post("/v1/auth/signup", json={"login_id": "scope_01", "password": "password1", "nickname": "시도테스트"})).json()["access_token"]
h = {"Authorization": f"Bearer {token}"}
await c.post("/v1/auth/terms", headers=h)
seoul = (await c.get("/v1/feed", params={"region": SEOUL_A}, headers=h)).json()
post_id = next(p["post_id"] for p in seoul["posts"] if p["post_type"] == PostType.WEATHER.value)
assert (await c.post(f"/v1/reaction/post/{post_id}/like", headers=h)).json()["like_count"] == 1