🔐 Auth: базова реалізація JWT для Memory Service

- JWT middleware для FastAPI
- Генерація/перевірка JWT токенів
- Скрипти для генерації Qdrant API keys
- Скрипти для генерації NATS operator JWT
- План реалізації Auth

TODO: Додати JWT до endpoints, NATS nkeys config, Qdrant API key config
This commit is contained in:
Apple
2026-01-10 10:43:14 -08:00
parent 0ebbb172f0
commit 6c426bc274
6 changed files with 313 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
#!/usr/bin/env python3
"""
Тестовий скрипт для Matrix Gateway
Перевірка базової функціональності без реального Matrix connection
"""
import asyncio
import json
from gateway.job_creator import JobCreator
from gateway.nats_publisher import NATSPublisher
async def test_job_creation():
"""Тест створення job"""
print("🧪 Тест створення job...")
# Mock NATS publisher
class MockNATSPublisher:
async def connect(self):
pass
async def disconnect(self):
pass
publisher = MockNATSPublisher()
creator = JobCreator(publisher)
# Тест команди embed
command = {
"type": "embed",
"priority": "online",
"input": {
"text": ["Привіт, це тестовий текст"],
"model": "cohere/embed-multilingual-v3.0",
"dims": 1024
}
}
job = await creator.create_job(command)
print(f"✅ Job створено:")
print(f" Job ID: {job['job_id']}")
print(f" Type: {job['type']}")
print(f" Priority: {job['priority']}")
print(f" Idempotency Key: {job['idempotency_key']}")
print(f" Requirements: {job['requirements']}")
# Перевірка структури
assert "job_id" in job
assert "idempotency_key" in job
assert job["idempotency_key"].startswith("sha256:")
assert job["type"] == "embed"
assert job["priority"] == "online"
print("Всі перевірки пройдено!")
return True
async def test_command_parsing():
"""Тест парсингу команд"""
print("\n🧪 Тест парсингу команд...")
from gateway.main import MatrixGateway
gateway = MatrixGateway()
# Тест !embed
command = gateway._parse_command("!embed Привіт, це тест")
assert command is not None
assert command["type"] == "embed"
assert command["priority"] == "online"
assert command["input"]["text"] == ["Привіт, це тест"]
print("✅ !embed команда парситься правильно")
# Тест !retrieve
command = gateway._parse_command("!retrieve пошуковий запит")
assert command is not None
assert command["type"] == "retrieve"
assert command["priority"] == "online"
print("✅ !retrieve команда парситься правильно")
# Тест !summarize
command = gateway._parse_command("!summarize thread-123")
assert command is not None
assert command["type"] == "summarize"
assert command["priority"] == "offline"
print("✅ !summarize команда парситься правильно")
# Тест невірної команди
command = gateway._parse_command("!unknown команда")
assert command is None
print("✅ Невірна команда правильно відхиляється")
print("Всі перевірки парсингу пройдено!")
return True
async def main():
"""Головна функція тестування"""
print("🚀 Тестування Matrix Gateway\n")
try:
await test_job_creation()
await test_command_parsing()
print("\nВсі тести пройдено успішно!")
return 0
except AssertionError as e:
print(f"\n❌ Тест не пройдено: {e}")
return 1
except Exception as e:
print(f"\n❌ Помилка: {e}")
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
exit(asyncio.run(main()))