Skip to content

Commit 94627fe

Browse files
committed
Add tests for feature: detect incorrect password on init
1 parent bb9287b commit 94627fe

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ system, you must also run the `--upgrade` command in each repository:
3737
### Changed
3838

3939
- Improve check for incorrect password to avoid false report when transcrypt
40-
init is run with --force in a repo containing dirty files (#196)
40+
init is run with --force in a repo containing dirty files & add tests (#196)
4141

4242
### Fixed
4343

tests/_test_helper.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function init_transcrypt {
4343
"$BATS_TEST_DIRNAME"/../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
4444
}
4545

46+
function uninstall_transcrypt {
47+
"$BATS_TEST_DIRNAME"/../transcrypt --uninstall --yes
48+
}
49+
4650
function encrypt_named_file {
4751
filename="$1"
4852
content=$2

tests/test_init.bats

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)