Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93972a62f7 | ||
|
|
f3da9f3b59 | ||
|
|
49f84655f7 |
@@ -24,6 +24,10 @@ def _create_base_client(url: str, key: str, access_token: Optional[str] = None,
|
|||||||
# Otherwise fall back to the API key
|
# Otherwise fall back to the API key
|
||||||
auth_header = f"Bearer {access_token}" if access_token else f"Bearer {key}"
|
auth_header = f"Bearer {access_token}" if access_token else f"Bearer {key}"
|
||||||
|
|
||||||
|
# Only override Authorization here. apikey is supplied to create_client via the `key` arg and
|
||||||
|
# set by supabase-py itself; setting it again here sends a DUPLICATE apikey header that the
|
||||||
|
# Supabase gateway (Kong) rejects with 401 "Duplicate API key found". For a per-user client
|
||||||
|
# apikey stays the anon key (from `key`) while this Authorization carries the user JWT.
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": auth_header,
|
"Authorization": auth_header,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,15 +55,19 @@ def test_dev_api_health_endpoint_is_healthy():
|
|||||||
assert payload['services']['redis']['database'] == 0
|
assert payload['services']['redis']['database'] == 0
|
||||||
|
|
||||||
|
|
||||||
|
# NOTE: these are >= baselines, not exact counts. The greenfield seed produces this floor;
|
||||||
|
# additive exam-marker fixtures (S4-4 cohort adds ~10 students/memberships; ad-hoc classes) push
|
||||||
|
# the live .94 counts above it. Exact == froze a snapshot that any new fixture breaks, while >=
|
||||||
|
# still catches a broken or missing seed.
|
||||||
def test_supabase_dev_seed_core_counts():
|
def test_supabase_dev_seed_core_counts():
|
||||||
assert _rest_count('profiles') == 21
|
assert _rest_count('profiles') >= 21
|
||||||
assert _rest_count('institute_memberships') == 21
|
assert _rest_count('institute_memberships') >= 21
|
||||||
assert _rest_count('institutes') == 2
|
assert _rest_count('institutes') >= 2
|
||||||
|
|
||||||
|
|
||||||
def test_supabase_dev_seed_timetable_counts():
|
def test_supabase_dev_seed_timetable_counts():
|
||||||
assert _rest_count('classes') == 17
|
assert _rest_count('classes') >= 17
|
||||||
assert _rest_count('taught_lessons') == 1462
|
assert _rest_count('taught_lessons') >= 1462
|
||||||
|
|
||||||
|
|
||||||
def test_runtime_identity_does_not_expose_secret_values():
|
def test_runtime_identity_does_not_expose_secret_values():
|
||||||
|
|||||||
@@ -122,11 +122,11 @@ def test_supabase_client_for_user_uses_access_token_authorization(monkeypatch):
|
|||||||
|
|
||||||
assert anon.access_token == "user-token"
|
assert anon.access_token == "user-token"
|
||||||
assert captured["url"] == "http://supabase.test"
|
assert captured["url"] == "http://supabase.test"
|
||||||
|
# apikey is supplied via the `key` positional arg (supabase-py sets the apikey header from it).
|
||||||
|
# options.headers must carry ONLY the per-user Authorization override — adding apikey here too
|
||||||
|
# produces a duplicate apikey header that Kong rejects ("Duplicate API key found").
|
||||||
assert captured["key"] == "anon-key"
|
assert captured["key"] == "anon-key"
|
||||||
assert captured["options_kwargs"]["headers"] == {
|
assert captured["options_kwargs"]["headers"] == {"Authorization": "Bearer user-token"}
|
||||||
"apikey": "anon-key",
|
|
||||||
"Authorization": "Bearer user-token",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test_no_school_bootstrap_requires_school_membership_but_allows_canvas():
|
def test_no_school_bootstrap_requires_school_membership_but_allows_canvas():
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ def test_supabase_anon_for_user_sets_user_authorization_header(monkeypatch):
|
|||||||
|
|
||||||
client_module.SupabaseAnonClient.for_user('Bearer user-jwt')
|
client_module.SupabaseAnonClient.for_user('Bearer user-jwt')
|
||||||
|
|
||||||
|
# apikey comes from the `key` arg (supabase-py sets the apikey header); options.headers must
|
||||||
|
# carry only the user Authorization override. A second apikey here → Kong "Duplicate API key".
|
||||||
assert captured['key'] == 'anon-key'
|
assert captured['key'] == 'anon-key'
|
||||||
assert captured['options'].headers['apikey'] == 'anon-key'
|
assert 'apikey' not in captured['options'].headers
|
||||||
assert captured['options'].headers['Authorization'] == 'Bearer user-jwt'
|
assert captured['options'].headers['Authorization'] == 'Bearer user-jwt'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user