mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-10-27 03:21:57 -06:00
Fix static asset fallback and seed default admin
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import hashlib
|
||||
import sqlite3
|
||||
import unittest
|
||||
|
||||
@@ -24,6 +25,56 @@ class MigrationTests(unittest.TestCase):
|
||||
self.assertIn("scheduled_jobs", tables)
|
||||
self.assertIn("scheduled_job_runs", tables)
|
||||
self.assertIn("github_token", tables)
|
||||
self.assertIn("users", tables)
|
||||
|
||||
cursor.execute(
|
||||
"SELECT username, role, password_sha512 FROM users WHERE LOWER(username)=LOWER(?)",
|
||||
("admin",),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
self.assertIsNotNone(row)
|
||||
if row:
|
||||
self.assertEqual(row[0], "admin")
|
||||
self.assertEqual(row[1].lower(), "admin")
|
||||
self.assertEqual(row[2], hashlib.sha512(b"Password").hexdigest())
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def test_ensure_default_admin_promotes_existing_user(self) -> None:
|
||||
conn = sqlite3.connect(":memory:")
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE NOT NULL,
|
||||
display_name TEXT,
|
||||
password_sha512 TEXT,
|
||||
role TEXT,
|
||||
last_login INTEGER,
|
||||
created_at INTEGER,
|
||||
updated_at INTEGER,
|
||||
mfa_enabled INTEGER DEFAULT 0,
|
||||
mfa_secret TEXT
|
||||
)
|
||||
"""
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT INTO users (username, display_name, password_sha512, role) VALUES (?, ?, ?, ?)",
|
||||
("admin", "Custom", "hash", "user"),
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
migrations.ensure_default_admin(conn)
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT role, password_sha512 FROM users WHERE LOWER(username)=LOWER(?)",
|
||||
("admin",),
|
||||
)
|
||||
role, password_hash = cursor.fetchone()
|
||||
self.assertEqual(role.lower(), "admin")
|
||||
self.assertEqual(password_hash, "hash")
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user