Skip to content

Commit 9024848

Browse files
Copilotmnriem
andauthored
fix: close HTTPError on 401/403, remove _VALID_AUTH_SCHEMES, catch TimeoutExpired, skip POSIX test on Windows, remove unused import
Agent-Logs-Url: https://github.com/github/spec-kit/sessions/a1e29737-dd6e-4287-96c1-509e0c96fb21 Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
1 parent 68b99cb commit 9024848

5 files changed

Lines changed: 5 additions & 16 deletions

File tree

src/specify_cli/authentication/azure_devops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _acquire_via_az_cli() -> str | None:
7676
payload = _json.loads(result.stdout)
7777
token = payload.get("accessToken", "").strip()
7878
return token or None
79-
except (OSError, _json.JSONDecodeError, KeyError):
79+
except (OSError, subprocess.TimeoutExpired, _json.JSONDecodeError, KeyError):
8080
return None
8181

8282
@staticmethod

src/specify_cli/authentication/config.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ class AuthConfigEntry:
3030
client_secret_env: str | None = None
3131

3232

33-
_VALID_AUTH_SCHEMES = frozenset({
34-
"bearer",
35-
"basic-pat",
36-
"azure-cli",
37-
"azure-ad",
38-
})
39-
40-
4133
def _default_config_path() -> Path:
4234
"""Return ``~/.specify/auth.json``."""
4335
return Path.home() / ".specify" / "auth.json"
@@ -106,11 +98,6 @@ def load_auth_config(
10698
auth = entry_raw.get("auth", "")
10799
if not isinstance(auth, str) or not auth:
108100
raise ValueError(f"providers[{i}]: 'auth' must be a non-empty string")
109-
if auth not in _VALID_AUTH_SCHEMES:
110-
raise ValueError(
111-
f"providers[{i}]: unsupported auth scheme {auth!r}; "
112-
f"valid: {sorted(_VALID_AUTH_SCHEMES)}"
113-
)
114101

115102
token = entry_raw.get("token")
116103
token_env = entry_raw.get("token_env")

src/specify_cli/authentication/http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def _make_req(auth_headers: dict[str, str]) -> urllib.request.Request:
131131
return opener.open(req, timeout=timeout)
132132
except urllib.error.HTTPError as exc:
133133
if exc.code in (401, 403):
134+
exc.close()
134135
continue # try next entry
135136
raise
136137

src/specify_cli/integrations/catalog.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ def _fetch_single_catalog(
232232
) -> Dict[str, Any]:
233233
"""Fetch one catalog, with per-URL caching."""
234234
import urllib.error
235-
import urllib.request
236235

237236
url_hash = hashlib.sha256(entry.url.encode()).hexdigest()[:16]
238237
cache_file = self.cache_dir / f"catalog-{url_hash}.json"

tests/test_authentication.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import base64
1717
import json
18+
import os
1819

1920
import pytest
2021

@@ -198,7 +199,7 @@ def test_unsupported_auth_scheme_raises(self, tmp_path):
198199
cfg.write_text(json.dumps({
199200
"providers": [{"hosts": ["github.com"], "provider": "github", "auth": "ntlm", "token_env": "X"}]
200201
}))
201-
with pytest.raises(ValueError, match="unsupported"):
202+
with pytest.raises(ValueError, match="does not support"):
202203
load_auth_config(cfg)
203204

204205
def test_bearer_without_token_raises(self, tmp_path):
@@ -243,6 +244,7 @@ def test_incompatible_provider_scheme_raises(self, tmp_path):
243244
with pytest.raises(ValueError, match="does not support"):
244245
load_auth_config(cfg)
245246

247+
@pytest.mark.skipif(os.name == "nt", reason="POSIX permission bits not supported on Windows")
246248
def test_world_readable_warns(self, tmp_path):
247249
import stat
248250

0 commit comments

Comments
 (0)