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
Exemplo n.º 2
0
    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"
Exemplo n.º 3
0
 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'])
Exemplo n.º 5
0
    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'
Exemplo n.º 9
0
    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"),
            ]
Exemplo n.º 10
0
    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'
Exemplo n.º 11
0
    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'
Exemplo n.º 12
0
    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"
Exemplo n.º 13
0
    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'
Exemplo n.º 14
0
    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'
Exemplo n.º 15
0
    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"
Exemplo n.º 16
0
    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"
Exemplo n.º 17
0
    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"
Exemplo n.º 18
0
    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"
Exemplo n.º 19
0
    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"
Exemplo n.º 20
0
    def test_wildcard_matching(self, capsys: Any) -> None:
        passgithelper.main(["get"])

        out, _ = capsys.readouterr()
        assert out == "password=narf-wildcard\n"
Exemplo n.º 21
0
    def test_username_skipped_if_provided(self, capsys: Any) -> None:
        passgithelper.main(["get"])

        out, _ = capsys.readouterr()
        assert out == "password=password\n"
Exemplo n.º 22
0
    def test_prefix_skipping(self, capsys: Any) -> None:
        passgithelper.main(["get"])

        out, _ = capsys.readouterr()
        assert out == "password=xyz\nusername=tester\n"
Exemplo n.º 23
0
 def test_select_unknown_extractor(self) -> None:
     with pytest.raises(KeyError):
         passgithelper.main(["get"])
Exemplo n.º 24
0
    def test_regex_username_selection(self, capsys: Any) -> None:
        passgithelper.main(["get"])

        out, _ = capsys.readouterr()
        assert out == "password=xyz\nusername=tester\n"
Exemplo n.º 25
0
    def test_help(self, capsys):
        with pytest.raises(SystemExit):
            passgithelper.main(['--help'])

        assert 'usage: ' in capsys.readouterr().out
Exemplo n.º 26
0
    def test_uses_configured_encoding(self, capsys: Any) -> None:
        passgithelper.main(["get"])

        out, _ = capsys.readouterr()
        assert out == f"password=täßt\n"
Exemplo n.º 27
0
 def test_path_used_if_present_fails(self) -> None:
     with pytest.raises(ValueError, match="No mapping section"):
         passgithelper.main(["get"])
Exemplo n.º 28
0
    def test_path_used_if_present(self, capsys: Any) -> None:
        passgithelper.main(["get"])

        out, _ = capsys.readouterr()
        assert out == "password=narf\n"
Exemplo n.º 29
0
    def test_entry_name_is_user(self, capsys: Any) -> None:
        passgithelper.main(["get"])

        out, _ = capsys.readouterr()
        assert out == "password=xyz\nusername=myuser\n"
Exemplo n.º 30
0
    def test_uses_utf8_by_default(self, capsys: Any) -> None:
        passgithelper.main(["get"])

        out, _ = capsys.readouterr()
        assert out == "password=täßt\n"