From 08cb1cbfd41abaeb90a5cb07152545295321e2f8 Mon Sep 17 00:00:00 2001 From: Dima Date: Wed, 23 Sep 2026 21:38:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20Compose-=D1=81=D1=82=D0=B5=D0=BD=D0=B4=20=D0=B8=20?= =?UTF-8?q?=D1=81=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 12 ++++-------- .gitattributes | 1 + Makefile | 5 ++++- compose.yaml | 34 ++++++++++++++++++++++++++++++++++ tests/session_expiry.py | 18 ++++++++++++++++++ 5 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 .gitattributes create mode 100644 compose.yaml create mode 100644 tests/session_expiry.py diff --git a/.env.example b/.env.example index 714c8076..1a20e778 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,7 @@ # Copy to .env for your LOCAL synthetic test environment; never commit .env. # These are logical interface suggestions; map actual framework names in REPORT.md. -APP_HOST=0.0.0.0 -APP_PORT=8080 -APP_ENV=lab +POSTGRES_DB=messenger +POSTGRES_USER=messenger +# Replace with a random local value before starting Compose. +POSTGRES_PASSWORD=replace-with-local-random-password SESSION_TTL_SECONDS=3600 -# Choose credentials locally. File paths contain no secret values. -DATABASE_URL_FILE=/run/secrets/database_url -# Optional on 3, required use on 4 in lab2; Redis OR Valkey: -SESSION_STORE=postgres -CACHE_URL_FILE=/run/secrets/cache_url diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..dfdb8b77 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/Makefile b/Makefile index 9ecb223e..0c498d93 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CA_FILE ?= ACTION_SCRIPT ?= TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",) -.PHONY: help check validate test load test-persistence +.PHONY: help check validate unit test load test-persistence help: @echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes" @@ -15,6 +15,9 @@ check: validate: $(PYTHON) scripts/validate_openapi.py +unit: + go test ./... + test: $(PYTHON) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS) diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..a9811f07 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,34 @@ +services: + db: + image: postgres:16.10-bookworm + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 3s + timeout: 3s + retries: 20 + api: + build: . + environment: + APP_HOST: 0.0.0.0 + APP_PORT: 8080 + SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} + DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable + ports: + - "127.0.0.1:8080:8080" + depends_on: + db: + condition: service_healthy + healthcheck: + test: ["CMD", "./healthcheck"] + interval: 5s + timeout: 3s + retries: 20 + +volumes: + postgres_data: diff --git a/tests/session_expiry.py b/tests/session_expiry.py new file mode 100644 index 00000000..e155c83b --- /dev/null +++ b/tests/session_expiry.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +"""Run against a test stack configured with SESSION_TTL_SECONDS=2.""" +import time +from client import Client, arguments, check, run + + +def main(): + args = arguments('Check that a short lived session expires') + client = Client(args.base_url, args.ca_file) + actor = client.user('expiry') + client.call('GET', '/api/v1/users/me', actor=actor, schema='User') + time.sleep(3) + client.call('GET', '/api/v1/users/me', 401, actor=actor) + print('PASS: expired Bearer token was rejected') + + +if __name__ == '__main__': + run(main)