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
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
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
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
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
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
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
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'
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)
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
def pts_edit_generatable_setup(): pts = PassTheSalt() pts.add('Example', Generatable(salt='salt')) pts.to_path('passthesalt') return pts