2016-03-23 20:18:33 -04:00
|
|
|
load common
|
|
|
|
load_fixtures
|
2016-04-06 13:33:42 -04:00
|
|
|
status=;output=; #; populated by bats run()
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
setup() {
|
|
|
|
destroy_tmp
|
|
|
|
build_repo
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_restricted() {
|
|
|
|
local p
|
|
|
|
for p in "${restricted[@]}"; do [ "$p" = "$1" ] && return 0; done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function validate_perms() {
|
2016-04-06 13:33:42 -04:00
|
|
|
local perms="$*"
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; determine which paths should have restricted permissions
|
|
|
|
restricted=()
|
|
|
|
local p
|
|
|
|
for p in $perms; do
|
|
|
|
case $p in
|
|
|
|
ssh)
|
|
|
|
restricted=("${restricted[@]}" $T_DIR_WORK/.ssh $T_DIR_WORK/.ssh/*)
|
|
|
|
;;
|
|
|
|
gpg)
|
|
|
|
restricted=("${restricted[@]}" $T_DIR_WORK/.gnupg $T_DIR_WORK/.gnupg/*)
|
|
|
|
;;
|
2017-09-17 20:06:02 -04:00
|
|
|
*)
|
|
|
|
restricted=("${restricted[@]}" $T_DIR_WORK/$p)
|
2016-03-23 20:18:33 -04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
#; validate permissions of each path in the worktere
|
|
|
|
local testpath
|
2016-04-06 13:33:42 -04:00
|
|
|
while IFS= read -r -d '' testpath; do
|
2016-03-23 20:18:33 -04:00
|
|
|
local perm_regex="....rwxrwx"
|
|
|
|
if is_restricted "$testpath"; then
|
|
|
|
perm_regex="....------"
|
|
|
|
fi
|
|
|
|
test_perms "$testpath" "$perm_regex" || return 1
|
2016-04-06 13:33:42 -04:00
|
|
|
done < <(find "$T_DIR_WORK" -print0)
|
|
|
|
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'perms'" {
|
|
|
|
echo "
|
|
|
|
When the command 'perms' is provided
|
|
|
|
Update permissions for ssh/gpg
|
|
|
|
Verify correct permissions
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
#; run perms
|
2016-04-06 13:33:42 -04:00
|
|
|
run "${T_YADM_Y[@]}" perms
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "" ]
|
|
|
|
|
|
|
|
#; validate permissions
|
|
|
|
validate_perms ssh gpg
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'perms' (with encrypt)" {
|
|
|
|
echo "
|
|
|
|
When the command 'perms' is provided
|
|
|
|
And YADM_ENCRYPT is present
|
|
|
|
Update permissions for ssh/gpg/encrypt
|
|
|
|
Support comments in YADM_ENCRYPT
|
|
|
|
Verify correct permissions
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
#; this version has a comment in it
|
2017-09-17 20:06:02 -04:00
|
|
|
echo -e "#.vimrc\n.tmux.conf\n.hammerspoon/*\n!.tmux.conf" > "$T_YADM_ENCRYPT"
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; run perms
|
2016-04-06 13:33:42 -04:00
|
|
|
run "${T_YADM_Y[@]}" perms
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "" ]
|
|
|
|
|
|
|
|
#; validate permissions
|
2017-09-17 20:06:02 -04:00
|
|
|
validate_perms ssh gpg ".hammerspoon/*"
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'perms' (ssh-perms=false)" {
|
|
|
|
echo "
|
|
|
|
When the command 'perms' is provided
|
|
|
|
And yadm.ssh-perms=false
|
|
|
|
Update permissions for gpg only
|
|
|
|
Verify correct permissions
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
#; configure yadm.ssh-perms
|
|
|
|
git config --file="$T_YADM_CONFIG" "yadm.ssh-perms" "false"
|
|
|
|
|
|
|
|
#; run perms
|
2016-04-06 13:33:42 -04:00
|
|
|
run "${T_YADM_Y[@]}" perms
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "" ]
|
|
|
|
|
|
|
|
#; validate permissions
|
|
|
|
validate_perms gpg
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'perms' (gpg-perms=false)" {
|
|
|
|
echo "
|
|
|
|
When the command 'perms' is provided
|
|
|
|
And yadm.gpg-perms=false
|
|
|
|
Update permissions for ssh only
|
|
|
|
Verify correct permissions
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
#; configure yadm.gpg-perms
|
|
|
|
git config --file="$T_YADM_CONFIG" "yadm.gpg-perms" "false"
|
|
|
|
|
|
|
|
#; run perms
|
2016-04-06 13:33:42 -04:00
|
|
|
run "${T_YADM_Y[@]}" perms
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "" ]
|
|
|
|
|
|
|
|
#; validate permissions
|
|
|
|
validate_perms ssh
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'auto-perms' (enabled)" {
|
|
|
|
echo "
|
|
|
|
When a command possibly changes the repo
|
|
|
|
Update permissions for ssh/gpg
|
|
|
|
Verify correct permissions
|
|
|
|
"
|
|
|
|
|
|
|
|
#; run status
|
2016-04-06 13:33:42 -04:00
|
|
|
run "${T_YADM_Y[@]}" status
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; validate status
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
#; validate permissions
|
|
|
|
validate_perms ssh gpg
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'auto-perms' (disabled)" {
|
|
|
|
echo "
|
|
|
|
When a command possibly changes the repo
|
|
|
|
And yadm.auto-perms=false
|
|
|
|
Take no action
|
|
|
|
Verify permissions are intact
|
|
|
|
"
|
|
|
|
|
|
|
|
#; configure yadm.auto-perms
|
|
|
|
git config --file="$T_YADM_CONFIG" "yadm.auto-perms" "false"
|
|
|
|
|
|
|
|
#; run status
|
2016-04-06 13:33:42 -04:00
|
|
|
run "${T_YADM_Y[@]}" status
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; validate status
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
#; validate permissions
|
|
|
|
validate_perms
|
|
|
|
}
|