def test_skip(self, monkeypatch, capsys): monkeypatch.setenv('PASS_GIT_HELPER_SKIP', '1') with pytest.raises(SystemExit): passgithelper.main(['get']) out, err = capsys.readouterr() assert not out assert not err
def test_custom_mapping_used(self, capsys: Any) -> None: # this would fail for the default file from with-username passgithelper.main( ["-m", "test_data/smoke/git-pass-mapping.ini", "get"]) out, _ = capsys.readouterr() assert out == "password=narf\n"
def test_skip(self, monkeypatch: Any, capsys: Any) -> None: monkeypatch.setenv("PASS_GIT_HELPER_SKIP", "1") with pytest.raises(SystemExit): passgithelper.main(["get"]) out, err = capsys.readouterr() assert not out assert not err
def test_select_unknown_extractor( self, xdg_dir, monkeypatch, capsys): monkeypatch.setattr('sys.stdin', io.StringIO(''' protocol=https host=mytest.com''')) with pytest.raises(KeyError): passgithelper.main(['get'])
def test_select_unknown_extractor(self, xdg_dir, monkeypatch, capsys): monkeypatch.setattr( "sys.stdin", io.StringIO(""" protocol=https host=mytest.com"""), ) with pytest.raises(KeyError): passgithelper.main(["get"])
def test_path_used_if_present_fails(self, xdg_dir, monkeypatch, caplog): monkeypatch.setattr('sys.stdin', io.StringIO(''' protocol=https host=mytest.com path=/foo/bar.git''')) with pytest.raises(SystemExit): passgithelper.main(['get']) assert caplog.record_tuples == [ ('root', logging.WARN, 'No mapping matched'), ]
def test_smoke_resolve(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr('sys.stdin', io.StringIO(''' protocol=https host=mytest.com''')) subprocess_mock = mocker.patch('subprocess.check_output') subprocess_mock.return_value = b'narf' passgithelper.main(['get']) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(['pass', 'show', 'dev/mytest']) out, _ = capsys.readouterr() assert out == 'password=narf\n'
def test_prefix_skipping(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr('sys.stdin', io.StringIO(''' protocol=https host=mytest.com''')) subprocess_mock = mocker.patch('subprocess.check_output') subprocess_mock.return_value = b'password: xyz\nuser: tester' passgithelper.main(['get']) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(['pass', 'show', 'dev/mytest']) out, _ = capsys.readouterr() assert out == 'password=xyz\nusername=tester\n'
def test_path_used_if_present_fails(self, xdg_dir, monkeypatch, caplog): monkeypatch.setattr( "sys.stdin", io.StringIO(""" protocol=https host=mytest.com path=/foo/bar.git"""), ) with caplog.at_level(logging.WARNING): with pytest.raises(SystemExit): passgithelper.main(["get"]) assert caplog.record_tuples == [ ("root", logging.WARNING, "No mapping matched"), ]
def test_username_provided(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr('sys.stdin', io.StringIO(''' protocol=https host=plainline.com''')) subprocess_mock = mocker.patch('subprocess.check_output') subprocess_mock.return_value = b'password\nusername' passgithelper.main(['get']) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with( ['pass', 'show', 'dev/plainline']) out, _ = capsys.readouterr() assert out == 'password=password\nusername=username\n'
def test_custom_mapping_used(self, xdg_dir, monkeypatch, mocker, capsys): # this would fail for the default file from with-username monkeypatch.setattr('sys.stdin', io.StringIO(''' protocol=https host=mytest.com''')) subprocess_mock = mocker.patch('subprocess.check_output') subprocess_mock.return_value = b'narf' passgithelper.main( ['-m', 'test_data/smoke/git-pass-mapping.ini', 'get']) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(['pass', 'show', 'dev/mytest']) out, _ = capsys.readouterr() assert out == 'password=narf\n'
def test_smoke_resolve(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr( "sys.stdin", io.StringIO(""" protocol=https host=mytest.com"""), ) subprocess_mock = mocker.patch("subprocess.check_output") subprocess_mock.return_value = b"narf" passgithelper.main(["get"]) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(["pass", "show", "dev/mytest"]) out, _ = capsys.readouterr() assert out == "password=narf\n"
def test_regex_username_selection( self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr('sys.stdin', io.StringIO(''' protocol=https host=mytest.com''')) subprocess_mock = mocker.patch('subprocess.check_output') subprocess_mock.return_value = \ b'xyz\nsomeline\nmyuser: tester\n' \ b'morestuff\nmyuser: ignore' passgithelper.main(['get']) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(['pass', 'show', 'dev/mytest']) out, _ = capsys.readouterr() assert out == 'password=xyz\nusername=tester\n'
def test_wildcard_matching(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr('sys.stdin', io.StringIO(''' protocol=https host=wildcard.com path=subpath/bar.git''')) subprocess_mock = mocker.patch('subprocess.check_output') subprocess_mock.return_value = b'narf-wildcard' passgithelper.main(['get']) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with( ['pass', 'show', 'dev/wildcard.com']) out, _ = capsys.readouterr() assert out == 'password=narf-wildcard\n'
def test_prefix_skipping(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr( "sys.stdin", io.StringIO(""" protocol=https host=mytest.com"""), ) subprocess_mock = mocker.patch("subprocess.check_output") subprocess_mock.return_value = b"password: xyz\nuser: tester" passgithelper.main(["get"]) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(["pass", "show", "dev/mytest"]) out, _ = capsys.readouterr() assert out == "password=xyz\nusername=tester\n"
def test_username_provided(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr( "sys.stdin", io.StringIO(""" protocol=https host=plainline.com"""), ) subprocess_mock = mocker.patch("subprocess.check_output") subprocess_mock.return_value = b"password\nusername" passgithelper.main(["get"]) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(["pass", "show", "dev/plainline"]) out, _ = capsys.readouterr() assert out == "password=password\nusername=username\n"
def test_regex_username_selection(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr( "sys.stdin", io.StringIO(""" protocol=https host=mytest.com"""), ) subprocess_mock = mocker.patch("subprocess.check_output") subprocess_mock.return_value = (b"xyz\nsomeline\nmyuser: tester\n" b"morestuff\nmyuser: ignore") passgithelper.main(["get"]) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(["pass", "show", "dev/mytest"]) out, _ = capsys.readouterr() assert out == "password=xyz\nusername=tester\n"
def test_custom_mapping_used(self, xdg_dir, monkeypatch, mocker, capsys): # this would fail for the default file from with-username monkeypatch.setattr( "sys.stdin", io.StringIO(""" protocol=https host=mytest.com"""), ) subprocess_mock = mocker.patch("subprocess.check_output") subprocess_mock.return_value = b"narf" passgithelper.main( ["-m", "test_data/smoke/git-pass-mapping.ini", "get"]) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with(["pass", "show", "dev/mytest"]) out, _ = capsys.readouterr() assert out == "password=narf\n"
def test_wildcard_matching(self, xdg_dir, monkeypatch, mocker, capsys): monkeypatch.setattr( "sys.stdin", io.StringIO(""" protocol=https host=wildcard.com username=wildcard path=subpath/bar.git"""), ) subprocess_mock = mocker.patch("subprocess.check_output") subprocess_mock.return_value = b"narf-wildcard" passgithelper.main(["get"]) subprocess_mock.assert_called_once() subprocess_mock.assert_called_with( ["pass", "show", "dev/wildcard.com/wildcard"]) out, _ = capsys.readouterr() assert out == "password=narf-wildcard\n"
def test_wildcard_matching(self, capsys: Any) -> None: passgithelper.main(["get"]) out, _ = capsys.readouterr() assert out == "password=narf-wildcard\n"
def test_username_skipped_if_provided(self, capsys: Any) -> None: passgithelper.main(["get"]) out, _ = capsys.readouterr() assert out == "password=password\n"
def test_prefix_skipping(self, capsys: Any) -> None: passgithelper.main(["get"]) out, _ = capsys.readouterr() assert out == "password=xyz\nusername=tester\n"
def test_select_unknown_extractor(self) -> None: with pytest.raises(KeyError): passgithelper.main(["get"])
def test_regex_username_selection(self, capsys: Any) -> None: passgithelper.main(["get"]) out, _ = capsys.readouterr() assert out == "password=xyz\nusername=tester\n"
def test_help(self, capsys): with pytest.raises(SystemExit): passgithelper.main(['--help']) assert 'usage: ' in capsys.readouterr().out
def test_uses_configured_encoding(self, capsys: Any) -> None: passgithelper.main(["get"]) out, _ = capsys.readouterr() assert out == f"password=täßt\n"
def test_path_used_if_present_fails(self) -> None: with pytest.raises(ValueError, match="No mapping section"): passgithelper.main(["get"])
def test_path_used_if_present(self, capsys: Any) -> None: passgithelper.main(["get"]) out, _ = capsys.readouterr() assert out == "password=narf\n"
def test_entry_name_is_user(self, capsys: Any) -> None: passgithelper.main(["get"]) out, _ = capsys.readouterr() assert out == "password=xyz\nusername=myuser\n"
def test_uses_utf8_by_default(self, capsys: Any) -> None: passgithelper.main(["get"]) out, _ = capsys.readouterr() assert out == "password=täßt\n"