summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py30
-rw-r--r--tests/test_cli.py11
-rw-r--r--tests/test_envtoolkit_instance.py2
-rw-r--r--tests/test_envtoolkit_instance_static.py2
4 files changed, 18 insertions, 27 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index a4463fd..6cc8b9f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,5 +1,5 @@
1# etoolkit 1# etoolkit
2# Copyright (C) 2021-2024 Simeon Simeonov 2# Copyright (C) 2021-2026 Simeon Simeonov
3 3
4# This program is free software: you can redistribute it and/or modify 4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@ import json
20import pytest 20import pytest
21 21
22 22
23@pytest.fixture() 23@pytest.fixture
24def config_data(): 24def config_data():
25 """config_data for testing""" 25 """config_data for testing"""
26 26
@@ -59,7 +59,7 @@ def config_data():
59 } 59 }
60 60
61 61
62@pytest.fixture() 62@pytest.fixture
63def config_file(tmp_path, config_data): 63def config_file(tmp_path, config_data):
64 """Temporary config file for testing that includes config_data""" 64 """Temporary config file for testing that includes config_data"""
65 65
@@ -68,7 +68,7 @@ def config_file(tmp_path, config_data):
68 return str(cf) 68 return str(cf)
69 69
70 70
71@pytest.fixture() 71@pytest.fixture
72def long_encrypted_value(): 72def long_encrypted_value():
73 """enc. value corresponding to 'Nobody expects the Spanish inquisition'""" 73 """enc. value corresponding to 'Nobody expects the Spanish inquisition'"""
74 74
@@ -79,25 +79,25 @@ def long_encrypted_value():
79 ) 79 )
80 80
81 81
82@pytest.fixture() 82@pytest.fixture
83def long_value(): 83def long_value():
84 """standard value (> 32 bytes)""" 84 """standard value (> 32 bytes)"""
85 return 'Nobody expects the Spanish inquisition' 85 return 'Nobody expects the Spanish inquisition'
86 86
87 87
88@pytest.fixture() 88@pytest.fixture
89def master_password(): 89def master_password():
90 """Master passord""" 90 """Master passord"""
91 return 'The very secret passwd' 91 return 'The very secret passwd'
92 92
93 93
94@pytest.fixture() 94@pytest.fixture
95def new_master_password(): 95def new_master_password():
96 """Master passord""" 96 """Master passord"""
97 return 'New very secret passwd' 97 return 'New very secret passwd'
98 98
99 99
100@pytest.fixture() 100@pytest.fixture
101def non_random_bytes_32(): 101def non_random_bytes_32():
102 """always use the same bytes instead of os.urandom(32)""" 102 """always use the same bytes instead of os.urandom(32)"""
103 103
@@ -107,7 +107,7 @@ def non_random_bytes_32():
107 ) 107 )
108 108
109 109
110@pytest.fixture() 110@pytest.fixture
111def non_random_bytes_57(): 111def non_random_bytes_57():
112 """always use the same bytes instead of os.urandom(57)""" 112 """always use the same bytes instead of os.urandom(57)"""
113 113
@@ -118,14 +118,14 @@ def non_random_bytes_57():
118 ) 118 )
119 119
120 120
121@pytest.fixture() 121@pytest.fixture
122def nonexistent_config_file(tmp_path): 122def nonexistent_config_file(tmp_path):
123 """temporary config file for testing that includes config_data""" 123 """temporary config file for testing that includes config_data"""
124 124
125 return str(tmp_path / 'etoolkitt.json') 125 return str(tmp_path / 'etoolkitt.json')
126 126
127 127
128@pytest.fixture() 128@pytest.fixture
129def password_hash(): 129def password_hash():
130 """password hash for testing, corresponding to 'The very secret passwd'""" 130 """password hash for testing, corresponding to 'The very secret passwd'"""
131 131
@@ -135,7 +135,7 @@ def password_hash():
135 ) 135 )
136 136
137 137
138@pytest.fixture() 138@pytest.fixture
139def short_encrypted_value(): 139def short_encrypted_value():
140 """enc. value corresponding to 'secret1'""" 140 """enc. value corresponding to 'secret1'"""
141 141
@@ -145,7 +145,7 @@ def short_encrypted_value():
145 ) 145 )
146 146
147 147
148@pytest.fixture() 148@pytest.fixture
149def short_encrypted_value_v1(): 149def short_encrypted_value_v1():
150 """enc. value (enc-val 1) corresponding to 'secret1'""" 150 """enc. value (enc-val 1) corresponding to 'secret1'"""
151 151
@@ -155,13 +155,13 @@ def short_encrypted_value_v1():
155 ) 155 )
156 156
157 157
158@pytest.fixture() 158@pytest.fixture
159def short_value(): 159def short_value():
160 """standard value (< 32 bytes)""" 160 """standard value (< 32 bytes)"""
161 return 'secret1' 161 return 'secret1'
162 162
163 163
164@pytest.fixture() 164@pytest.fixture
165def wrong_master_password(): 165def wrong_master_password():
166 """Wrong master passord""" 166 """Wrong master passord"""
167 return 'the very secret passwd' 167 return 'the very secret passwd'
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 953abf4..b7913da 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1,5 +1,5 @@
1# etoolkit 1# etoolkit
2# Copyright (C) 2021-2024 Simeon Simeonov 2# Copyright (C) 2021-2026 Simeon Simeonov
3 3
4# This program is free software: you can redistribute it and/or modify 4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -38,7 +38,6 @@ def test_decrypt_v1(binput, capsys, config_file, master_password):
38 ): 38 ):
39 with pytest.raises(SystemExit) as exit_info: 39 with pytest.raises(SystemExit) as exit_info:
40 main(['-c', f'{config_file}', '-d']) 40 main(['-c', f'{config_file}', '-d'])
41 assert exit_info.type == SystemExit
42 assert exit_info.value.code == 0 41 assert exit_info.value.code == 0
43 assert capsys.readouterr().out.strip() == 'Decrypted value: bar' 42 assert capsys.readouterr().out.strip() == 'Decrypted value: bar'
44 43
@@ -60,7 +59,6 @@ def test_decrypt_v2(
60 ): 59 ):
61 with pytest.raises(SystemExit) as exit_info: 60 with pytest.raises(SystemExit) as exit_info:
62 main(['-c', f'{config_file}', '-d']) 61 main(['-c', f'{config_file}', '-d'])
63 assert exit_info.type == SystemExit
64 assert exit_info.value.code == 0 62 assert exit_info.value.code == 0
65 assert capsys.readouterr().out.strip() == ( 63 assert capsys.readouterr().out.strip() == (
66 f'Decrypted value: {short_value}' 64 f'Decrypted value: {short_value}'
@@ -88,7 +86,6 @@ def test_encrypt_with_echo(
88 ): 86 ):
89 with pytest.raises(SystemExit) as exit_info: 87 with pytest.raises(SystemExit) as exit_info:
90 main(['-c', f'{config_file}', '-e', '-E']) 88 main(['-c', f'{config_file}', '-e', '-E'])
91 assert exit_info.type == SystemExit
92 assert exit_info.value.code == 0 89 assert exit_info.value.code == 0
93 assert capsys.readouterr().out.strip() == ( 90 assert capsys.readouterr().out.strip() == (
94 f'Encrypted value: {short_encrypted_value}' 91 f'Encrypted value: {short_encrypted_value}'
@@ -116,7 +113,6 @@ def test_encrypt_without_echo(
116 ): 113 ):
117 with pytest.raises(SystemExit) as exit_info: 114 with pytest.raises(SystemExit) as exit_info:
118 main(['-c', f'{config_file}', '-e']) 115 main(['-c', f'{config_file}', '-e'])
119 assert exit_info.type == SystemExit
120 assert exit_info.value.code == 0 116 assert exit_info.value.code == 0
121 assert capsys.readouterr().out.strip() == ( 117 assert capsys.readouterr().out.strip() == (
122 f'Encrypted value: {short_encrypted_value}' 118 f'Encrypted value: {short_encrypted_value}'
@@ -139,11 +135,9 @@ def test_list(capsys, config_file, nonexistent_config_file):
139 135
140 with pytest.raises(SystemExit) as exit_info: 136 with pytest.raises(SystemExit) as exit_info:
141 main(['-c', nonexistent_config_file, '-l']) 137 main(['-c', nonexistent_config_file, '-l'])
142 assert exit_info.type == SystemExit
143 assert exit_info.value.code == errno.EIO 138 assert exit_info.value.code == errno.EIO
144 with pytest.raises(SystemExit) as exit_info: 139 with pytest.raises(SystemExit) as exit_info:
145 main(['-c', config_file, '-l']) 140 main(['-c', config_file, '-l'])
146 assert exit_info.type == SystemExit
147 assert exit_info.value.code == 0 141 assert exit_info.value.code == 0
148 assert capsys.readouterr().out.strip() == f'dev{os.linesep}secret' 142 assert capsys.readouterr().out.strip() == f'dev{os.linesep}secret'
149 143
@@ -153,7 +147,6 @@ def test_help(capsys):
153 147
154 with pytest.raises(SystemExit) as exit_info: 148 with pytest.raises(SystemExit) as exit_info:
155 main(['-h']) 149 main(['-h'])
156 assert exit_info.type == SystemExit
157 assert exit_info.value.code == 0 150 assert exit_info.value.code == 0
158 assert capsys.readouterr().out.startswith('usage: etoolkit') 151 assert capsys.readouterr().out.startswith('usage: etoolkit')
159 152
@@ -169,7 +162,6 @@ def test_generate_master_password_hash(
169 urandom.return_value = non_random_bytes_32 162 urandom.return_value = non_random_bytes_32
170 with pytest.raises(SystemExit) as exit_info: 163 with pytest.raises(SystemExit) as exit_info:
171 main(['--generate-master-password-hash']) 164 main(['--generate-master-password-hash'])
172 assert exit_info.type == SystemExit
173 assert exit_info.value.code == 0 165 assert exit_info.value.code == 0
174 assert capsys.readouterr().out.strip() == ( 166 assert capsys.readouterr().out.strip() == (
175 'Master password hash: pbkdf2_sha256$500000$uYpZM1VfAGq0CDZL2duITs076' 167 'Master password hash: pbkdf2_sha256$500000$uYpZM1VfAGq0CDZL2duITs076'
@@ -182,7 +174,6 @@ def test_version(capsys):
182 174
183 with pytest.raises(SystemExit) as exit_info: 175 with pytest.raises(SystemExit) as exit_info:
184 main(['-v']) 176 main(['-v'])
185 assert exit_info.type == SystemExit
186 assert exit_info.value.code == 0 177 assert exit_info.value.code == 0
187 assert capsys.readouterr().out.startswith( 178 assert capsys.readouterr().out.startswith(
188 f'etoolkit {etoolkit.__version__}' 179 f'etoolkit {etoolkit.__version__}'
diff --git a/tests/test_envtoolkit_instance.py b/tests/test_envtoolkit_instance.py
index f555f81..5137e9f 100644
--- a/tests/test_envtoolkit_instance.py
+++ b/tests/test_envtoolkit_instance.py
@@ -1,5 +1,5 @@
1# etoolkit 1# etoolkit
2# Copyright (C) 2021-2024 Simeon Simeonov 2# Copyright (C) 2021-2026 Simeon Simeonov
3 3
4# This program is free software: you can redistribute it and/or modify 4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
diff --git a/tests/test_envtoolkit_instance_static.py b/tests/test_envtoolkit_instance_static.py
index ee5cf9e..e13d439 100644
--- a/tests/test_envtoolkit_instance_static.py
+++ b/tests/test_envtoolkit_instance_static.py
@@ -1,5 +1,5 @@
1# etoolkit 1# etoolkit
2# Copyright (C) 2021-2024 Simeon Simeonov 2# Copyright (C) 2021-2026 Simeon Simeonov
3 3
4# This program is free software: you can redistribute it and/or modify 4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by