Remove sudo prefix from command if detected

This commit is contained in:
Michael Aquilina 2019-08-26 12:25:43 +01:00
parent a77777987d
commit cbd4e2bcac
No known key found for this signature in database
GPG key ID: 636066730B056BD1
2 changed files with 14 additions and 0 deletions

View file

@ -61,6 +61,11 @@ function _is_auto_notify_ignored() {
# Remove leading whitespace
target_command="$(echo "$target_command" | sed -e 's/^ *//')"
# Remove sudo prefix from command if detected
if [[ "$target_command" == "sudo "* ]]; then
target_command="${target_command/sudo /}"
fi
# If AUTO_NOTIFY_WHITELIST is defined, then auto-notify will ignore
# any item not defined in the white list
# Otherwise - the alternative (default) approach is used where the

View file

@ -51,3 +51,12 @@
assert $state equals 0
assert "$output" same_as "no"
}
@test 'is_auto_notify_ignored - AUTO_NOTIFY_WHITELIST allowed with sudo' {
AUTO_NOTIFY_WHITELIST="foobar"
run _is_auto_notify_ignored "sudo foobar baz"
assert $state equals 0
assert "$output" same_as "no"
}