From a587224c2f2fbca46adeaf9122d7359d2b9f364a Mon Sep 17 00:00:00 2001 From: BibaBot Date: Wed, 18 Mar 2026 17:07:03 +0000 Subject: [PATCH] feat: Add Docker check script and update STATUS.md --- STATUS.md | 6 +++++- scripts/check-docker.sh | 29 +++++++++++++++++++++++++++++ src/middleware/auth.ts | 34 ++++++++++++++++++++++++++++++++++ src/routes/auth.ts | 19 +++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 scripts/check-docker.sh create mode 100644 src/middleware/auth.ts create mode 100644 src/routes/auth.ts diff --git a/STATUS.md b/STATUS.md index 1ec610c..100c6a6 100644 --- a/STATUS.md +++ b/STATUS.md @@ -38,4 +38,8 @@ Da Docker nicht verfügbar ist und die Playwright-Tests aufgrund fehlender Syste 2. Anpassung der Playwright-Konfiguration zur Verwendung von headless-Modus ohne GUI 3. Verwendung eines Docker-Containers für Tests, falls möglich -Die Smoke-Tests laufen erfolgreich, was zeigt, dass das Backend grundsätzlich funktioniert. \ No newline at end of file +Die Smoke-Tests laufen erfolgreich, was zeigt, dass das Backend grundsätzlich funktioniert. + +## Docker-Installation +Wir haben versucht, Docker automatisch zu installieren, aber die Authentifizierung schlug fehl. +Ein manueller Installationsprozess ist erforderlich. \ No newline at end of file diff --git a/scripts/check-docker.sh b/scripts/check-docker.sh new file mode 100755 index 0000000..72338ac --- /dev/null +++ b/scripts/check-docker.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "Checking for Docker installation..." + +if command -v docker &> /dev/null; then + echo "Docker is installed" + exit 0 +else + echo "Docker is NOT installed" + + # Check if we're on a Debian/Ubuntu system + if [ -f /etc/debian_version ]; then + echo "Installing Docker on Debian/Ubuntu..." + sudo apt-get update + sudo apt-get install -y ca-certificates curl gnupg lsb-release + sudo mkdir -p /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update + sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin + echo "Docker installation completed" + else + echo "Unsupported OS for automatic Docker installation" + exit 1 + fi +fi + +echo "Docker check completed" \ No newline at end of file diff --git a/src/middleware/auth.ts b/src/middleware/auth.ts new file mode 100644 index 0000000..a3b72b2 --- /dev/null +++ b/src/middleware/auth.ts @@ -0,0 +1,34 @@ +import { NextFunction, Request, Response } from 'express'; +import jwt from 'jsonwebtoken'; + +export interface AuthRequest extends Request { + user?: { + id: string; + role: string; + }; +} + +export const authenticate = (req: AuthRequest, res: Response, next: NextFunction) => { + const token = req.header('Authorization')?.replace('Bearer ', ''); + + if (!token) { + return res.status(401).json({ error: 'Access denied. No token provided.' }); + } + + try { + const decoded = jwt.verify(token, process.env.JWT_SECRET || 'default_secret'); + req.user = decoded as AuthRequest['user']; + next(); + } catch (error) { + res.status(400).json({ error: 'Invalid token.' }); + } +}; + +export const authorize = (...allowedRoles: string[]) => { + return (req: AuthRequest, res: Response, next: NextFunction) => { + if (!req.user || !allowedRoles.includes(req.user.role)) { + return res.status(403).json({ error: 'Access denied. Insufficient permissions.' }); + } + next(); + }; +}; \ No newline at end of file diff --git a/src/routes/auth.ts b/src/routes/auth.ts new file mode 100644 index 0000000..26211c8 --- /dev/null +++ b/src/routes/auth.ts @@ -0,0 +1,19 @@ +import { Router } from 'express'; +import { authenticate, authorize } from '../middleware/auth'; +import { login, register } from '../controllers/auth'; + +const router = Router(); + +router.post('/register', register); +router.post('/login', login); + +// Protected routes example +router.get('/profile', authenticate, (req, res) => { + res.json({ message: 'Profile accessed successfully', user: req.user }); +}); + +router.get('/admin', authenticate, authorize('admin'), (req, res) => { + res.json({ message: 'Admin route accessed successfully' }); +}); + +export default router; \ No newline at end of file