feat(auth): implement TOTP setup and management
Lint / Lint (Node/Svelte) (push) Successful in 24s
Lint / Lint (Go) (push) Successful in 28s
Lint / Lint (Python) (push) Failing after 14s
Tests / Test (Node/Svelte) (push) Successful in 18s
Tests / Test (Go) (push) Successful in 25s
Tests / Test (Python) (push) Successful in 12s
Lint / Lint (Node/Svelte) (push) Successful in 24s
Lint / Lint (Go) (push) Successful in 28s
Lint / Lint (Python) (push) Failing after 14s
Tests / Test (Node/Svelte) (push) Successful in 18s
Tests / Test (Go) (push) Successful in 25s
Tests / Test (Python) (push) Successful in 12s
- Added TOTP support for two-factor authentication in the auth module. - Introduced new types and interfaces for TOTP setup and token actions in the web UI. - Created backend logic for generating and verifying TOTP secrets and tokens. - Implemented user management features including role assignments and user CRUD operations. - Enhanced UI components for managing users and TOTP settings. - Added styles for optional labels and authentication reset links. - Implemented reset code generation and validation for admin accounts.
This commit is contained in:
1 parent
2f57554154
commit
da97fd4fb1
30 files changed
+2145
-27
No files matched your search
@@ -1,8 +1,11 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from shared_backend.auth import hash_password, verify_password
|
||||
from datetime import timedelta
|
||||
|
||||
from shared_backend.auth import ResetManager, hash_password, verify_password
|
||||
from shared_backend.config import DatabaseConfig
|
||||
from shared_backend.totp import totp_provisioning_uri, verify_totp
|
||||
from shared_backend.tokens import hash_token, new_session_token
|
||||
|
||||
|
||||
@@ -17,6 +20,38 @@ class SharedBackendTests(unittest.TestCase):
|
||||
self.assertNotEqual(token, token_hash)
|
||||
self.assertEqual(hash_token(token), token_hash)
|
||||
|
||||
def test_reset_manager_round_trip_and_one_time_use(self):
|
||||
messages = []
|
||||
manager = ResetManager(log=messages.append)
|
||||
code = manager.request()
|
||||
|
||||
self.assertEqual(len(code), 8)
|
||||
self.assertIn(f"ADMIN RESET CODE: {code}", messages[0])
|
||||
self.assertTrue(manager.confirm(f" {code.lower()} "))
|
||||
self.assertFalse(manager.confirm(code))
|
||||
|
||||
def test_reset_manager_expires(self):
|
||||
manager = ResetManager(ttl=timedelta(seconds=-1), log=lambda _message: None)
|
||||
code = manager.request()
|
||||
self.assertFalse(manager.confirm(code))
|
||||
|
||||
def test_totp_rfc6238_sha1_vectors(self):
|
||||
secret = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
|
||||
vectors = [
|
||||
(59, "287082"),
|
||||
(1111111109, "081804"),
|
||||
(1111111111, "050471"),
|
||||
(1234567890, "005924"),
|
||||
(2000000000, "279037"),
|
||||
]
|
||||
for timestamp, code in vectors:
|
||||
self.assertTrue(verify_totp(secret, code, timestamp))
|
||||
self.assertTrue(
|
||||
totp_provisioning_uri("Example App", "admin@example.com", secret).startswith(
|
||||
"otpauth://totp/"
|
||||
)
|
||||
)
|
||||
|
||||
def test_database_config_from_environment(self):
|
||||
config = DatabaseConfig.from_env(
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user