feat: add proquint-based userid generation
This commit is contained in:
parent
e5220c97b1
commit
b22325588a
2 changed files with 31 additions and 0 deletions
11
src/fastapi_oidc_op/userid.py
Normal file
11
src/fastapi_oidc_op/userid.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import secrets
|
||||
|
||||
from proquint import uint2quint
|
||||
|
||||
|
||||
def generate_userid() -> str:
|
||||
"""Generate a unique user identifier in proquint format.
|
||||
|
||||
Returns a 32-bit proquint string like 'lusab-bansen'.
|
||||
"""
|
||||
return uint2quint(secrets.randbits(32))
|
||||
20
tests/test_userid.py
Normal file
20
tests/test_userid.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from fastapi_oidc_op.userid import generate_userid
|
||||
|
||||
|
||||
def test_generate_userid_format() -> None:
|
||||
userid = generate_userid()
|
||||
# 32-bit proquint format: xxxxx-xxxxx
|
||||
parts = userid.split("-")
|
||||
assert len(parts) == 2
|
||||
for part in parts:
|
||||
assert len(part) == 5
|
||||
|
||||
|
||||
def test_generate_userid_uniqueness() -> None:
|
||||
ids = {generate_userid() for _ in range(100)}
|
||||
assert len(ids) == 100 # All unique
|
||||
|
||||
|
||||
def test_generate_userid_is_lowercase() -> None:
|
||||
userid = generate_userid()
|
||||
assert userid == userid.lower()
|
||||
Loading…
Add table
Add a link
Reference in a new issue