forked from mtusi2026/mtusi2026lab2
rollback-тесты на urllib из-за нестабильности httpx через docker-proxy на win
This commit is contained in:
+5
-3
@@ -16,7 +16,7 @@ SESSION_TTL = int(os.getenv("SESSION_TTL_SECONDS", "3600"))
|
||||
|
||||
def _prehash(password: str) -> bytes:
|
||||
# bcrypt работает с ≤72 байт, SHA-256 даёт 32 байта и снимает ограничение
|
||||
return hashlib.sha256(password.encode("utf-8")).digest()
|
||||
return hashlib.sha256(password.encode("utf-8")).hexdigest().encode("ascii")
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
@@ -72,7 +72,9 @@ async def revoke_current_session(authorization: str, db: AsyncSession) -> None:
|
||||
if not authorization or not authorization.startswith("Bearer "):
|
||||
raise _unauthorized_bearer()
|
||||
token = authorization[7:]
|
||||
await db.execute(
|
||||
result = await db.execute(
|
||||
delete(SessionRow).where(SessionRow.token_hash == hash_token(token))
|
||||
)
|
||||
await db.commit()
|
||||
await db.commit()
|
||||
if result.rowcount == 0:
|
||||
raise _unauthorized_bearer()
|
||||
+21
-13
@@ -10,20 +10,28 @@ from ..db.models import Chat, ChatMember, User
|
||||
async def create_atomic(
|
||||
db: AsyncSession, title: str, member_ids: list[UUID]
|
||||
) -> Chat:
|
||||
async with db.begin():
|
||||
found = (
|
||||
(await db.execute(select(User.id).where(User.id.in_(member_ids))))
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
if len(set(found)) != len(set(member_ids)):
|
||||
raise ValueError("member_not_found")
|
||||
# проверка всех участников
|
||||
found = (
|
||||
(await db.execute(select(User.id).where(User.id.in_(member_ids))))
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
if len(set(found)) != len(set(member_ids)):
|
||||
await db.rollback()
|
||||
raise ValueError("member_not_found")
|
||||
|
||||
chat = Chat(title=title)
|
||||
db.add(chat)
|
||||
await db.flush()
|
||||
for uid in member_ids:
|
||||
db.add(ChatMember(chat_id=chat.id, user_id=uid))
|
||||
chat = Chat(title=title)
|
||||
db.add(chat)
|
||||
await db.flush() # получить chat.id
|
||||
|
||||
for uid in member_ids:
|
||||
db.add(ChatMember(chat_id=chat.id, user_id=uid))
|
||||
|
||||
try:
|
||||
await db.commit()
|
||||
except Exception:
|
||||
await db.rollback()
|
||||
raise
|
||||
|
||||
await db.refresh(chat)
|
||||
return chat
|
||||
|
||||
Reference in New Issue
Block a user