Exemplo n.º 1
0
def test_pts_ls():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt().with_master('password')
        pts.add('Example1', Generatable(salt='salt'))
        pts.add('Example2', Encrypted('verysecret'))
        pts.to_path('passthesalt')

        datetime_1 = pts.get('Example1').modified.strftime(
            '%Y-%m-%d %H:%M:%S.%f')
        datetime_2 = pts.get('Example2').modified.strftime(
            '%Y-%m-%d %H:%M:%S.%f')

        result = runner.invoke(cli, ['--path', 'passthesalt', 'ls'])
        expected = (
            'Label     Kind         Modified                    Salt\n'
            '--------  -----------  --------------------------  ------\n'
            f'Example1  generatable  {datetime_1}  salt\n'
            f'Example2  encrypted    {datetime_2}\n')
        assert result.output == expected

        result = runner.invoke(
            cli, ['--path', 'passthesalt', 'ls', '--kind', 'encrypted'])
        expected = ('Label     Kind       Modified\n'
                    '--------  ---------  --------------------------\n'
                    f'Example2  encrypted  {datetime_2}\n')
        assert result.output == expected
Exemplo n.º 2
0
def test_pts_add_exists():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt()
        pts.add('Example', Generatable(salt='salt'))
        pts.to_path('passthesalt')

        result = runner.invoke(cli, ['--path', 'passthesalt', 'add'],
                               input='Example\n')
        assert result.exit_code == 1
        assert "'Example' already exists" in result.output
Exemplo n.º 3
0
def test_pts_mv():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt()
        pts.add('Example', Generatable(salt='salt'))
        pts.to_path('passthesalt')

        result = runner.invoke(
            cli, ['--path', 'passthesalt', 'mv', 'Example', 'Example2'])
        assert result.exit_code == 0
        assert "Renamed 'Example' as 'Example2'!" in result.output
Exemplo n.º 4
0
def test_pts_rm():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt()
        pts.add('Example', Generatable(salt='salt'))
        pts.to_path('passthesalt')

        result = runner.invoke(cli, ['--path', 'passthesalt', 'rm'],
                               input='Example\ny\n')
        assert result.exit_code == 0
        assert "Removed 'Example'!" in result.output
Exemplo n.º 5
0
def test_pts_get_incorrect_master():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt(config=Config(master=Master('password')))
        pts.add('Example', Generatable(salt='salt'))
        pts.to_path('passthesalt')

        result = runner.invoke(
            cli,
            ['--path', 'passthesalt', 'get', '--no-clipboard'],
            input='Example\npasswor\npasswor\npasswor\n',
        )
        assert result.exit_code == 1
        assert 'three incorrect attempts' in result.output
Exemplo n.º 6
0
def test_pts_get_generated():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt(config=Config(master=Master('password')))
        pts.add('Example', Generatable(salt='salt'))
        pts.to_path('passthesalt')

        result = runner.invoke(
            cli,
            ['--path', 'passthesalt', 'get', '--no-clipboard'],
            input='Example\npassword\n',
        )
        assert result.exit_code == 0
        assert 'M%J+hUIcYqe=LSDtSq0d' in result.output
Exemplo n.º 7
0
def test_pts_get_encrypted():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt(config=Config(
            master=Master('password'))).with_master('password')
        pts.add('Example', Encrypted('verysecret'))
        pts.to_path('passthesalt')

        result = runner.invoke(
            cli,
            ['--path', 'passthesalt', 'get', '--no-clipboard'],
            input='Example\npassword\n',
        )
        assert result.exit_code == 0
        assert 'verysecret' in result.output
Exemplo n.º 8
0
def test_pts_diff():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt()
        pts.to_path('passthesalt_other')
        pts.add('Example', Generatable(salt='salt'))
        pts.to_path('passthesalt')

        result = runner.invoke(
            cli,
            ['--path', 'passthesalt', 'diff', '--path', 'passthesalt_other'])
        assert result.exit_code == 1
        assert (
            'Local store has the following extra/modified secrets:\nExample'
            in result.output)

        result = runner.invoke(
            cli,
            ['--path', 'passthesalt_other', 'diff', '--path', 'passthesalt'])
        assert result.exit_code == 1
        assert (
            'Remote store has the following extra/modified secrets:\nExample'
            in result.output)
Exemplo n.º 9
0
def pts_edit_encrypted_setup():
    pts = PassTheSalt(config=Config(
        master=Master('password'))).with_master('password')
    pts.add('Example', Encrypted('verysecret'))
    pts.to_path('passthesalt')
    return pts
Exemplo n.º 10
0
def pts_edit_generatable_setup():
    pts = PassTheSalt()
    pts.add('Example', Generatable(salt='salt'))
    pts.to_path('passthesalt')
    return pts