From fa21828be54b29fcf1a0e93a3bdd1f7081c680b8 Mon Sep 17 00:00:00 2001 From: emilylange Date: Wed, 31 May 2023 15:08:39 +0200 Subject: [PATCH] nixosTests.acme-dns: init --- nixos/tests/acme-dns.nix | 50 +++++++++++++++++++++++++++ nixos/tests/all-tests.nix | 1 + pkgs/servers/dns/acme-dns/default.nix | 3 ++ 3 files changed, 54 insertions(+) create mode 100644 nixos/tests/acme-dns.nix diff --git a/nixos/tests/acme-dns.nix b/nixos/tests/acme-dns.nix new file mode 100644 index 000000000000..92d9498fe714 --- /dev/null +++ b/nixos/tests/acme-dns.nix @@ -0,0 +1,50 @@ +import ./make-test-python.nix ({ ... }: { + name = "acme-dns"; + + nodes.machine = { pkgs, ... }: { + services.acme-dns = { + enable = true; + settings = { + general = rec { + domain = "acme-dns.home.arpa"; + nsname = domain; + nsadmin = "admin.home.arpa"; + records = [ + "${domain}. A 127.0.0.1" + "${domain}. AAAA ::1" + "${domain}. NS ${domain}." + ]; + }; + logconfig.loglevel = "debug"; + }; + }; + environment.systemPackages = with pkgs; [ curl bind ]; + }; + + testScript = '' + import json + + machine.wait_for_unit("acme-dns.service") + machine.wait_for_open_port(53) # dns + machine.wait_for_open_port(8080) # http api + + result = machine.succeed("curl --fail -X POST http://localhost:8080/register") + print(result) + + registration = json.loads(result) + + machine.succeed(f'dig -t TXT @localhost {registration["fulldomain"]} | grep "SOA" | grep "admin.home.arpa"') + + # acme-dns exspects a TXT value string length of exactly 43 chars + txt = "___dummy_validation_token_for_txt_record___" + + machine.succeed( + "curl --fail -X POST http://localhost:8080/update " + + f' -H "X-Api-User: {registration["username"]}"' + + f' -H "X-Api-Key: {registration["password"]}"' + + f' -d \'{{"subdomain":"{registration["subdomain"]}", "txt":"{txt}"}}\''' + ) + + assert txt in machine.succeed(f'dig -t TXT +short @localhost {registration["fulldomain"]}') + ''; +}) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index abe281a204b4..04bbf3b876aa 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -95,6 +95,7 @@ in { _3proxy = runTest ./3proxy.nix; aaaaxy = runTest ./aaaaxy.nix; acme = runTest ./acme.nix; + acme-dns = handleTest ./acme-dns.nix {}; adguardhome = runTest ./adguardhome.nix; aesmd = runTestOn ["x86_64-linux"] ./aesmd.nix; agate = runTest ./web-servers/agate.nix; diff --git a/pkgs/servers/dns/acme-dns/default.nix b/pkgs/servers/dns/acme-dns/default.nix index d0e146e80fd2..08cd511f1827 100644 --- a/pkgs/servers/dns/acme-dns/default.nix +++ b/pkgs/servers/dns/acme-dns/default.nix @@ -1,6 +1,7 @@ { lib , buildGoModule , fetchFromGitHub +, nixosTests }: buildGoModule rec { @@ -21,6 +22,8 @@ buildGoModule rec { substituteInPlace $out/lib/systemd/system/acme-dns.service --replace "/usr/local/bin/acme-dns" "$out/bin/acme-dns" ''; + passthru.tests = { inherit (nixosTests) acme-dns; }; + meta = { description = "Limited DNS server to handle ACME DNS challenges easily and securely"; homepage = "https://github.com/joohoi/acme-dns";