Skip to content

Commit fee58ac

Browse files
committed
test(github): clear GITHUB_TOKEN env in test_throws_when_no_auth
TestGitHubAdapterConstructor.test_throws_when_no_auth expected ValidationError on auth-less construction, but the GitHubAdapter constructor's env-fallback path silently satisfied auth from a GITHUB_TOKEN set by CI / dev shell — so the test failed wherever GITHUB_TOKEN was set in the environment. The duplicate test at line 827 in this same file already does the env-var cleanup correctly. Apply the same pattern to line 190 so the suite is fully green for the 0.4.27 release: pop GITHUB_TOKEN / GITHUB_APP_ID / GITHUB_PRIVATE_KEY before the assert, restore them in finally.
1 parent 1b9cd10 commit fee58ac

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

tests/test_github_webhook.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,27 @@ def test_create_single_tenant_app(self):
188188
assert a.is_multi_tenant is False
189189

190190
def test_throws_when_no_auth(self):
191-
with pytest.raises(ValidationError, match="Authentication"):
192-
GitHubAdapter(
193-
{
194-
"webhook_secret": "secret",
195-
"user_name": "bot",
196-
"logger": ConsoleLogger("error"),
197-
}
198-
)
191+
# Clear env vars so the constructor's env-fallback path can't
192+
# silently satisfy auth from a GITHUB_TOKEN injected by CI / dev shell.
193+
old_token = os.environ.pop("GITHUB_TOKEN", None)
194+
old_app = os.environ.pop("GITHUB_APP_ID", None)
195+
old_key = os.environ.pop("GITHUB_PRIVATE_KEY", None)
196+
try:
197+
with pytest.raises(ValidationError, match="Authentication"):
198+
GitHubAdapter(
199+
{
200+
"webhook_secret": "secret",
201+
"user_name": "bot",
202+
"logger": ConsoleLogger("error"),
203+
}
204+
)
205+
finally:
206+
if old_token is not None:
207+
os.environ["GITHUB_TOKEN"] = old_token
208+
if old_app is not None:
209+
os.environ["GITHUB_APP_ID"] = old_app
210+
if old_key is not None:
211+
os.environ["GITHUB_PRIVATE_KEY"] = old_key
199212

200213
def test_bot_user_id_when_set(self):
201214
a = _make_adapter(bot_user_id=42)

0 commit comments

Comments
 (0)