@@ -168,3 +168,46 @@ SETUP_SKIP_INIT_TRANSCRYPT=1
168168 [ " ${lines[0]} " = " ==> sensitive_file <==" ]
169169 [ " ${lines[1]} " = " $SECRET_CONTENT_ENC " ]
170170}
171+
172+ @test " crypt: warn on incorrect password as indicated by dirty files after init" {
173+ init_transcrypt
174+
175+ SECRET_CONTENT=" My secret content"
176+ SECRET_CONTENT_ENC=" U2FsdGVkX1/6ilR0PmJpAyCF7iG3+k4aBwbgVd48WaQXznsg42nXbQrlWsf/qiCg"
177+
178+ encrypt_named_file sensitive_file " $SECRET_CONTENT "
179+
180+ # Clear the password and reset the repo
181+ uninstall_transcrypt
182+ git reset --hard
183+
184+ # Init transcrypt with wrong password, command fails with error message
185+ run " $BATS_TEST_DIRNAME " /../transcrypt --cipher=aes-256-cbc --password=' WRONG' --yes
186+ [ " $status " -eq 1 ]
187+ [ " ${lines[0]} " = " transcrypt: Unexpected new dirty files in the repository when configured by transcrypt, please check your password." ]
188+ }
189+
190+ @test " crypt: warn on incorrect password as indicated by dirty files after init when forced" {
191+ init_transcrypt
192+
193+ SECRET_CONTENT=" My secret content"
194+ SECRET_CONTENT_ENC=" U2FsdGVkX1/6ilR0PmJpAyCF7iG3+k4aBwbgVd48WaQXznsg42nXbQrlWsf/qiCg"
195+
196+ encrypt_named_file sensitive_file " $SECRET_CONTENT "
197+
198+ # Clear the password and reset the repo
199+ uninstall_transcrypt
200+ git reset --hard
201+
202+ # Dirty repo before init, to check pre- and post-init dirty files counts
203+ # work despite the pre-existing dirty file
204+ echo " Dirty file" > dirty_file
205+ git add dirty_file
206+
207+ # Force init transcrypt with wrong password, command fails with error message
208+ run " $BATS_TEST_DIRNAME " /../transcrypt --force --cipher=aes-256-cbc --password=' WRONG' --yes
209+ [ " $status " -eq 1 ]
210+ [ " ${lines[0]} " = " transcrypt: Unexpected new dirty files in the repository when configured by transcrypt, please check your password." ]
211+
212+ rm dirty_file
213+ }
0 commit comments