summaryrefslogtreecommitdiff
path: root/tests/test_cli.py
diff options
context:
space:
mode:
authorSimeon Simeonov2024-05-13 21:52:13 +0200
committerSimeon Simeonov2024-05-13 21:52:13 +0200
commit08a3280b062af83ee50fa139d7827d954907886e (patch)
tree8e1d3f3117d05b3ad779d070ec30ddbbe242e62b /tests/test_cli.py
parentbb9a844e22134a2537652ea14f93e82acb4ee380 (diff)
Implement re-encryption support2.0.0
Diffstat (limited to 'tests/test_cli.py')
-rw-r--r--tests/test_cli.py57
1 files changed, 36 insertions, 21 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 1693a2b..953abf4 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -44,14 +44,17 @@ def test_decrypt_v1(binput, capsys, config_file, master_password):
44 44
45 45
46@unittest.mock.patch('builtins.input') 46@unittest.mock.patch('builtins.input')
47def test_decrypt_v2(binput, capsys, config_file, master_password): 47def test_decrypt_v2(
48 binput,
49 capsys,
50 config_file,
51 master_password,
52 short_encrypted_value,
53 short_value,
54):
48 """Tests v2 decryption via the CLI interface""" 55 """Tests v2 decryption via the CLI interface"""
49 56
50 binput.return_value = ( 57 binput.return_value = short_encrypted_value
51 'enc-val$2$RCSZqq9pWrRDoCVYVHopyu1LzaJGfv8roVviq'
52 'rLTBxM=$+Yo6Ya2MAVcBLTQHuATkyFc+dzYsL/E'
53 'SvA6ofOUDsiKZvIff35cUHAmoNxVuGG+MXv4='
54 )
55 with unittest.mock.patch.dict( 58 with unittest.mock.patch.dict(
56 os.environ, {'ETOOLKIT_MASTER_PASSWORD': master_password} 59 os.environ, {'ETOOLKIT_MASTER_PASSWORD': master_password}
57 ): 60 ):
@@ -59,18 +62,27 @@ def test_decrypt_v2(binput, capsys, config_file, master_password):
59 main(['-c', f'{config_file}', '-d']) 62 main(['-c', f'{config_file}', '-d'])
60 assert exit_info.type == SystemExit 63 assert exit_info.type == SystemExit
61 assert exit_info.value.code == 0 64 assert exit_info.value.code == 0
62 assert capsys.readouterr().out.strip() == 'Decrypted value: bar' 65 assert capsys.readouterr().out.strip() == (
66 f'Decrypted value: {short_value}'
67 )
63 68
64 69
65@unittest.mock.patch('os.urandom') 70@unittest.mock.patch('os.urandom')
66@unittest.mock.patch('builtins.input') 71@unittest.mock.patch('builtins.input')
67def test_encrypt_with_echo( 72def test_encrypt_with_echo(
68 binput, urandom, capsys, non_random_bytes_61, config_file, master_password 73 binput,
74 urandom,
75 capsys,
76 non_random_bytes_57,
77 config_file,
78 master_password,
79 short_encrypted_value,
80 short_value,
69): 81):
70 """Tests encryption via the CLI interface""" 82 """Tests encryption via the CLI interface"""
71 83
72 binput.return_value = 'bar' 84 binput.return_value = short_value
73 urandom.return_value = non_random_bytes_61 85 urandom.return_value = non_random_bytes_57
74 with unittest.mock.patch.dict( 86 with unittest.mock.patch.dict(
75 os.environ, {'ETOOLKIT_MASTER_PASSWORD': master_password} 87 os.environ, {'ETOOLKIT_MASTER_PASSWORD': master_password}
76 ): 88 ):
@@ -79,21 +91,26 @@ def test_encrypt_with_echo(
79 assert exit_info.type == SystemExit 91 assert exit_info.type == SystemExit
80 assert exit_info.value.code == 0 92 assert exit_info.value.code == 0
81 assert capsys.readouterr().out.strip() == ( 93 assert capsys.readouterr().out.strip() == (
82 'Encrypted value: enc-val$2$RCSZqq9pWrRDoCVYVHopyu1LzaJGfv8roVviq' 94 f'Encrypted value: {short_encrypted_value}'
83 'rLTBxM=$+Yo6Ya2MAVcBLTQHuATkyFc+dzYsL/E'
84 'SvA6ofOUDsiKZvIff35cUHAmoNxVuGG+MXv4='
85 ) 95 )
86 96
87 97
88@unittest.mock.patch('os.urandom') 98@unittest.mock.patch('os.urandom')
89@unittest.mock.patch('getpass.getpass') 99@unittest.mock.patch('getpass.getpass')
90def test_encrypt_without_echo( 100def test_encrypt_without_echo(
91 getpass, urandom, capsys, non_random_bytes_61, config_file, master_password 101 getpass,
102 urandom,
103 capsys,
104 non_random_bytes_57,
105 config_file,
106 master_password,
107 short_encrypted_value,
108 short_value,
92): 109):
93 """Tests encryption via the CLI interface""" 110 """Tests encryption via the CLI interface"""
94 111
95 getpass.return_value = 'bar' 112 getpass.return_value = short_value
96 urandom.return_value = non_random_bytes_61 113 urandom.return_value = non_random_bytes_57
97 with unittest.mock.patch.dict( 114 with unittest.mock.patch.dict(
98 os.environ, {'ETOOLKIT_MASTER_PASSWORD': master_password} 115 os.environ, {'ETOOLKIT_MASTER_PASSWORD': master_password}
99 ): 116 ):
@@ -102,13 +119,11 @@ def test_encrypt_without_echo(
102 assert exit_info.type == SystemExit 119 assert exit_info.type == SystemExit
103 assert exit_info.value.code == 0 120 assert exit_info.value.code == 0
104 assert capsys.readouterr().out.strip() == ( 121 assert capsys.readouterr().out.strip() == (
105 'Encrypted value: enc-val$2$RCSZqq9pWrRDoCVYVHopyu1LzaJGfv8roVviq' 122 f'Encrypted value: {short_encrypted_value}'
106 'rLTBxM=$+Yo6Ya2MAVcBLTQHuATkyFc+dzYsL/E'
107 'SvA6ofOUDsiKZvIff35cUHAmoNxVuGG+MXv4='
108 ) 123 )
109 124
110 125
111def test_fetch_encrypted_value(config_file, master_password): 126def test_fetch_encrypted_value(config_file, master_password, short_value):
112 """Tests decryption of encrypted value""" 127 """Tests decryption of encrypted value"""
113 128
114 with unittest.mock.patch.dict( 129 with unittest.mock.patch.dict(
@@ -116,7 +131,7 @@ def test_fetch_encrypted_value(config_file, master_password):
116 ): 131 ):
117 assert os.environ.get('ETOOLKIT_TEST_PASSWORD') is None 132 assert os.environ.get('ETOOLKIT_TEST_PASSWORD') is None
118 main(['-c', f'{config_file}', '-q', '-s', '/bin/false', 'secret']) 133 main(['-c', f'{config_file}', '-q', '-s', '/bin/false', 'secret'])
119 assert os.environ.get('ETOOLKIT_TEST_PASSWORD') == 'bar' 134 assert os.environ.get('ETOOLKIT_TEST_PASSWORD') == short_value
120 135
121 136
122def test_list(capsys, config_file, nonexistent_config_file): 137def test_list(capsys, config_file, nonexistent_config_file):