Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed backend/__pycache__/jules_engine.cpython-312.pyc
Binary file not shown.
Binary file removed backend/__pycache__/main.cpython-312.pyc
Binary file not shown.
Binary file removed backend/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file not shown.
14 changes: 13 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
from models import UserScan, SHOPIFY_INVENTORY
from models import UserScan, StaffLogin, SHOPIFY_INVENTORY
from jules_engine import get_jules_advice

# Load .env file
Expand All @@ -28,6 +28,7 @@

# 🛡️ Configuración Maestra (abvetos.com) - Secrets moved to environment variables
SECRET_KEY = os.getenv("LVT_SECRET_KEY", "DEVELOPMENT_SECRET_DO_NOT_USE_IN_PROD")
STAFF_PASSWORD = os.getenv("STAFF_PASSWORD", "DEVELOPMENT_STAFF_PASS_DO_NOT_USE_IN_PROD")
PATENT = "PCT/EP2025/067317"

def verify_auth(user_id: str, token: str) -> bool:
Expand All @@ -49,6 +50,17 @@ def calculate_fit(user_waist: float, item_id: str):
is_perfect = 0.95 <= fit_index <= 1.05
return is_perfect, round(fit_index, 3), item

@app.post("/api/verify-staff")
async def verify_staff(login: StaffLogin):
"""
🛡️ Secure staff verification using hmac.compare_digest
to prevent timing attacks.
"""
if hmac.compare_digest(login.password.encode(), STAFF_PASSWORD.encode()):
return {"status": "SUCCESS", "message": "Acceso concedido"}
else:
raise HTTPException(status_code=401, detail="Acceso denegado")

@app.post("/api/recommend")
async def recommend_garment(scan: UserScan, garment_id: str = "BALMAIN_SS26_SLIM"):
# 1. Seguridad y Handshake
Expand Down
3 changes: 3 additions & 0 deletions backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class UserScan(BaseModel):
waist: float
event_type: str # e.g., 'Gala', 'Business', 'Cocktail'

class StaffLogin(BaseModel):
password: str

class Garment(BaseModel):
id: str
name: str
Expand Down
Binary file not shown.
34 changes: 34 additions & 0 deletions backend/tests/test_staff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from fastapi.testclient import TestClient
from backend.main import app
import os

client = TestClient(app)

def test_verify_staff_success(monkeypatch):
# Set a known staff password for testing
monkeypatch.setenv("STAFF_PASSWORD", "TEST_STAFF_PASS")
# Reload the app's STAFF_PASSWORD from env
import backend.main
monkeypatch.setattr(backend.main, "STAFF_PASSWORD", "TEST_STAFF_PASS")

response = client.post("/api/verify-staff", json={"password": "TEST_STAFF_PASS"})
assert response.status_code == 200
assert response.json()["status"] == "SUCCESS"

def test_verify_staff_failure(monkeypatch):
monkeypatch.setenv("STAFF_PASSWORD", "TEST_STAFF_PASS")
import backend.main
monkeypatch.setattr(backend.main, "STAFF_PASSWORD", "TEST_STAFF_PASS")

response = client.post("/api/verify-staff", json={"password": "WRONG_PASSWORD"})
assert response.status_code == 401
assert response.json()["detail"] == "Acceso denegado"

def test_verify_staff_empty_password(monkeypatch):
monkeypatch.setenv("STAFF_PASSWORD", "TEST_STAFF_PASS")
import backend.main
monkeypatch.setattr(backend.main, "STAFF_PASSWORD", "TEST_STAFF_PASS")

response = client.post("/api/verify-staff", json={"password": ""})
assert response.status_code == 401
Comment on lines +1 to +34
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test setup logic is repeated across all test functions. This can be refactored into a single pytest fixture with autouse=True to reduce code duplication and improve maintainability.

Additionally, test_verify_staff_empty_password is missing an assertion to verify the response body. I've added it to make the test more robust and consistent with the other failure case.

import pytest
from fastapi.testclient import TestClient
from backend.main import app
import os

client = TestClient(app)

@pytest.fixture(autouse=True)
def mock_staff_password(monkeypatch):
    """Mocks the staff password for the duration of the tests."""
    test_password = "TEST_STAFF_PASS"
    monkeypatch.setenv("STAFF_PASSWORD", test_password)
    # Since the env var is read at module load, we also need to patch the variable in the imported module.
    import backend.main
    monkeypatch.setattr(backend.main, "STAFF_PASSWORD", test_password)

def test_verify_staff_success():
    response = client.post("/api/verify-staff", json={"password": "TEST_STAFF_PASS"})
    assert response.status_code == 200
    assert response.json()["status"] == "SUCCESS"

def test_verify_staff_failure():
    response = client.post("/api/verify-staff", json={"password": "WRONG_PASSWORD"})
    assert response.status_code == 401
    assert response.json()["detail"] == "Acceso denegado"

def test_verify_staff_empty_password():
    response = client.post("/api/verify-staff", json={"password": ""})
    assert response.status_code == 401
    assert response.json()["detail"] == "Acceso denegado"

29 changes: 22 additions & 7 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,29 @@ class TryOnYouBunker {
modal.style.display = 'none';
}

verifyPrivatePass() {
async verifyPrivatePass() {
const input = document.getElementById('private-pass-input');
if (input.value === "SAC_MUSEUM_2026") {
this.showNotification('ACCESO CONCEDIDO', 'success');
setTimeout(() => { window.location.href = "/staff-dashboard"; }, 1500);
} else {
this.showNotification('ACCESO DENEGADO', 'error');
input.value = "";
const password = input.value;

try {
const response = await fetch('/api/verify-staff', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ password })
});

if (response.ok) {
this.showNotification('ACCESO CONCEDIDO', 'success');
setTimeout(() => { window.location.href = "/staff-dashboard"; }, 1500);
} else {
this.showNotification('ACCESO DENEGADO', 'error');
input.value = "";
}
} catch (error) {
console.error('Staff verification failed:', error);
this.showNotification('BUNKER OFFLINE', 'error');
}
}
}
Expand Down
Binary file removed verification/collection.png
Binary file not shown.
Binary file removed verification/consultation.png
Binary file not shown.
Binary file removed verification/full_page.png
Binary file not shown.
Binary file removed verification/jules_form_verification.png
Binary file not shown.
29 changes: 0 additions & 29 deletions verification/verify_jules_form.py

This file was deleted.

42 changes: 0 additions & 42 deletions verification/verify_tryonyou.py

This file was deleted.

12 changes: 12 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'vite';

export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
},
},
},
});