geeViz.eeAuth.tests.test_eeCreds¶
Tests for the eeCreds high-level API.
Functions
Bytes input is decoded as UTF-8 or base64. |
|
addCreds returns self for fluent style. |
|
Even without type=authorized_user, presence of refresh_token → OAuth. |
|
|
|
Without explicit .use(), .current() returns the first registered name. |
|
The default tenant_header should be geeViz-branded so it's obviously library-owned in browser DevTools / packet captures. |
|
Polymorphism: build_proxy_router should accept an EECreds the same way it accepts an SARegistry. |
|
The old |
|
|
If every port in the explicit walk range is taken, the OS picks any free port (port 0 in bind() means ephemeral). |
When the preferred port is bindable, return it as-is. |
|
When the preferred port is busy, walk up until a free one is found. |
|
|
If no upstream is registered, /ee-api requests must 503 cleanly rather than hanging or crashing the server. |
|
|
End-to-end: stand up a stub upstream + the geeViz handler, hit /ee-api/* on the handler, and verify the request lands at the upstream with the tenant header stamped and the response streamed back. |
|
First get_token mints; second returns the cache; force_refresh re-mints. |
|
Forgiving lookup — unknown name → first registered. |
|
|
End-to-end: when proxy_port is busy, start() should still succeed on an alternate port, and proxy_url reflects the actual port. |
The tenant must be baked into the per-session run_js (NOT the page URL). |
|
When eeCreds isn't started (proxy_url is None), Map.view() must fall back to the legacy direct-token mint path. |
|
When eeCreds.proxy_url is set, Map.view() must register that upstream with the local HTTP server so /ee-api/* gets reverse-proxied — and keep the viewer URL empty (no proxy address baked in). |
|
If the JSON has its own client_id/client_secret (e.g. a custom OAuth app), those win over EE's well-known fallback. |
|
|
Tenant resolution order: explicit ?tenant on the request → ?tenant on the Referer URL → |
|
|
If only one credential is registered, get_token returns it without any .use() call needed — the simplest possible path 'works automatically'. |
|
start(launch_proxy=False, ee_init=False) is idempotent + reports state. |
|
eeCreds.stop() must clear the proxy thread + URL so the registry can be restarted cleanly. |
|
Calling stop() on a never-started registry should be a no-op rather than crashing. |
|
A stopped registry can be started again. |
|
sync_oauth_project with the same project that's already set should be a no-op (no log noise, no token invalidation). |
|
The SDK placeholder |
|
sync_oauth_project should update every OAuth entry's project_id and invalidate cached tokens, so the next mint includes the new project. |
|
build_proxy_router must accept tenant_header= so deployments can use whatever name they want (e.g. AskTerra agent uses X-AskTerra-Tenant for back-compat). |
|
Plain .use() (no with) takes effect right away. |
|
- geeViz.eeAuth.tests.test_eeCreds.test_addCreds_dict_oauth_from_refresh_token_only()[source]¶
Even without type=authorized_user, presence of refresh_token → OAuth.
- geeViz.eeAuth.tests.test_eeCreds.test_addCreds_bytes_input()[source]¶
Bytes input is decoded as UTF-8 or base64.
- geeViz.eeAuth.tests.test_eeCreds.test_addCreds_chains()[source]¶
addCreds returns self for fluent style.
- geeViz.eeAuth.tests.test_eeCreds.test_current_falls_back_to_first()[source]¶
Without explicit .use(), .current() returns the first registered name.
- geeViz.eeAuth.tests.test_eeCreds.test_use_switches_tenant_immediately()[source]¶
Plain .use() (no with) takes effect right away.
- geeViz.eeAuth.tests.test_eeCreds.test_get_token_caches_and_refreshes()[source]¶
First get_token mints; second returns the cache; force_refresh re-mints.
- geeViz.eeAuth.tests.test_eeCreds.test_get_token_unknown_falls_back_to_first()[source]¶
Forgiving lookup — unknown name → first registered.
- geeViz.eeAuth.tests.test_eeCreds.test_start_returns_status()[source]¶
start(launch_proxy=False, ee_init=False) is idempotent + reports state.
- geeViz.eeAuth.tests.test_eeCreds.test_eeCreds_works_with_build_proxy_router()[source]¶
Polymorphism: build_proxy_router should accept an EECreds the same way it accepts an SARegistry.
- geeViz.eeAuth.tests.test_eeCreds.test_single_cred_used_automatically_without_use()[source]¶
If only one credential is registered, get_token returns it without any .use() call needed — the simplest possible path ‘works automatically’.
- geeViz.eeAuth.tests.test_eeCreds.test_stop_clears_proxy_state()[source]¶
eeCreds.stop() must clear the proxy thread + URL so the registry can be restarted cleanly.
- geeViz.eeAuth.tests.test_eeCreds.test_stop_is_safe_when_not_started()[source]¶
Calling stop() on a never-started registry should be a no-op rather than crashing.
- geeViz.eeAuth.tests.test_eeCreds.test_default_header_mentions_geeviz()[source]¶
The default tenant_header should be geeViz-branded so it’s obviously library-owned in browser DevTools / packet captures.
- geeViz.eeAuth.tests.test_eeCreds.test_tenant_header_is_configurable()[source]¶
build_proxy_router must accept tenant_header= so deployments can use whatever name they want (e.g. AskTerra agent uses X-AskTerra-Tenant for back-compat).
- geeViz.eeAuth.tests.test_eeCreds.test_stop_then_restart()[source]¶
A stopped registry can be started again.
- geeViz.eeAuth.tests.test_eeCreds.test_find_free_port_returns_preferred_when_available()[source]¶
When the preferred port is bindable, return it as-is.
- geeViz.eeAuth.tests.test_eeCreds.test_find_free_port_walks_past_busy()[source]¶
When the preferred port is busy, walk up until a free one is found.
- geeViz.eeAuth.tests.test_eeCreds.test_find_free_port_falls_back_to_os_assigned_when_all_taken()[source]¶
If every port in the explicit walk range is taken, the OS picks any free port (port 0 in bind() means ephemeral).
- geeViz.eeAuth.tests.test_eeCreds.test_sync_oauth_project_updates_all_oauth_entries()[source]¶
sync_oauth_project should update every OAuth entry’s project_id and invalidate cached tokens, so the next mint includes the new project. SA entries are NOT touched (their project_id is from JSON).
- geeViz.eeAuth.tests.test_eeCreds.test_sync_oauth_project_rejects_earthengine_legacy()[source]¶
The SDK placeholder
earthengine-legacymust never propagate via sync_oauth_project — otherwise we’d just re-create the original bug after legacy init was somehow set to the placeholder.
- geeViz.eeAuth.tests.test_eeCreds.test_sync_oauth_project_noop_when_already_correct()[source]¶
sync_oauth_project with the same project that’s already set should be a no-op (no log noise, no token invalidation).
- geeViz.eeAuth.tests.test_eeCreds.test_ee_persistent_refresh_token_only_credentials_work()[source]¶
The old
earthengine authenticatecredentials file format contains justrefresh_token(and sometimesscopes) with noclient_id/client_secret/token_uri. EE injects its well-known OAuth client at runtime — we have to do the same when building google.oauth2.credentials.Credentials, otherwise the first refresh raises:RefreshError: The credentials do not contain the necessary fields need to refresh the access token. You must specify refresh_token, token_uri, client_id, and client_secret.
Regression test for the eeCreds proxy crash when auto-discovery pulled in a bare-refresh-token EE persistent credentials file.
- geeViz.eeAuth.tests.test_eeCreds.test_oauth_user_provided_client_id_takes_precedence()[source]¶
If the JSON has its own client_id/client_secret (e.g. a custom OAuth app), those win over EE’s well-known fallback.
- geeViz.eeAuth.tests.test_eeCreds.test_launch_proxy_picks_alternate_port_when_preferred_busy()[source]¶
End-to-end: when proxy_port is busy, start() should still succeed on an alternate port, and proxy_url reflects the actual port.
- geeViz.eeAuth.tests.test_eeCreds.test_map_view_uses_eeCreds_proxy_when_available()[source]¶
When eeCreds.proxy_url is set, Map.view() must register that upstream with the local HTTP server so /ee-api/* gets reverse-proxied — and keep the viewer URL empty (no proxy address baked in).
- geeViz.eeAuth.tests.test_eeCreds.test_map_view_bakes_tenant_into_run_js_not_url()[source]¶
The tenant must be baked into the per-session run_js (NOT the page URL). This pins every browser tab to the tenant that was current at Map.view() time, immune to subsequent
eeCreds.use()changes that mutate process-wide state.
- geeViz.eeAuth.tests.test_eeCreds.test_map_view_falls_back_without_eecreds_running()[source]¶
When eeCreds isn’t started (proxy_url is None), Map.view() must fall back to the legacy direct-token mint path.
- geeViz.eeAuth.tests.test_eeCreds.test_set_ee_api_upstream_round_trip()[source]¶
_set_ee_api_upstreammust accept a URL, normalize trailing slashes, andNonemust reset the upstream so the handler 503s.
- geeViz.eeAuth.tests.test_eeCreds.test_resolve_ee_tenant_precedence_request_then_referer_then_current()[source]¶
Tenant resolution order: explicit ?tenant on the request → ?tenant on the Referer URL →
eeCreds.current().
- geeViz.eeAuth.tests.test_eeCreds.test_geeviz_request_handler_proxies_ee_api(tmp_path)[source]¶
End-to-end: stand up a stub upstream + the geeViz handler, hit /ee-api/* on the handler, and verify the request lands at the upstream with the tenant header stamped and the response streamed back.
- geeViz.eeAuth.tests.test_eeCreds.test_geeviz_request_handler_parses_tenant_from_path_prefix(tmp_path)[source]¶
/ee-api/t/<tenant>/v1/...must route to the named tenant regardless of process-wideeeCreds.current(). This is the mechanism that pins each browser tab to its Map.view()-time tenant even when subsequenteeCreds.use()switches change global state.
- geeViz.eeAuth.tests.test_eeCreds.test_build_run_js_emits_tenant_pin_when_provided()[source]¶
_build_run_js(tenant='foo')must produce JS that re-assignsauthProxyAPIURLto a tenant-prefixed origin path. With no tenant, the JS must NOT touchauthProxyAPIURLso the bundle’s own default (window.location.origin + '/ee-api') sticks.