fix: persist Gitea credentials across AI sessions
This commit is contained in:
1 parent
3a0b288dfa
commit
98262e83e8
23 files changed
+1694
-286
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import importlib.util
|
||||
import io
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
SCRIPTS = Path(__file__).resolve().parents[1] / "skills" / "updating-gitea-repositories" / "scripts"
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
spec = importlib.util.spec_from_file_location("credential_oauth_identity_test", SCRIPTS / "credential_oauth_identity.py")
|
||||
identity = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(identity)
|
||||
|
||||
|
||||
class IdentityTest(unittest.TestCase):
|
||||
def test_reports_api_login_without_disclosing_token(self):
|
||||
class Response:
|
||||
def __enter__(self): return self
|
||||
def __exit__(self, *args): pass
|
||||
def read(self, limit): return b'{"login":"alice"}'
|
||||
class Opener:
|
||||
def open(self, request, timeout): return Response()
|
||||
def get(namespace, operation, fields, output):
|
||||
output.write(b"username=oauth2\npassword=fake-secret-token\n")
|
||||
with patch.object(identity.vault, "run", side_effect=get):
|
||||
self.assertEqual(identity.lookup("https://example.invalid", "gitea-oauth-" + "a" * 32, Opener()), "alice")
|
||||
|
||||
def test_empty_vault_result_is_rejected(self):
|
||||
with patch.object(identity.vault, "run"), self.assertRaises(identity.IdentityError):
|
||||
identity.lookup("https://example.invalid", "gitea-oauth-" + "a" * 32, object())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user