Example #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
Example #2
0
def test_pts_encrypt():
    runner = CliRunner()

    with runner.isolated_filesystem():
        pts = PassTheSalt(config=Config(master=Master('password')))
        pts.to_path('passthesalt')

        result = runner.invoke(
            cli,
            ['--path', 'passthesalt', 'encrypt'],
            input='Example\nsecret\nsecret\npassword\n',
        )
        assert result.exit_code == 0
        assert "Stored 'Example'!" in result.output

        pts = PassTheSalt.from_path('passthesalt').with_master('password')
        assert isinstance(pts.get('Example'), Encrypted)
        assert pts.get('Example').get() == 'secret'