@@ -188,6 +188,56 @@ def test_encrypt_file_requires_valid_input_file(self):
188188 with pytest .raises (Exception ):
189189 imapbackup .encrypt_file_gpg ("/tmp/nonexistent-file-xyz-123.txt" , "test@example.com" )
190190
191+ @patch ('subprocess.run' )
192+ @patch ('os.path.exists' )
193+ def test_encrypt_file_uses_no_auto_key_retrieve_flag (self , mock_exists , mock_subprocess , temp_dir ):
194+ """Test that encrypt_file_gpg uses --no-auto-key-retrieve flag to prevent WKD lookups"""
195+ import os
196+
197+ # Create a test file
198+ test_file = os .path .join (temp_dir , "test.txt" )
199+ with open (test_file , 'w' ) as f :
200+ f .write ("test data" )
201+
202+ # Mock os.path.exists to return True for the output file
203+ def exists_side_effect (path ):
204+ if path .endswith ('.gpg' ):
205+ return True
206+ return os .path .exists (path )
207+ mock_exists .side_effect = exists_side_effect
208+
209+ # Mock subprocess.run to succeed
210+ mock_result = MagicMock ()
211+ mock_result .returncode = 0
212+ mock_subprocess .return_value = mock_result
213+
214+ # Call encrypt_file_gpg
215+ try :
216+ result = imapbackup .encrypt_file_gpg (test_file , "test@example.com" )
217+ except :
218+ pass # We're only interested in the subprocess call, not the result
219+
220+ # Verify subprocess.run was called
221+ assert mock_subprocess .called
222+
223+ # Get the command that was passed to subprocess.run
224+ call_args = mock_subprocess .call_args
225+ cmd = call_args [0 ][0 ] # First positional argument is the command list
226+
227+ # Verify --no-auto-key-retrieve flag is present
228+ assert '--no-auto-key-retrieve' in cmd , \
229+ "GPG command must include --no-auto-key-retrieve flag to prevent WKD auto-retrieval"
230+
231+ # Verify other essential flags are present
232+ assert 'gpg' in cmd [0 ]
233+ assert '--batch' in cmd
234+ assert '--yes' in cmd
235+ assert '--trust-model' in cmd
236+ assert 'always' in cmd
237+ assert '--encrypt' in cmd
238+ assert '--recipient' in cmd
239+ assert 'test@example.com' in cmd
240+
191241
192242@pytest .mark .unit
193243class TestS3EncryptionFailures :
0 commit comments