feat: add branded login.html with PAM/password mode detection

- Create muxplex/frontend/login.html with:
  - POST form targeting /login with password autocomplete='current-password'
  - Wordmark img referencing /wordmark-on-dark.svg
  - Hidden username field shown in PAM mode via window.MUXPLEX_AUTH
  - Error banner shown when ?error=1 query param is present
  - Inline dark-theme CSS with design token variables (--bg, --accent, etc.)
  - Inline <script> reading window.MUXPLEX_AUTH for auth mode detection

- Add 6 login tests to muxplex/tests/test_frontend_html.py:
  - test_login_html_exists
  - test_login_html_has_form
  - test_login_html_has_password_autocomplete
  - test_login_html_has_wordmark
  - test_login_html_references_muxplex_auth
  - test_login_html_has_error_display

All 6 tests pass. Existing 15 index.html tests unaffected.

Co-authored-by: Amplifier <amplifier@amplified.dev>
This commit is contained in:
Brian Krabach
2026-03-28 22:13:14 -07:00
parent dd0507d8e1
commit d5ffced6a5
2 changed files with 254 additions and 0 deletions
+192
View File
@@ -0,0 +1,192 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sign in — muxplex</title>
<style>
:root {
--bg: #0D1117;
--surface: #161B22;
--border: #30363D;
--text: #E6EDF3;
--text-muted: #8B949E;
--accent: #00D9F5;
--accent-dim: #0096A8;
--error-bg: #3D1515;
--error-border: #7A2020;
--error-text: #FF7B7B;
--input-bg: #0D1117;
--radius: 6px;
}
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.login-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 2rem;
width: 100%;
max-width: 360px;
}
.login-wordmark {
text-align: center;
margin-bottom: 1.5rem;
}
.login-wordmark img {
height: 28px;
}
.error-banner {
display: none;
background: var(--error-bg);
border: 1px solid var(--error-border);
border-radius: var(--radius);
color: var(--error-text);
font-size: 0.875rem;
padding: 0.625rem 0.75rem;
margin-bottom: 1rem;
}
.error-banner.visible {
display: block;
}
.field {
margin-bottom: 1rem;
}
.field label {
display: block;
font-size: 0.8125rem;
font-weight: 600;
color: var(--text-muted);
margin-bottom: 0.375rem;
text-transform: uppercase;
letter-spacing: 0.04em;
}
.field input {
width: 100%;
background: var(--input-bg);
border: 1px solid var(--border);
border-radius: var(--radius);
color: var(--text);
font-size: 0.9375rem;
padding: 0.5rem 0.75rem;
outline: none;
transition: border-color 0.15s ease;
}
.field input:focus {
border-color: var(--accent);
}
.field-username {
display: none;
}
.field-username.visible {
display: block;
}
.login-btn {
width: 100%;
background: var(--accent);
border: none;
border-radius: var(--radius);
color: #0D1117;
cursor: pointer;
font-size: 0.9375rem;
font-weight: 700;
padding: 0.625rem 1rem;
margin-top: 0.5rem;
transition: background 0.15s ease;
}
.login-btn:hover {
background: var(--accent-dim);
}
</style>
</head>
<body>
<div class="login-card">
<div class="login-wordmark">
<img src="/wordmark-on-dark.svg" alt="muxplex" />
</div>
<div id="error-banner" class="error-banner" role="alert" aria-live="assertive">
Incorrect credentials. Please try again.
</div>
<form method="post" action="/login">
<div class="field field-username" id="username-field">
<label for="username">Username</label>
<input
id="username"
name="username"
type="text"
autocomplete="username"
placeholder="username"
/>
</div>
<div class="field">
<label for="password">Password</label>
<input
id="password"
name="password"
type="password"
autocomplete="current-password"
placeholder="••••••••"
required
/>
</div>
<button type="submit" class="login-btn">Sign in</button>
</form>
</div>
<script>
(function () {
// Auth mode injection point — server sets window.MUXPLEX_AUTH before this script runs.
// Shape: { mode: 'pam' | 'password', user: string | null }
var auth = window.MUXPLEX_AUTH || { mode: 'password', user: null };
// Show username field when auth mode is PAM (requires system username).
if (auth.mode === 'pam') {
var usernameField = document.getElementById('username-field');
if (usernameField) {
usernameField.classList.add('visible');
}
}
// Show error banner when ?error=1 is present in the URL query string.
var params = new URLSearchParams(window.location.search);
if (params.get('error') === '1') {
var banner = document.getElementById('error-banner');
if (banner) {
banner.classList.add('visible');
}
}
})();
</script>
</body>
</html>
+62
View File
@@ -5,6 +5,7 @@ import pathlib
from bs4 import BeautifulSoup, Tag from bs4 import BeautifulSoup, Tag
HTML_PATH = pathlib.Path(__file__).parent.parent / "frontend" / "index.html" HTML_PATH = pathlib.Path(__file__).parent.parent / "frontend" / "index.html"
LOGIN_PATH = pathlib.Path(__file__).parent.parent / "frontend" / "login.html"
# Parse once per module — tests are read-only so sharing is safe. # Parse once per module — tests are read-only so sharing is safe.
_SOUP: BeautifulSoup = BeautifulSoup(HTML_PATH.read_text(), "html.parser") _SOUP: BeautifulSoup = BeautifulSoup(HTML_PATH.read_text(), "html.parser")
@@ -263,3 +264,64 @@ def test_html_element_classes() -> None:
assert expected_class in classes, ( assert expected_class in classes, (
f"#{el_id} is missing class '{expected_class}'{reason}. Has: {classes}" f"#{el_id} is missing class '{expected_class}'{reason}. Has: {classes}"
) )
# ── Login page tests ─────────────────────────────────────────────────────────
def _get_login_soup() -> BeautifulSoup:
"""Load and parse login.html — raises FileNotFoundError if file is missing."""
return BeautifulSoup(LOGIN_PATH.read_text(), "html.parser")
def test_login_html_exists() -> None:
"""login.html must exist in the frontend directory."""
assert LOGIN_PATH.exists(), f"Missing login.html at {LOGIN_PATH}"
def test_login_html_has_form() -> None:
"""login.html must have a <form> that POSTs to /login."""
soup = _get_login_soup()
form = soup.find("form")
assert form is not None, "Missing <form> element in login.html"
method = str(form.get("method", "")).lower() # type: ignore[union-attr]
assert method == "post", f"Form method must be 'post', got: {method!r}"
action = str(form.get("action", "")) # type: ignore[union-attr]
assert action == "/login", f"Form action must be '/login', got: {action!r}"
def test_login_html_has_password_autocomplete() -> None:
"""Password input must have autocomplete='current-password'."""
soup = _get_login_soup()
pw = soup.find("input", attrs={"type": "password"})
assert pw is not None, "Missing <input type='password'> in login.html"
ac = str(pw.get("autocomplete", "")) # type: ignore[union-attr]
assert ac == "current-password", (
f"Password input must have autocomplete='current-password', got: {ac!r}"
)
def test_login_html_has_wordmark() -> None:
"""login.html must include an <img> whose src contains 'wordmark'."""
soup = _get_login_soup()
imgs = soup.find_all("img")
srcs = [str(img.get("src", "")) for img in imgs]
assert any("wordmark" in s for s in srcs), (
f"No <img> with src containing 'wordmark' found; srcs: {srcs}"
)
def test_login_html_references_muxplex_auth() -> None:
"""login.html must reference MUXPLEX_AUTH (for JS-based auth mode detection)."""
text = LOGIN_PATH.read_text()
assert "MUXPLEX_AUTH" in text, (
"login.html must reference window.MUXPLEX_AUTH for auth mode detection"
)
def test_login_html_has_error_display() -> None:
"""login.html must include an error display element (text 'error' must appear)."""
text = LOGIN_PATH.read_text().lower()
assert "error" in text, (
"login.html must include an error display element (text 'error' not found)"
)