syncthing: fix badly escaped ignore patterns test
The previous test would pass no matter what the `ignoreString` was. I don't know enough Bash/Grep to explain it, but it was easy to test by just changing the pattern to have `WRONG` instead of `val1`, and that would still pass the `assertFileContains` test. I've hopefully fixed it now, by using `lib.escapeShellArg` before passing it to `assertFileContains`, and I've also added a negative test case, to ensure that a bad ignore string is _not_ found in the merge script.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
{ lib, ... }:
|
||||
|
||||
{
|
||||
services.syncthing = {
|
||||
enable = true;
|
||||
@@ -19,9 +21,8 @@
|
||||
|
||||
nmt.script =
|
||||
let
|
||||
ignoreString = ''
|
||||
{"ignore":["val1","!val2","*al3","val'\'''4","val\"5"]}
|
||||
'';
|
||||
ignoreString = ''{"ignore":["val1","!val2","*al3","val'\'''4","val\"5"]}'';
|
||||
ignoreStringBad = ''{"ignore":["WRONG","!val2","*al3","val'\'''4","val\"5"]}'';
|
||||
in
|
||||
''
|
||||
serviceFile=home-files/.config/systemd/user/syncthing-init.service
|
||||
@@ -30,7 +31,10 @@
|
||||
assertFileContains "$serviceFile" "ExecStart="
|
||||
|
||||
updateScript=$(grep -o '/nix/store/[^ ]*-merge-syncthing-config' "$TESTED/$serviceFile")
|
||||
assertFileContains "$updateScript" '${ignoreString}'
|
||||
assertFileContains "$updateScript" "/rest/db/ignores?folder=ew8bc-4uanl"
|
||||
assertFileContains "$updateScript" ${lib.escapeShellArg ignoreString}
|
||||
if grep -qF ${lib.escapeShellArg ignoreStringBad} "$(_abs "$updateScript")"; then
|
||||
fail "syncthing bad ignore string shouldn't be found in updateScript"
|
||||
fi
|
||||
'';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user