Skip to content

💫 Toolkit to help you get started with SDD or any other process!

chore: organize authentication domain (#4678)

Manfred Rieme1046bd55704
diff --git a/src/specify_cli/_github_http.py b/src/specify_cli/authentication/github_http.py
similarity index 98%
rename from src/specify_cli/_github_http.py
rename to src/specify_cli/authentication/github_http.py
index 0b6b9be18..402a147d6 100644
--- a/src/specify_cli/_github_http.py
+++ b/src/specify_cli/authentication/github_http.py
@@ -1,4 +1,4 @@
-"""Shared GitHub HTTP request helpers.
+"""GitHub-specific HTTP request helpers for the authentication domain.
Provides ``build_github_request()`` for attaching GITHUB_TOKEN / GH_TOKEN
credentials to requests targeting GitHub-hosted domains, and
@@ -107,7 +107,7 @@ def resolve_github_release_asset_api_url(
Args:
download_url: The URL to resolve.
open_url_fn: A callable compatible with
- ``specify_cli.authentication.http.open_url`` used for the
+ :func:`specify_cli.authentication.http.open_url` used for the
authenticated release-metadata lookup.
timeout: Per-request timeout in seconds.
github_hosts: Host patterns to treat as GitHub Enterprise Server.
@@ -117,7 +117,7 @@ def resolve_github_release_asset_api_url(
import json
import urllib.error
- from specify_cli._download_security import read_response_limited
+ from .._download_security import read_response_limited
# Accessing ``.hostname`` (like ``.port`` below) raises ValueError on a
# malformed authority, e.g. an invalid bracketed IPv6 host
diff --git a/src/specify_cli/bundles/sources.py b/src/specify_cli/bundles/sources.py
index 3d78d2973..581969c66 100644
--- a/src/specify_cli/bundles/sources.py
+++ b/src/specify_cli/bundles/sources.py
@@ -190,7 +190,7 @@ def _download_remote_manifest(
import yaml as _yaml
from ..authentication.http import github_provider_hosts, open_url
- from .._github_http import resolve_github_release_asset_api_url
+ from ..authentication.github_http import resolve_github_release_asset_api_url
from .manifest import BundleManifest
from ..shared_infra import verify_archive_sha256
diff --git a/src/specify_cli/extensions/__init__.py b/src/specify_cli/extensions/__init__.py
index 775ade731..e4b9e7de9 100644
--- a/src/specify_cli/extensions/__init__.py
+++ b/src/specify_cli/extensions/__init__.py
@@ -3793,11 +3793,12 @@ class ExtensionCatalog(CatalogStackBase):
) -> Optional[str]:
"""Resolve a GitHub release asset URL to its API asset URL.
- Delegates to the shared helper in :mod:`specify_cli._github_http`,
+ Delegates to the shared helper in
+ :mod:`specify_cli.authentication.github_http`,
passing the ``github`` provider hosts from ``auth.json`` so GitHub
Enterprise Server release assets resolve via ``/api/v3``.
"""
- from specify_cli._github_http import resolve_github_release_asset_api_url
+ from specify_cli.authentication.github_http import resolve_github_release_asset_api_url
from specify_cli.authentication.http import github_provider_hosts
return resolve_github_release_asset_api_url(
diff --git a/src/specify_cli/presets/__init__.py b/src/specify_cli/presets/__init__.py
index b22a44066..eff1e6815 100644
--- a/src/specify_cli/presets/__init__.py
+++ b/src/specify_cli/presets/__init__.py
@@ -4542,7 +4542,7 @@ class PresetCatalog:
Passes the ``github`` provider hosts from ``auth.json`` so GitHub
Enterprise Server release assets resolve via ``/api/v3``.
"""
- from specify_cli._github_http import resolve_github_release_asset_api_url
+ from specify_cli.authentication.github_http import resolve_github_release_asset_api_url
from specify_cli.authentication.http import github_provider_hosts
return resolve_github_release_asset_api_url(
diff --git a/src/specify_cli/presets/command_add.py b/src/specify_cli/presets/command_add.py
index fae04d055..17bb778e9 100644
--- a/src/specify_cli/presets/command_add.py
+++ b/src/specify_cli/presets/command_add.py
@@ -217,7 +217,7 @@ def preset_add(
with tempfile.TemporaryDirectory() as tmpdir:
archive_path = Path(tmpdir) / "preset.archive"
try:
- from specify_cli._github_http import (
+ from specify_cli.authentication.github_http import (
resolve_github_release_asset_api_url,
)
from specify_cli.authentication.http import github_provider_hosts
diff --git a/src/specify_cli/workflows/_commands.py b/src/specify_cli/workflows/_commands.py
index 940fa6163..de01789d0 100644
--- a/src/specify_cli/workflows/_commands.py
+++ b/src/specify_cli/workflows/_commands.py
@@ -1165,7 +1165,9 @@ def _install_workflow_from_catalog(
try:
from specify_cli.authentication.http import open_url as _open_url
from specify_cli.authentication.http import github_provider_hosts as _github_provider_hosts
- from specify_cli._github_http import resolve_github_release_asset_api_url as _resolve_gh_asset
+ from specify_cli.authentication.github_http import (
+ resolve_github_release_asset_api_url as _resolve_gh_asset,
+ )
_wf_cat_extra_headers = None
_resolved_workflow_url = _resolve_gh_asset(
diff --git a/src/specify_cli/workflows/command_add.py b/src/specify_cli/workflows/command_add.py
index 774d57515..f123a9645 100644
--- a/src/specify_cli/workflows/command_add.py
+++ b/src/specify_cli/workflows/command_add.py
@@ -303,7 +303,7 @@ def workflow_add(
cli.console.print("Cancelled")
raise cli.typer.Exit(0)
- from specify_cli._github_http import (
+ from specify_cli.authentication.github_http import (
resolve_github_release_asset_api_url as _resolve_gh_asset,
)
from specify_cli.authentication.http import (
diff --git a/tests/http_helpers.py b/tests/http_helpers.py
index 04696d7c0..f5bd2e8b0 100644
--- a/tests/http_helpers.py
+++ b/tests/http_helpers.py
@@ -28,7 +28,8 @@ def route_opener_open_through_urlopen(monkeypatch):
modules are built on.
Delegating ``open()`` to urlopen at call time keeps those patches
effective; the redirect handler's own behavior is covered by
- ``TestRedirectStripping`` in test_authentication.py.
+ ``TestRedirectStripping`` in
+ ``tests/specify_cli/authentication/test_authentication.py``.
Import this fixture into a test module to activate it there.
"""
diff --git a/tests/specify_cli/authentication/__init__.py b/tests/specify_cli/authentication/__init__.py
new file mode 100644
index 000000000..7edbe28fb
--- /dev/null
+++ b/tests/specify_cli/authentication/__init__.py
@@ -0,0 +1 @@
+"""Tests for the authentication domain."""
diff --git a/tests/auth_helpers.py b/tests/specify_cli/authentication/helpers.py
similarity index 92%
rename from tests/auth_helpers.py
rename to tests/specify_cli/authentication/helpers.py
index babc43e40..2522fcec8 100644
--- a/tests/auth_helpers.py
+++ b/tests/specify_cli/authentication/helpers.py
@@ -1,4 +1,4 @@
-"""Shared test helpers for authentication config injection."""
+"""Shared authentication-domain test helpers."""
from __future__ import annotations
diff --git a/tests/test_authentication.py b/tests/specify_cli/authentication/test_authentication.py
similarity index 99%
rename from tests/test_authentication.py
rename to tests/specify_cli/authentication/test_authentication.py
index 38e12edd5..7c8f8b7ef 100644
--- a/tests/test_authentication.py
+++ b/tests/specify_cli/authentication/test_authentication.py
@@ -1,4 +1,4 @@
-"""Tests for the authentication provider registry and config-driven HTTP helpers.
+"""Tests for the authentication domain registry and config-driven HTTP helpers.
Covers:
- Config loading (auth.json parsing, validation, permission warning)
diff --git a/tests/test_github_http.py b/tests/specify_cli/authentication/test_github_http.py
similarity index 99%
rename from tests/test_github_http.py
rename to tests/specify_cli/authentication/test_github_http.py
index 6131bacdd..ad6440f79 100644
--- a/tests/test_github_http.py
+++ b/tests/specify_cli/authentication/test_github_http.py
@@ -9,7 +9,7 @@ from urllib.request import Request
import pytest
-from specify_cli._github_http import (
+from specify_cli.authentication.github_http import (
GITHUB_HOSTS,
build_github_request,
resolve_github_release_asset_api_url,
@@ -47,7 +47,9 @@ class TestBuildGitHubRequest:
)
def test_malformed_explicit_port_raises_before_request_construction(self, url):
"""Malformed explicit ports are rejected before creating a Request."""
- with patch("specify_cli._github_http.urllib.request.Request") as request:
+ with patch(
+ "specify_cli.authentication.github_http.urllib.request.Request"
+ ) as request:
with pytest.raises(ValueError):
build_github_request(url)
request.assert_not_called()
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index 09f1c9203..d2d7d4efd 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -5537,7 +5537,7 @@ class TestExtensionCatalog:
return ExtensionCatalog(project_dir)
def _inject_github_config(self, monkeypatch, token_env="GH_TOKEN"):
- from tests.auth_helpers import inject_github_config
+ from tests.specify_cli.authentication.helpers import inject_github_config
inject_github_config(monkeypatch, token_env)
def test_make_request_no_token_no_auth_header(self, temp_dir, monkeypatch):
diff --git a/tests/test_presets.py b/tests/test_presets.py
index d71bd5258..df9f448ab 100644
--- a/tests/test_presets.py
+++ b/tests/test_presets.py
@@ -2282,7 +2282,7 @@ class TestPresetCatalog:
"""Test template catalog functionality."""
def _inject_github_config(self, monkeypatch, token_env="GH_TOKEN"):
- from tests.auth_helpers import inject_github_config
+ from tests.specify_cli.authentication.helpers import inject_github_config
inject_github_config(monkeypatch, token_env)
def test_default_catalog_url(self, project_dir):
diff --git a/tests/test_upgrade.py b/tests/test_upgrade.py
index edce927e8..513cd2343 100644
--- a/tests/test_upgrade.py
+++ b/tests/test_upgrade.py
@@ -349,7 +349,7 @@ def _capture_request_via_auth_opener():
def _inject_github_config(monkeypatch, token_env="GH_TOKEN"):
- from tests.auth_helpers import inject_github_config
+ from tests.specify_cli.authentication.helpers import inject_github_config
inject_github_config(monkeypatch, token_env)