|
1 | 1 | import io
|
2 | 2 | import os
|
| 3 | +import random |
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 |
|
@@ -45,6 +46,45 @@ def test_subprocess_get_use_http_path(git_helper, mocker):
|
45 | 46 | assert creds == Credential(username="foo", password="bar")
|
46 | 47 |
|
47 | 48 |
|
| 49 | +def test_subprocess_ignore_unexpected_credential_keys(git_helper, mocker): |
| 50 | + git_helper.use_http_path = True |
| 51 | + run = mocker.patch( |
| 52 | + "subprocess.run", |
| 53 | + # Simulate git-credential-osxkeychain (version >=2.45) |
| 54 | + return_value=mocker.Mock( |
| 55 | + stdout="username=foo\npassword=bar\ncapability[]=state\nstate[]=osxkeychain:seen=1" |
| 56 | + ), |
| 57 | + ) |
| 58 | + creds = git_helper.get(Credential(protocol="https", host="foo.com", path="foo.git")) |
| 59 | + assert run.call_args.args[0] == ["git-credential-foo", "get"] |
| 60 | + assert ( |
| 61 | + run.call_args.kwargs.get("input") |
| 62 | + == "protocol=https\nhost=foo.com\npath=foo.git\n" |
| 63 | + ) |
| 64 | + assert creds == Credential(username="foo", password="bar") |
| 65 | + |
| 66 | + |
| 67 | +def test_subprocess_strip_trailing_garbage_bytes(git_helper, mocker): |
| 68 | + """Garbage bytes were output from git-credential-osxkeychain from 2.45.0 to 2.47.0 |
| 69 | + so must be removed |
| 70 | + https://github.com/git/git/commit/6c3c451fb6e1c3ca83f74e63079d4d0af01b2d69""" |
| 71 | + git_helper.use_http_path = True |
| 72 | + run = mocker.patch( |
| 73 | + "subprocess.run", |
| 74 | + # Simulate git-credential-osxkeychain (version 2.45), assuming initial 0-byte |
| 75 | + return_value=mocker.Mock( |
| 76 | + stdout=f"username=foo\npassword=bar{chr(0)}{random.randbytes(15)}" |
| 77 | + ), |
| 78 | + ) |
| 79 | + creds = git_helper.get(Credential(protocol="https", host="foo.com", path="foo.git")) |
| 80 | + assert run.call_args.args[0] == ["git-credential-foo", "get"] |
| 81 | + assert ( |
| 82 | + run.call_args.kwargs.get("input") |
| 83 | + == "protocol=https\nhost=foo.com\npath=foo.git\n" |
| 84 | + ) |
| 85 | + assert creds == Credential(username="foo", password="bar") |
| 86 | + |
| 87 | + |
48 | 88 | def test_subprocess_get_failed(git_helper, mocker):
|
49 | 89 | from subprocess import CalledProcessError
|
50 | 90 |
|
|
0 commit comments