feat: 10/20 회의 반영 — 이야기 탭을 오늘 피드로 합침(글쓰기 칸·사진 올리기·위치 정보 삭제), 오늘의 각 카드와 히어로·각 공유 템플릿, 나만의 각을 이름+날씨 조건 저장으로, 로그인 없이 좋아요(IP 해시), 피드 순서·불쾌지수 상시·포스트 그림 배경, 새 각 아이콘
This commit is contained in:
1 parent
017022a0b0
commit
d0213f41a6
81 files changed
+3503
-593
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import io
|
||||
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
from PIL import Image
|
||||
|
||||
from router.router import app
|
||||
|
||||
REGION = "1144000000"
|
||||
GPS_IFD = 0x8825
|
||||
|
||||
|
||||
def client():
|
||||
return AsyncClient(transport=ASGITransport(app=app), base_url="http://test")
|
||||
|
||||
|
||||
async def _login(c, login_id: str) -> dict:
|
||||
body = (await c.post("/v1/auth/signup", json={"login_id": login_id, "password": "password1", "nickname": login_id})).json()
|
||||
return {"Authorization": f"Bearer {body['access_token']}"}
|
||||
|
||||
|
||||
def _jpeg_with_gps(w: int = 2400, h: int = 1600) -> bytes:
|
||||
exif = Image.Exif()
|
||||
exif[0x010F] = "PhoneMaker"
|
||||
exif[GPS_IFD] = {1: "N", 2: (37.0, 33.0, 0.0), 3: "E", 4: (126.0, 58.0, 0.0)}
|
||||
buf = io.BytesIO()
|
||||
Image.new("RGB", (w, h), (120, 180, 230)).save(buf, "JPEG", exif=exif)
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_upload_strips_location_resizes_and_attaches_to_talk():
|
||||
src = _jpeg_with_gps()
|
||||
assert Image.open(io.BytesIO(src)).getexif().get_ifd(GPS_IFD)
|
||||
async with client() as c:
|
||||
assert (await c.post("/v1/talk/image", files={"file": ("a.jpg", src, "image/jpeg")})).status_code == 401
|
||||
h = await _login(c, "photo_01")
|
||||
url = (await c.post("/v1/talk/image", files={"file": ("a.jpg", src, "image/jpeg")}, headers=h)).json()["image"]
|
||||
got = await c.get(url)
|
||||
assert got.status_code == 200 and got.headers["content-type"] == "image/webp"
|
||||
img = Image.open(io.BytesIO(got.content))
|
||||
assert max(img.size) == 1080
|
||||
assert not img.getexif()
|
||||
talk = (await c.post("/v1/talk", json={"region_code": REGION, "body": "하늘 사진", "image": url}, headers=h)).json()["talk"]
|
||||
assert talk["image"] == url
|
||||
listed = (await c.get("/v1/talk/list")).json()["talks"][0]
|
||||
assert listed["image"] == url
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_rejects_non_images_and_foreign_paths():
|
||||
async with client() as c:
|
||||
h = await _login(c, "photo_02")
|
||||
bad = (await c.post("/v1/talk/image", files={"file": ("a.txt", b"not an image", "text/plain")}, headers=h)).json()
|
||||
assert bad["result"]["desc"] == "INVALID_INPUT"
|
||||
for image in ("https://evil.example/a.webp", "/v1/talk/image/../../etc/passwd", "/v1/talk/image/" + "0" * 32 + ".webp"):
|
||||
res = (await c.post("/v1/talk", json={"region_code": REGION, "body": "안녕", "image": image}, headers=h)).json()
|
||||
assert res["result"]["desc"] == "INVALID_INPUT"
|
||||
assert (await c.get("/v1/talk/image/" + "0" * 32 + ".webp")).status_code == 404
|
||||
Reference in new issue
Block a user