diff --git a/test/common.nix b/test/common.nix index 96d9a1d..abeef15 100644 --- a/test/common.nix +++ b/test/common.nix @@ -45,8 +45,6 @@ client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt") def curl(target, format, endpoint, data="", extra=""): - data = ' '.join(data.replace("\n", "").split()) - extra = ' '.join(extra.replace("\n", "").split()) cmd = ("curl --show-error --location" + " --cookie-jar cookie.txt" + " --cookie cookie.txt" @@ -63,6 +61,9 @@ # print(r) return json.loads(r) + def unline_with(j, s): + return j.join((x.strip() for x in s.split("\n"))) + '' + (if (! redirectSSO) then '' with subtest("access"): @@ -84,7 +85,7 @@ ) + (let script = extraScript args; - indent = indent: str: lib.concatMapStringsSep "\n" (x: (lib. replicate indent " ") + x) (lib.splitString "\n" script); + indent = i: str: lib.concatMapStringsSep "\n" (x: (lib.strings.replicate i " ") + x) (lib.splitString "\n" script); in lib.optionalString (script != "") '' with subtest("extraScript"): diff --git a/test/services/deluge.nix b/test/services/deluge.nix index 7bcffa6..2496e7b 100644 --- a/test/services/deluge.nix +++ b/test/services/deluge.nix @@ -27,35 +27,35 @@ let with subtest("web connect"): print(server.succeed("cat ${node.config.services.deluge.dataDir}/.config/deluge/auth")) - response = curl(client, "", "${proto_fqdn}/json", extra = """ + response = curl(client, "", "${proto_fqdn}/json", extra = unline_with(" ", """ -H "Content-Type: application/json" -H "Accept: application/json" - """, data = """ + """), data = unline_with(" ", """ {"method": "auth.login", "params": ["deluge"], "id": 1} - """) + """)) print(response) if response['error']: raise Exception(f"error is {response['error']}") if not response['result']: raise Exception(f"response is {response}") - response = curl(client, "", "${proto_fqdn}/json", extra = """ + response = curl(client, "", "${proto_fqdn}/json", extra = unline_with(" ", """ -H "Content-Type: application/json" -H "Accept: application/json" - """, data = """ + """), data = unline_with(" ", """ {"method": "web.get_hosts", "params": [], "id": 1} - """) + """)) print(response) if response['error']: raise Exception(f"error is {response['error']}") hostID = response['result'][0][0] - response = curl(client, "", "${proto_fqdn}/json", extra = """ + response = curl(client, "", "${proto_fqdn}/json", extra = unline_with(" ", """ -H "Content-Type: application/json" -H "Accept: application/json" - """, data = f""" + """), data = unline_with(" ", f""" {{"method": "web.connect", "params": ["{hostID}"], "id": 1}} - """) + """)) print(response) if response['error']: raise Exception(f"result had an error {response['error']}")