Merge pull request #239 from joshrabinowitz/spaces-in-filenames

Spaces in filenames
pull/242/head
Josh Rabinowitz 6 years ago committed by GitHub
commit d5c138ab60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -176,6 +176,7 @@ function _delete_line {
} }
# this sets the global variable 'filename'
function _temporary_file { function _temporary_file {
# This function creates temporary file # This function creates temporary file
# which will be removed on system exit. # which will be removed on system exit.
@ -258,7 +259,7 @@ function _fsdb_rm_record {
local key="$1" # required local key="$1" # required
local fsdb="$2" # required local fsdb="$2" # required
_gawk_inplace -v key="$key" "'$AWK_FSDB_RM_RECORD'" "$fsdb" _gawk_inplace -v key="'$key'" "'$AWK_FSDB_RM_RECORD'" "$fsdb"
} }
function _fsdb_clear_hashes { function _fsdb_clear_hashes {
@ -462,6 +463,7 @@ function _find_and_clean_formatted {
} }
# this sets the global array variable 'filenames'
function _list_all_added_files { function _list_all_added_files {
local path_mappings local path_mappings
path_mappings=$(_get_secrets_dir_paths_mapping) path_mappings=$(_get_secrets_dir_paths_mapping)
@ -470,9 +472,14 @@ function _list_all_added_files {
_abort "$path_mappings is missing." _abort "$path_mappings is missing."
fi fi
local filename
filenames=() # not local
while read -r line; do while read -r line; do
_get_record_filename "$line" filename=$(_get_record_filename "$line")
filenames+=("$filename")
done < "$path_mappings" done < "$path_mappings"
declare -a filenames # so caller can get list from filenames array
} }

@ -22,16 +22,16 @@ function changes {
_user_required _user_required
local filenames="$*" filenames=("$@") # list of positional params. global.
if [[ -z "$filenames" ]]; then if [[ ${#filenames[@]} -eq 0 ]]; then
# Checking if no filenames are passed, show diff for all files. # Checking if no filenames are passed, show diff for all files.
filenames=$(_list_all_added_files) _list_all_added_files # this sets the array variable 'filenames'
fi fi
IFS=' IFS='
' '
for filename in $filenames; do for filename in "${filenames[@]}"; do
local decrypted local decrypted
local diff_result local diff_result

@ -74,7 +74,7 @@ function _optional_fsdb_update_hash {
fsdb=$(_get_secrets_dir_paths_mapping) fsdb=$(_get_secrets_dir_paths_mapping)
_gawk_inplace -v key="$key" -v hash="$hash" "'$AWK_FSDB_UPDATE_HASH'" "$fsdb" _gawk_inplace -v key="'$key'" -v hash="$hash" "'$AWK_FSDB_UPDATE_HASH'" "$fsdb"
} }

@ -18,5 +18,10 @@ function list {
_user_required _user_required
# Command logic: # Command logic:
_list_all_added_files filenames=()
_list_all_added_files # exports 'filenames' array
local filename
for filename in "${filenames[@]}"; do
echo "$filename"
done
} }

@ -33,8 +33,6 @@ function remove {
normalized_path=$(_git_normalize_filename "$item") normalized_path=$(_git_normalize_filename "$item")
path=$(_append_root_path "$normalized_path") path=$(_append_root_path "$normalized_path")
echo "$item -> $normalized_path -> $path"
# Checking if file exists: # Checking if file exists:
if [[ ! -f "$path" ]]; then if [[ ! -f "$path" ]]; then
_abort "file not found: $item" _abort "file not found: $item"

@ -37,6 +37,15 @@ TEST_DEFAULT_USER="user1"
TEST_SECOND_USER="user2" # shellcheck disable=2034 TEST_SECOND_USER="user2" # shellcheck disable=2034
TEST_ATTACKER_USER="attacker1" # shellcheck disable=2034 TEST_ATTACKER_USER="attacker1" # shellcheck disable=2034
#TEST_DEFAULT_FILENAME="file_one" # no spaces
#TEST_SECOND_FILENAME="file_two" # no spaces
#TEST_THIRD_FILENAME="file_three" # no spaces
TEST_DEFAULT_FILENAME="space file" # has spaces
TEST_SECOND_FILENAME="space file two" # has spaces
TEST_THIRD_FILENAME="space file three" # has spaces
function test_user_password { function test_user_password {
# It was set on key creation: # It was set on key creation:
echo "${1}pass" echo "${1}pass"

@ -21,7 +21,7 @@ function teardown {
@test "run 'add' normally" { @test "run 'add' normally" {
# Preparations: # Preparations:
local filename="local_file" local filename="$TEST_DEFAULT_FILENAME"
echo "content" > "$filename" echo "content" > "$filename"
echo "$filename" > ".gitignore" echo "$filename" > ".gitignore"
@ -41,7 +41,7 @@ function teardown {
@test "run 'add' for unignored file" { @test "run 'add' for unignored file" {
local test_file='test_file' local test_file="$TEST_DEFAULT_FILENAME"
touch "$test_file" touch "$test_file"
echo "content" > "$test_file" echo "content" > "$test_file"
@ -53,7 +53,7 @@ function teardown {
@test "run 'add' for unignored file with '-i'" { @test "run 'add' for unignored file with '-i'" {
local test_file='test_file.auto_ignore' local test_file='test_file.auto_ignore' # TODO - paramaterize filename
touch "$test_file" touch "$test_file"
echo "content" > "$test_file" echo "content" > "$test_file"
@ -112,7 +112,7 @@ function teardown {
local root='test_dir' local root='test_dir'
local node="$root/node" local node="$root/node"
local sibling="$root/sibling" local sibling="$root/sibling"
local test_file="$node/test_file" local test_file="$node/$TEST_DEFAULT_FILENAME"
local current_dir=$(pwd) local current_dir=$(pwd)
mkdir -p "$node" mkdir -p "$node"
@ -124,7 +124,7 @@ function teardown {
cd "$sibling" cd "$sibling"
# Testing: # Testing:
run git secret add "../node/test_file" run git secret add "../node/$TEST_DEFAULT_FILENAME"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "$output" == *"1 item(s) added."* ]] [[ "$output" == *"1 item(s) added."* ]]
@ -143,7 +143,7 @@ function teardown {
@test "run 'add' for file in subfolder" { @test "run 'add' for file in subfolder" {
# Preparations: # Preparations:
local test_file='test_file' local test_file="$TEST_DEFAULT_FILENAME"
local test_dir='test_dir' local test_dir='test_dir'
mkdir -p "$test_dir" mkdir -p "$test_dir"
@ -163,7 +163,7 @@ function teardown {
@test "run 'add' twice for one file" { @test "run 'add' twice for one file" {
# Preparations: # Preparations:
local filename="local_file" local filename="$TEST_DEFAULT_FILENAME"
echo "content" > "$filename" echo "content" > "$filename"
echo "$filename" > ".gitignore" echo "$filename" > ".gitignore"
@ -187,11 +187,11 @@ function teardown {
@test "run 'add' for multiple files" { @test "run 'add' for multiple files" {
# Preparations: # Preparations:
local filename1="local_file1" local filename1="$TEST_DEFAULT_FILENAME"
echo "content1" > "$filename1" echo "content1" > "$filename1"
echo "$filename1" > ".gitignore" echo "$filename1" > ".gitignore"
local filename2="local_file2" local filename2="$TEST_SECOND_FILENAME"
echo "content2" > "$filename2" echo "content2" > "$filename2"
echo "$filename2" >> ".gitignore" echo "$filename2" >> ".gitignore"

@ -2,7 +2,7 @@
load _test_base load _test_base
FILE_TO_HIDE="file_to_hide" FILE_TO_HIDE="$TEST_DEFAULT_FILENAME"
FILE_CONTENTS="hidden content юникод" FILE_CONTENTS="hidden content юникод"
FINGERPRINT="" FINGERPRINT=""

@ -2,8 +2,8 @@
load _test_base load _test_base
FILE_TO_HIDE="file_to_hide" FILE_TO_HIDE="$TEST_DEFAULT_FILENAME"
SECOND_FILE_TO_HIDE="second_file_to_hide" SECOND_FILE_TO_HIDE="$TEST_SECOND_FILENAME"
FILE_CONTENTS="hidden content юникод" FILE_CONTENTS="hidden content юникод"
FINGERPRINT="" FINGERPRINT=""
@ -54,7 +54,7 @@ function teardown {
@test "run 'changes' with hidden file missing" { @test "run 'changes' with hidden file missing" {
local password=$(test_user_password "$TEST_DEFAULT_USER") local password=$(test_user_password "$TEST_DEFAULT_USER")
local encrypted_file=$(_get_encrypted_filename $FILE_TO_HIDE) local encrypted_file=$(_get_encrypted_filename "$FILE_TO_HIDE")
rm "$encrypted_file" rm "$encrypted_file"
run git secret changes -d "$TEST_GPG_HOMEDIR" -p "$password" "$FILE_TO_HIDE" run git secret changes -d "$TEST_GPG_HOMEDIR" -p "$password" "$FILE_TO_HIDE"

@ -2,8 +2,8 @@
load _test_base load _test_base
FIRST_FILE="file_to_hide1" FIRST_FILE="$TEST_DEFAULT_FILENAME"
SECOND_FILE="file_to_hide2" SECOND_FILE="$TEST_SECOND_FILENAME"
FOLDER="somedir" FOLDER="somedir"
FILE_IN_FOLDER="${FOLDER}/file_to_hide3" FILE_IN_FOLDER="${FOLDER}/file_to_hide3"

@ -2,7 +2,7 @@
load _test_base load _test_base
FILE_TO_HIDE="file_to_hide" FILE_TO_HIDE="$TEST_DEFAULT_FILENAME"
FILE_CONTENTS="hidden content юникод" FILE_CONTENTS="hidden content юникод"
@ -61,7 +61,7 @@ function teardown {
@test "run 'hide' with missing file" { @test "run 'hide' with missing file" {
# Preparations: # Preparations:
local second_file="second_file.txt" local second_file="$TEST_SECOND_FILENAME"
local second_content="some content" local second_content="some content"
set_state_secret_add "$second_file" "$second_content" set_state_secret_add "$second_file" "$second_content"
@ -77,7 +77,7 @@ function teardown {
@test "run 'hide' with multiple files" { @test "run 'hide' with multiple files" {
# Preparations: # Preparations:
local second_file="second_file.txt" local second_file="$TEST_SECOND_FILENAME"
local second_content="some content" local second_content="some content"
set_state_secret_add "$second_file" "$second_content" set_state_secret_add "$second_file" "$second_content"
@ -183,7 +183,7 @@ function teardown {
# Preparations: # Preparations:
local root_dir='test_sub_dir' local root_dir='test_sub_dir'
mkdir -p "$root_dir" mkdir -p "$root_dir"
local second_file="$root_dir/second_file.txt" local second_file="$root_dir/$TEST_SECOND_FILENAME"
local second_content="some content" local second_content="some content"
set_state_secret_add "$second_file" "$second_content" set_state_secret_add "$second_file" "$second_content"

@ -2,8 +2,8 @@
load _test_base load _test_base
FIRST_FILE="file_to_hide1" FIRST_FILE="$TEST_DEFAULT_FILENAME"
SECOND_FILE="file_to_hide2" SECOND_FILE="$TEST_SECOND_FILENAME"
function setup { function setup {
@ -55,8 +55,8 @@ function _has_line {
[ "$other_files" -eq 0 ] [ "$other_files" -eq 0 ]
# Both files should be present: # Both files should be present:
local first_encrypted_file=$(_get_encrypted_filename $FIRST_FILE) local first_encrypted_file=$(_get_encrypted_filename "$FIRST_FILE")
local second_encrypted_file=$(_get_encrypted_filename $SECOND_FILE) local second_encrypted_file=$(_get_encrypted_filename "$SECOND_FILE")
[ -f "$first_encrypted_file" ] [ -f "$first_encrypted_file" ]
[ -f "$second_encrypted_file" ] [ -f "$second_encrypted_file" ]
@ -74,8 +74,8 @@ function _has_line {
[ "$second_line" -eq 1 ] [ "$second_line" -eq 1 ]
# Both files should be present: # Both files should be present:
local first_encrypted_file=$(_get_encrypted_filename $FIRST_FILE) local first_encrypted_file=$(_get_encrypted_filename "$FIRST_FILE")
local second_encrypted_file=$(_get_encrypted_filename $SECOND_FILE) local second_encrypted_file=$(_get_encrypted_filename "$SECOND_FILE")
[ -f "$first_encrypted_file" ] [ -f "$first_encrypted_file" ]
[ -f "$second_encrypted_file" ] [ -f "$second_encrypted_file" ]
@ -88,7 +88,7 @@ function _has_line {
# Prepartions: # Prepartions:
local folder="somedir" local folder="somedir"
local file_in_folder="$folder/file_to_hide3" local file_in_folder="$folder/$TEST_THIRD_FILENAME"
mkdir -p "$folder" mkdir -p "$folder"
set_state_secret_add "$file_in_folder" "somecontent3" set_state_secret_add "$file_in_folder" "somecontent3"
@ -101,7 +101,7 @@ function _has_line {
local mapping_contains=$(_has_line "$file_in_folder") local mapping_contains=$(_has_line "$file_in_folder")
[ "$mapping_contains" -eq 1 ] [ "$mapping_contains" -eq 1 ]
local encrypted_file=$(_get_encrypted_filename $file_in_folder) local encrypted_file=$(_get_encrypted_filename "$file_in_folder")
[ -f "$encrypted_file" ] [ -f "$encrypted_file" ]
# Cleaning up: # Cleaning up:
@ -118,8 +118,8 @@ function _has_line {
local mapping_contains=$(_has_line "$SECOND_FILE") local mapping_contains=$(_has_line "$SECOND_FILE")
[ "$mapping_contains" -eq 1 ] [ "$mapping_contains" -eq 1 ]
local first_encrypted_file=$(_get_encrypted_filename $FIRST_FILE) local first_encrypted_file=$(_get_encrypted_filename "$FIRST_FILE")
local second_encrypted_file=$(_get_encrypted_filename $SECOND_FILE) local second_encrypted_file=$(_get_encrypted_filename "$SECOND_FILE")
echo "$output" echo "$output"
echo "$first_encrypted_file and $second_encrypted_file" echo "$first_encrypted_file and $second_encrypted_file"

@ -2,7 +2,7 @@
load _test_base load _test_base
FILE_TO_HIDE="file_to_hide" FILE_TO_HIDE="$TEST_DEFAULT_FILENAME"
FILE_CONTENTS="hidden content юникод" FILE_CONTENTS="hidden content юникод"
FINGERPRINT="" FINGERPRINT=""

@ -2,7 +2,7 @@
load _test_base load _test_base
FILE_TO_HIDE="file_to_hide" FILE_TO_HIDE="$TEST_DEFAULT_FILENAME"
FILE_CONTENTS="hidden content юникод" FILE_CONTENTS="hidden content юникод"
FINGERPRINT="" FINGERPRINT=""

@ -6,4 +6,7 @@ set -e
# Running all the bats-tests in a dir with spaces: # Running all the bats-tests in a dir with spaces:
cd "${SECRET_PROJECT_ROOT}"; rm -rf 'tempdir with spaces'; mkdir 'tempdir with spaces'; cd 'tempdir with spaces'; cd "${SECRET_PROJECT_ROOT}"; rm -rf 'tempdir with spaces'; mkdir 'tempdir with spaces'; cd 'tempdir with spaces';
bats "${SECRET_PROJECT_ROOT}/tests"
# bats expects diagnostic lines to be sent to fd 3, matching reges '^ #' (IE, like: `echo '# message here' >&3`)
# bats ... 3>&1 shows diagnostic output when errors occur.
bats "${SECRET_PROJECT_ROOT}/tests/" 3>&1

Loading…
Cancel
Save