-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitSCM: add GitHub token support (bug 1934475) (#189)
* Makefile: typo * GitSCM: redact repo auth details in exceptions * GitSCM: add GitHub token support (bug 1934475) * dependencies: update requirements.txt * doc: document environment parameters * settings: deprecate LANDO_GITHUB_ACCESS_TOKEN
- Loading branch information
Showing
10 changed files
with
1,098 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
import pytest | ||
|
||
from lando.main.scm.exceptions import SCMException | ||
from lando.main.scm.git import GitSCM | ||
|
||
|
||
|
@@ -138,6 +139,38 @@ def test_GitSCM_clean_repo( | |
), f"strip_non_public_commits not honoured for {new_file}" | ||
|
||
|
||
def test_GitSCM_push_get_github_token(git_repo: Path): | ||
scm = GitSCM(str(git_repo)) | ||
scm._git_run = MagicMock() | ||
scm._get_github_token = MagicMock() | ||
scm._get_github_token.side_effect = ["ghs_yolo"] | ||
|
||
scm.push("https://github.com/some/repo") | ||
|
||
assert scm._git_run.call_count == 1, "_git_run wasn't called when pushing" | ||
assert ( | ||
scm._get_github_token.call_count == 1 | ||
), "_get_github_token wasn't called when pushing to a github-like URL" | ||
assert ( | ||
"git:[email protected]" in scm._git_run.call_args[0][1] | ||
), "github token not found in rewritten push_path" | ||
|
||
|
||
def test_GitSCM_git_run_redact_url_userinfo(git_repo: Path): | ||
scm = GitSCM(str(git_repo)) | ||
userinfo = "user:password" | ||
with pytest.raises(SCMException) as exc: | ||
scm.push( | ||
f"http://{userinfo}@this-shouldn-t-resolve-otherwise-this-will-timeout-and-this-test-will-take-longer/some/repo" | ||
) | ||
|
||
assert userinfo not in exc.value.out | ||
assert userinfo not in exc.value.err | ||
assert userinfo not in str(exc.value) | ||
assert userinfo not in repr(exc.value) | ||
assert "[REDACTED]" in exc.value.err | ||
|
||
|
||
def _monkeypatch_scm(monkeypatch, scm: GitSCM, method: str) -> MagicMock: | ||
""" | ||
Mock a method on `scm` to test the call, but let it continue with its original side | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters