def test_gitsecret_add_exception(gen_gitsecret, mocker): # noqa: F811 file_check = FakeCompletedProcess(**{ 'stdout': ".gitignore\n.gitsecret/keys/mapping.cfg\n.gitsecret/keys/pubring.kbx\n.gitsecret/keys/trustdb.gpg\n.gitsecret/paths/mapping.cfg\n", 'returncode': 0 }) git_secret_add_output = FakeCompletedProcess(**{ 'stdout': "\n", "stderr": "git-secret: abort: file not found: hello.txt1", 'returncode': 1 }) mocker.patch('gitsecret.subprocess.run', return_value=file_check) mocker.patch('gitsecret.subprocess.run', return_value=git_secret_add_output) with pytest.raises(GitSecretException): gen_gitsecret.add("hello.txt1")
def test_gitsecret_add(gen_gitsecret, mocker): # noqa: F811 file_check = FakeCompletedProcess(**{ 'stdout': ".gitignore\n.gitsecret/keys/mapping.cfg\n.gitsecret/keys/pubring.kbx\n.gitsecret/keys/trustdb.gpg\n.gitsecret/paths/mapping.cfg\n", 'returncode': 0 }) git_secret_add_output = FakeCompletedProcess(**{ 'stdout': "1 item(s) added.\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=file_check) mocker.patch('gitsecret.subprocess.run', return_value=git_secret_add_output) gen_gitsecret.add("hello.txt") assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == ["git", "secret", "add", "hello.txt"]
def test_gitsecret_clean_noreturn(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess(**{ 'stdout': "\ncleaning:\n\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) assert len(gen_gitsecret.clean()) == 0
def test_gitsecret_create_alreadycreated(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess(**{ 'stdout': "'git-secret: abort: already inited.\n'", 'returncode': 1 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) with pytest.raises(GitSecretException): gen_gitsecret.create()
def test_gitsecret_whoknows(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess(**{ 'stdout': "[email protected]\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) assert gen_gitsecret.whoknows() == ["*****@*****.**"]
def test_gitsecret_whoknows_exception(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess(**{ 'stdout': "Not a repo", 'returncode': 1 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) with pytest.raises(GitSecretException): gen_gitsecret.whoknows()
def test_gitsecret_add_nogitignore(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess(**{ 'stdout': ".gitignore\n.gitsecret/keys/mapping.cfg\n.gitsecret/keys/pubring.kbx\n.gitsecret/keys/trustdb.gpg\n.gitsecret/paths/mapping.cfg\n\nhello.txt", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) with pytest.raises(GitSecretException): gen_gitsecret.add("hello.txt")
def test_gitsecret_reveal_exception(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess(**{ 'stdout': "None", 'stderr': "hello.txt1 -> -> /Users/ivanlee/repos/sandbox/box5/\ngit-secret: abort: file not found: hello.txt1", 'returncode': 1 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) with pytest.raises(GitSecretException): gen_gitsecret.remove(file_path="hello.txt")
def test_gitsecret_add_autoadd(gen_gitsecret, mocker): # noqa: F811 git_secret_add_output = FakeCompletedProcess(**{ 'stdout': "1 item(s) added.\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=git_secret_add_output) gen_gitsecret.add("hello.txt", autoadd=True) assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == ["git", "secret", "add", "-i", "hello.txt"]
def test_gitsecret_tell_exception(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess(**{ 'stdout': "some", 'stderr': 'error', 'returncode': 1 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) with pytest.raises(GitSecretException): gen_gitsecret.tell(gpg_path="/random/path")
def test_gitsecret_remove(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess(**{ 'stdout': "hello.txt -> hello.txt -> /Users/ivanlee/repos/sandbox/box5/hello.txt\nremoved from index.\nensure that files: [hello.txt] are now not ignored.\ncleaning up...\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) gen_gitsecret.remove(file_path="hello.txt") assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == ["git", "secret", "remove", "hello.txt"]
def test_gitsecret_list_exception(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess( **{ 'stdout': "None", 'stderr': "git-secret: abort: /Users/ivanlee/repos/sandbox/box5/.gitsecret/paths/mapping.cfg is missing", 'returncode': 1 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) with pytest.raises(GitSecretException): gen_gitsecret.list()
def test_gitsecret_killperson_exception(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess( **{ 'stdout': "None", 'stderr': 'gpg: key "*****@*****.**" not found: Not found\ngpg: [email protected]: delete key failed: Not found\n', 'returncode': 2 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) with pytest.raises(GitSecretException): gen_gitsecret.killperson(email="*****@*****.**")
def test_gitsecret_reveal_exception(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess( **{ 'stdout': "None", 'stderr': "git-secret: abort: no public keys for users found. run 'git secret tell email@address'.\n", 'returncode': 1 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) with pytest.raises(GitSecretException): gen_gitsecret.reveal("test1")
def test_gitsecret_list(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess(**{ 'stdout': "\nhello.txt\nhello1.txt\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) assert gen_gitsecret.list() == ["hello.txt", "hello1.txt"] assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == [ "git", "secret", "list" ]
def test_gitsecret_reveal(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess(**{ 'stdout': "done. all 10 files are revealed.\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) gen_gitsecret.reveal(password="******") assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == [ "git", "secret", "reveal", "-p", "test" ]
def test_gitsecret_hide(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess(**{ 'stdout': "done. all 11 files are hidden.\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) gen_gitsecret.hide() assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == [ "git", "secret", "hide" ]
def test_gitsecret_create(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess( **{ 'stdout': "'/Users/ivanlee/repos/sandbox/box2/.gitsecret/' created.\ncleaning up...\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) gen_gitsecret.create() assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == [ "git", "secret", "init" ]
def test_gitsecret_killperson(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess( **{ 'stdout': "removed keys.\nnow [[email protected]] do not have an access to the repository.\nmake sure to hide the existing secrets again\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) gen_gitsecret.killperson(email="*****@*****.**") assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == [ "git", "secret", "killperson", "*****@*****.**" ]
def test_gitsecret_tell(gen_gitsecret, mocker): # noqa: F811 shell_cmd = FakeCompletedProcess( **{ 'stdout': "gpg: keybox '/Users/ivanlee/repos/sandbox/box2/.gitsecret/keys/pubring.kbx' created\ngpg: /Users/ivanlee/repos/sandbox/box2/.gitsecret/keys/trustdb.gpg: trustdb created\ndone. [email protected] added as someone who know(s) the secret.\ncleaning up...", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_cmd) gen_gitsecret.tell(email="*****@*****.**") assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == [ "git", "secret", "tell", "*****@*****.**" ]
def test_gitsecret_clean(gen_gitsecret, mocker): # noqa: F811 shell_command = FakeCompletedProcess( **{ 'stdout': "\ncleaning:\n/Users/ivanlee/repos/sandbox/box5/hello.txt.secret\n\n", 'returncode': 0 }) mocker.patch('gitsecret.subprocess.run', return_value=shell_command) assert gen_gitsecret.clean( )[0] == "/Users/ivanlee/repos/sandbox/box5/hello.txt.secret" assert gitsecret.subprocess.run.assert_called_once assert gitsecret.subprocess.run.call_args[1]['args'] == [ "git", "secret", "clean", "-v" ]