From afec23fb17d82d3edd20a786fac7413a603a5a62 Mon Sep 17 00:00:00 2001 From: joshr Date: Sat, 18 Aug 2018 09:17:05 -0400 Subject: [PATCH] add test for -C option. fix typos in comments. --- tests/test_hide.bats | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/test_hide.bats b/tests/test_hide.bats index baf82a1c..cd9e35f1 100644 --- a/tests/test_hide.bats +++ b/tests/test_hide.bats @@ -32,11 +32,37 @@ function teardown { [ "$status" -eq 0 ] [ "$output" = "done. all 1 files are hidden." ] - # New files should be crated: + # New files should be created: local encrypted_file=$(_get_encrypted_filename "$FILE_TO_HIDE") [ -f "$encrypted_file" ] } +@test "run 'hide' with '-C'" { + + # attempt to alter permissions on input file + chmod o-rwx "$FILE_TO_HIDE" + + run git secret hide -C + + # Command must execute normally: + [ "$status" -eq 0 ] + [ "$output" = "done. all 1 files are hidden." ] + + # New files should be created: + local encrypted_file=$(_get_encrypted_filename "$FILE_TO_HIDE") + [ -f "$encrypted_file" ] + + # permissions should match. We don't have access to SECRETS_OCTAL_PERMS_COMMAND here + local secret_perm + local file_perm + secret_perm=$(ls -l "$encrypted_file" | cut -d' ' -f1) + file_perm=$(ls -l "$FILE_TO_HIDE" | cut -d' ' -f1) + echo "# secret_perm: $secret_perm, file_perm: $file_perm" >&3 + + [ "$secret_perm" = "$file_perm" ] + +} + @test "run 'hide' from inside subdirectory" { # Preparations: local root_dir='test_sub_dir' @@ -101,7 +127,7 @@ function teardown { [ "${lines[0]}" = "done. all 1 files are hidden." ] [ "${lines[1]}" = "cleaning up..." ] - # New files should be crated: + # New files should be created: local encrypted_file=$(_get_encrypted_filename "$FILE_TO_HIDE") [ -f "$encrypted_file" ] } @@ -130,7 +156,7 @@ function teardown { # no changes should occur to path_mappings files cmp -s "${path_mappings}" "${path_mappings}.bak" - # New files should be crated: + # New files should be created: local encrypted_file=$(_get_encrypted_filename "$FILE_TO_HIDE") [ -f "$encrypted_file" ] }