mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-16 19:36:54 +00:00
Change-detectors, tautologies, source-reading tests, redundant duplicates, mock-echo tests and dead/unrunnable tests. Per-test rationale in the lane ledger (category + reason for every removal).
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
"""Regression tests for Tirith-safe GitHub credential extraction (#22722)."""
|
|
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
HELPER = REPO_ROOT / "skills/software-development/github/scripts/git-credential-token.py"
|
|
|
|
|
|
def _extract(path: Path) -> subprocess.CompletedProcess[str]:
|
|
return subprocess.run(
|
|
[sys.executable, str(HELPER), str(path)],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
|
|
|
|
def _credential_file(tmp_path: Path, value: str) -> Path:
|
|
credentials = tmp_path / "credentials"
|
|
credentials.write_text(value, encoding="utf-8", newline="")
|
|
return credentials
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("credential", "token"),
|
|
[
|
|
("https://octocat:[email protected]\n", "password-form-token"),
|
|
("https://oauth-token:[email protected]\n", "oauth-token"),
|
|
("https://[email protected]\n", "ghp_token_only"),
|
|
("https://[email protected]\n", "github_pat_token_only"),
|
|
],
|
|
)
|
|
def test_extracts_supported_git_credential_url_forms(tmp_path, credential, token):
|
|
result = _extract(_credential_file(tmp_path, credential))
|
|
|
|
assert result.returncode == 0
|
|
assert result.stdout == f"{token}\n"
|
|
assert result.stderr == ""
|
|
|
|
|
|
def test_extracts_password_from_exact_github_https_credential(tmp_path):
|
|
credentials = _credential_file(
|
|
tmp_path,
|
|
"https://ignored:[email protected]\n"
|
|
"https://octocat:secret%2F[email protected]\n",
|
|
)
|
|
|
|
result = _extract(credentials)
|
|
|
|
assert result.returncode == 0
|
|
assert result.stdout == "secret/token\n"
|
|
assert result.stderr == ""
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"credential",
|
|
[
|
|
"https://octocat:[email protected]\n",
|
|
"https://[email protected]\n",
|
|
"https://%6f[email protected]\n",
|
|
"https://octocat:[email protected]%2eattacker.example\n",
|
|
"https://octocat:token%0D%0AX-Injected%[email protected]\n",
|
|
"https://ghp_token%[email protected]\n",
|
|
"https://octocat:token%00s[email protected]\n",
|
|
"https://octocat:token%09s[email protected]\n",
|
|
"https://octocat:token%C2%85s[email protected]\n",
|
|
"https://ghp_token%1F[email protected]\n",
|
|
"https://ghp_token%C2%9F[email protected]\n",
|
|
"https://octocat:bad%[email protected]\n",
|
|
"https://octocat:[email protected]:bogus\n",
|
|
"http://octocat:[email protected]\n",
|
|
],
|
|
)
|
|
def test_rejects_ambiguous_lookalike_or_malformed_credentials(tmp_path, credential):
|
|
result = _extract(_credential_file(tmp_path, credential))
|
|
|
|
assert result.returncode == 1
|
|
assert result.stdout == ""
|
|
assert result.stderr == ""
|