forked from retoor/devplacepy
Auth: username+password, email+password and API key everywhere; key returns carry username and email
POST /auth/login (form and JSON) now accepts the username in the email field, like HTTP Basic and POST /auth/token always did; the token endpoint no longer lowercases the identifier before the username lookup, fixing mixed-case usernames. The login field is relabelled and type=text so browsers accept a username.
Every JSON return of the personal API key now also returns the account username and email: the profile JSON gains a can_view_api_key-gated email beside api_key (username already rides profile_user), and POST /profile/regenerate-api-key returns {api_key, username, email}. A client holding only its DEVPLACE_API_KEY value can now fetch its full account via GET /profile in one call.
Documented fully: authentication prose page (three credentials, precedence, DEVPLACE_API_KEY, account fetch, separate DevRant/WebSocket auth domains), new auth-token docs_api card, regenerated-key sample, conventions, README, CLAUDE.md, OpenAPI description, corrected profile key hint. Summary in changes.md (left unversioned per request).
Tests: username/mixed-case/uppercase-email login and token cases, API-key account fetch via X-API-KEY and Bearer, owner/admin vs stranger/guest email gating, regenerate shape, browser login by username. Failing-first observed red, green after.
This commit is contained in:
@@ -58,6 +58,41 @@ def test_token_accepts_username_as_identifier(app_server):
|
||||
assert r.json()["access_token"]
|
||||
|
||||
|
||||
def _signup_mixed_case(password="secret123"):
|
||||
_counter_token[0] += 1
|
||||
name = f"TokMix{int(time.time() * 1000)}{_counter_token[0]}"
|
||||
email = f"{name.lower()}@t.dev"
|
||||
requests.post(
|
||||
f"{BASE_URL}/auth/signup",
|
||||
data={
|
||||
"username": name,
|
||||
"email": email,
|
||||
"password": password,
|
||||
"confirm_password": password,
|
||||
"birth_date": "1990-01-01",
|
||||
"accept_terms": "1",
|
||||
},
|
||||
allow_redirects=True,
|
||||
)
|
||||
return name, email, password
|
||||
|
||||
|
||||
def test_token_accepts_mixed_case_username(app_server):
|
||||
name, email, password = _signup_mixed_case()
|
||||
r = requests.post(f"{BASE_URL}/auth/token", data={"email": name, "password": password})
|
||||
assert r.status_code == 200, r.text[:300]
|
||||
assert r.json()["access_token"]
|
||||
|
||||
|
||||
def test_token_accepts_uppercase_email(app_server):
|
||||
name, email, password = _signup()
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/auth/token", data={"email": email.upper(), "password": password}
|
||||
)
|
||||
assert r.status_code == 200, r.text[:300]
|
||||
assert r.json()["access_token"]
|
||||
|
||||
|
||||
def test_token_via_json_body(app_server):
|
||||
name, email, password = _signup()
|
||||
r = requests.post(
|
||||
|
||||
Reference in New Issue
Block a user