diff options
Diffstat (limited to 'tests/test_envtoolkit_instance_static.py')
| -rw-r--r-- | tests/test_envtoolkit_instance_static.py | 80 |
1 files changed, 36 insertions, 44 deletions
diff --git a/tests/test_envtoolkit_instance_static.py b/tests/test_envtoolkit_instance_static.py index e13d439..8c21a0f 100644 --- a/tests/test_envtoolkit_instance_static.py +++ b/tests/test_envtoolkit_instance_static.py | |||
| @@ -23,9 +23,10 @@ import etoolkit | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | @unittest.mock.patch('getpass.getpass') | 25 | @unittest.mock.patch('getpass.getpass') |
| 26 | def test_confirm_password_prompt(getpass, password_hash, master_password): | 26 | def test_confirm_password_prompt( |
| 27 | getpass: unittest.mock.MagicMock, password_hash: str, master_password: str | ||
| 28 | ) -> None: | ||
| 27 | """Tests the static EtoolkitInstance.confirm_password_prompt method""" | 29 | """Tests the static EtoolkitInstance.confirm_password_prompt method""" |
| 28 | |||
| 29 | getpass.return_value = master_password | 30 | getpass.return_value = master_password |
| 30 | assert ( | 31 | assert ( |
| 31 | etoolkit.EtoolkitInstance.confirm_password_prompt(password_hash) | 32 | etoolkit.EtoolkitInstance.confirm_password_prompt(password_hash) |
| @@ -37,9 +38,10 @@ def test_confirm_password_prompt(getpass, password_hash, master_password): | |||
| 37 | ) | 38 | ) |
| 38 | 39 | ||
| 39 | 40 | ||
| 40 | def test_decrypt_v1(master_password, short_encrypted_value_v1, short_value): | 41 | def test_decrypt_v1( |
| 42 | master_password: str, short_encrypted_value_v1: str, short_value: str | ||
| 43 | ) -> None: | ||
| 41 | """Tests the static EtoolkitInstance.decrypt method""" | 44 | """Tests the static EtoolkitInstance.decrypt method""" |
| 42 | |||
| 43 | assert ( | 45 | assert ( |
| 44 | etoolkit.EtoolkitInstance.decrypt( | 46 | etoolkit.EtoolkitInstance.decrypt( |
| 45 | master_password, short_encrypted_value_v1 | 47 | master_password, short_encrypted_value_v1 |
| @@ -59,10 +61,9 @@ def test_decrypt_v1(master_password, short_encrypted_value_v1, short_value): | |||
| 59 | 61 | ||
| 60 | 62 | ||
| 61 | def test_decrypt_v2_no_padding( | 63 | def test_decrypt_v2_no_padding( |
| 62 | master_password, long_encrypted_value, long_value | 64 | master_password: str, long_encrypted_value: str, long_value: str |
| 63 | ): | 65 | ) -> None: |
| 64 | """Tests the static EtoolkitInstance.decrypt method for v2 - no padding""" | 66 | """Tests the static EtoolkitInstance.decrypt method for v2 - no padding""" |
| 65 | |||
| 66 | assert ( | 67 | assert ( |
| 67 | etoolkit.EtoolkitInstance.decrypt( | 68 | etoolkit.EtoolkitInstance.decrypt( |
| 68 | master_password, long_encrypted_value | 69 | master_password, long_encrypted_value |
| @@ -80,10 +81,9 @@ def test_decrypt_v2_no_padding( | |||
| 80 | 81 | ||
| 81 | 82 | ||
| 82 | def test_decrypt_v2_with_padding( | 83 | def test_decrypt_v2_with_padding( |
| 83 | master_password, short_encrypted_value, short_value | 84 | master_password: str, short_encrypted_value: str, short_value: str |
| 84 | ): | 85 | ) -> None: |
| 85 | """Tests the static EtoolkitInstance.decrypt method for v2 with padding""" | 86 | """Tests the static EtoolkitInstance.decrypt method for v2 with padding""" |
| 86 | |||
| 87 | assert ( | 87 | assert ( |
| 88 | etoolkit.EtoolkitInstance.decrypt( | 88 | etoolkit.EtoolkitInstance.decrypt( |
| 89 | master_password, short_encrypted_value | 89 | master_password, short_encrypted_value |
| @@ -99,9 +99,8 @@ def test_decrypt_v2_with_padding( | |||
| 99 | assert exc_info.value.args[0] == f'Invalid tag when decrypting: {edata}' | 99 | assert exc_info.value.args[0] == f'Invalid tag when decrypting: {edata}' |
| 100 | 100 | ||
| 101 | 101 | ||
| 102 | def test_encrypt_no_padding(master_password, long_value): | 102 | def test_encrypt_no_padding(master_password: str, long_value: str) -> None: |
| 103 | """Tests the static EtoolkitInstance.encrypt method with a long string""" | 103 | """Tests the static EtoolkitInstance.encrypt method with a long string""" |
| 104 | |||
| 105 | edata = etoolkit.EtoolkitInstance.encrypt(master_password, long_value) | 104 | edata = etoolkit.EtoolkitInstance.encrypt(master_password, long_value) |
| 106 | assert edata.startswith('enc-val$2$') | 105 | assert edata.startswith('enc-val$2$') |
| 107 | assert len(edata) == 131 | 106 | assert len(edata) == 131 |
| @@ -111,9 +110,8 @@ def test_encrypt_no_padding(master_password, long_value): | |||
| 111 | ) | 110 | ) |
| 112 | 111 | ||
| 113 | 112 | ||
| 114 | def test_encrypt_with_padding(master_password, short_value): | 113 | def test_encrypt_with_padding(master_password: str, short_value: str) -> None: |
| 115 | """Tests the static EtoolkitInstance.encrypt method with a short string""" | 114 | """Tests the static EtoolkitInstance.encrypt method with a short string""" |
| 116 | |||
| 117 | edata = etoolkit.EtoolkitInstance.encrypt(master_password, short_value) | 115 | edata = etoolkit.EtoolkitInstance.encrypt(master_password, short_value) |
| 118 | assert edata.startswith('enc-val$2$') | 116 | assert edata.startswith('enc-val$2$') |
| 119 | assert len(edata) == 123 | 117 | assert len(edata) == 123 |
| @@ -125,14 +123,13 @@ def test_encrypt_with_padding(master_password, short_value): | |||
| 125 | 123 | ||
| 126 | @unittest.mock.patch('os.urandom') | 124 | @unittest.mock.patch('os.urandom') |
| 127 | def test_encrypt_staticly_no_padding( | 125 | def test_encrypt_staticly_no_padding( |
| 128 | urandom, | 126 | urandom: unittest.mock.MagicMock, |
| 129 | master_password, | 127 | master_password: str, |
| 130 | non_random_bytes_32, | 128 | non_random_bytes_32: bytes, |
| 131 | long_encrypted_value, | 129 | long_encrypted_value: str, |
| 132 | long_value, | 130 | long_value: str, |
| 133 | ): | 131 | ) -> None: |
| 134 | """Tests the EtoolkitInstance.encrypt method always with the same salt""" | 132 | """Tests the EtoolkitInstance.encrypt method always with the same salt""" |
| 135 | |||
| 136 | urandom.return_value = non_random_bytes_32 | 133 | urandom.return_value = non_random_bytes_32 |
| 137 | edata = etoolkit.EtoolkitInstance.encrypt(master_password, long_value) | 134 | edata = etoolkit.EtoolkitInstance.encrypt(master_password, long_value) |
| 138 | assert edata == long_encrypted_value | 135 | assert edata == long_encrypted_value |
| @@ -144,14 +141,13 @@ def test_encrypt_staticly_no_padding( | |||
| 144 | 141 | ||
| 145 | @unittest.mock.patch('os.urandom') | 142 | @unittest.mock.patch('os.urandom') |
| 146 | def test_encrypt_staticly_with_padding( | 143 | def test_encrypt_staticly_with_padding( |
| 147 | urandom, | 144 | urandom: unittest.mock.MagicMock, |
| 148 | master_password, | 145 | master_password: str, |
| 149 | non_random_bytes_57, | 146 | non_random_bytes_57: bytes, |
| 150 | short_encrypted_value, | 147 | short_encrypted_value: str, |
| 151 | short_value, | 148 | short_value: str, |
| 152 | ): | 149 | ) -> None: |
| 153 | """Tests the EtoolkitInstance.encrypt method always with the same salt""" | 150 | """Tests the EtoolkitInstance.encrypt method always with the same salt""" |
| 154 | |||
| 155 | urandom.return_value = non_random_bytes_57 | 151 | urandom.return_value = non_random_bytes_57 |
| 156 | edata = etoolkit.EtoolkitInstance.encrypt(master_password, short_value) | 152 | edata = etoolkit.EtoolkitInstance.encrypt(master_password, short_value) |
| 157 | assert edata == short_encrypted_value | 153 | assert edata == short_encrypted_value |
| @@ -160,9 +156,8 @@ def test_encrypt_staticly_with_padding( | |||
| 160 | ) | 156 | ) |
| 161 | 157 | ||
| 162 | 158 | ||
| 163 | def test_get_new_password_hash(master_password): | 159 | def test_get_new_password_hash(master_password: str) -> None: |
| 164 | """Tests the static EtoolkitInstance.get_new_password_hash method""" | 160 | """Tests the static EtoolkitInstance.get_new_password_hash method""" |
| 165 | |||
| 166 | new_hash = etoolkit.EtoolkitInstance.get_new_password_hash(master_password) | 161 | new_hash = etoolkit.EtoolkitInstance.get_new_password_hash(master_password) |
| 167 | # all pbkdf2 params are the same / hardcoded for the time being | 162 | # all pbkdf2 params are the same / hardcoded for the time being |
| 168 | assert new_hash.startswith('pbkdf2_sha256$500000$') | 163 | assert new_hash.startswith('pbkdf2_sha256$500000$') |
| @@ -173,9 +168,8 @@ def test_get_new_password_hash(master_password): | |||
| 173 | ) | 168 | ) |
| 174 | 169 | ||
| 175 | 170 | ||
| 176 | def test_parse_value(): | 171 | def test_parse_value() -> None: |
| 177 | """Tests the static EtoolkitInstance.parse_value method""" | 172 | """Tests the static EtoolkitInstance.parse_value method""" |
| 178 | |||
| 179 | assert ( | 173 | assert ( |
| 180 | etoolkit.EtoolkitInstance.parse_value('t%bs%t', {'%b': 'e', '%t': 't'}) | 174 | etoolkit.EtoolkitInstance.parse_value('t%bs%t', {'%b': 'e', '%t': 't'}) |
| 181 | == 'test' | 175 | == 'test' |
| @@ -183,10 +177,9 @@ def test_parse_value(): | |||
| 183 | 177 | ||
| 184 | 178 | ||
| 185 | def test_password_matches( | 179 | def test_password_matches( |
| 186 | password_hash, master_password, wrong_master_password | 180 | password_hash: str, master_password: str, wrong_master_password: str |
| 187 | ): | 181 | ) -> None: |
| 188 | """Tests the static EtoolkitInstance.password_matches method""" | 182 | """Tests the static EtoolkitInstance.password_matches method""" |
| 189 | |||
| 190 | assert etoolkit.EtoolkitInstance.password_matches( | 183 | assert etoolkit.EtoolkitInstance.password_matches( |
| 191 | master_password, password_hash | 184 | master_password, password_hash |
| 192 | ) | 185 | ) |
| @@ -197,16 +190,15 @@ def test_password_matches( | |||
| 197 | 190 | ||
| 198 | @unittest.mock.patch('os.urandom') | 191 | @unittest.mock.patch('os.urandom') |
| 199 | def test_reencrypt_staticly_with_padding( | 192 | def test_reencrypt_staticly_with_padding( |
| 200 | urandom, | 193 | urandom: unittest.mock.MagicMock, |
| 201 | master_password, | 194 | master_password: str, |
| 202 | new_master_password, | 195 | new_master_password: str, |
| 203 | non_random_bytes_57, | 196 | non_random_bytes_57: bytes, |
| 204 | short_encrypted_value, | 197 | short_encrypted_value: str, |
| 205 | short_encrypted_value_v1, | 198 | short_encrypted_value_v1: str, |
| 206 | short_value, | 199 | short_value: str, |
| 207 | ): | 200 | ) -> None: |
| 208 | """Tests the EtoolkitInstance.reencrypt method always with the same salt""" | 201 | """Tests the EtoolkitInstance.reencrypt method always with the same salt""" |
| 209 | |||
| 210 | urandom.return_value = non_random_bytes_57 | 202 | urandom.return_value = non_random_bytes_57 |
| 211 | # reencrypt (migrate) v1 to current using the same password | 203 | # reencrypt (migrate) v1 to current using the same password |
| 212 | edata = etoolkit.EtoolkitInstance.reencrypt( | 204 | edata = etoolkit.EtoolkitInstance.reencrypt( |
