diff options
author | Emery Hemingway <ehmry@posteo.net> | 2020-07-21 23:20:27 +0200 |
---|---|---|
committer | ehmry <ehmry@posteo.net> | 2020-07-24 11:04:33 +0200 |
commit | 76d60b0fcd855431e840e9bae0fcb136f3c1afe4 (patch) | |
tree | 9ab7aecc99668e99ce2d9caade56532a64fc62a0 /nixos/tests | |
parent | f40699c907787d960e8e41ad399c12592ac9737d (diff) | |
download | nixpkgs-76d60b0fcd855431e840e9bae0fcb136f3c1afe4.tar nixpkgs-76d60b0fcd855431e840e9bae0fcb136f3c1afe4.tar.gz nixpkgs-76d60b0fcd855431e840e9bae0fcb136f3c1afe4.tar.bz2 nixpkgs-76d60b0fcd855431e840e9bae0fcb136f3c1afe4.tar.lz nixpkgs-76d60b0fcd855431e840e9bae0fcb136f3c1afe4.tar.xz nixpkgs-76d60b0fcd855431e840e9bae0fcb136f3c1afe4.tar.zst nixpkgs-76d60b0fcd855431e840e9bae0fcb136f3c1afe4.zip |
nixos/molly-brown: init
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/molly-brown.nix | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/nixos/tests/molly-brown.nix b/nixos/tests/molly-brown.nix new file mode 100644 index 00000000000..09ce42726ca --- /dev/null +++ b/nixos/tests/molly-brown.nix @@ -0,0 +1,71 @@ +import ./make-test-python.nix ({ pkgs, ... }: + + let testString = "NixOS Gemini test successful"; + in { + + name = "molly-brown"; + meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ ehmry ]; }; + + nodes = { + + geminiServer = { config, pkgs, ... }: + let + inherit (config.networking) hostName; + cfg = config.services.molly-brown; + in { + + environment.systemPackages = [ + (pkgs.writeScriptBin "test-gemini" '' + #!${pkgs.python3}/bin/python + + import socket + import ssl + import tempfile + import textwrap + import urllib.parse + + url = "gemini://geminiServer/init.gmi" + parsed_url = urllib.parse.urlparse(url) + + s = socket.create_connection((parsed_url.netloc, 1965)) + context = ssl.SSLContext() + context.check_hostname = False + context.verify_mode = ssl.CERT_NONE + s = context.wrap_socket(s, server_hostname=parsed_url.netloc) + s.sendall((url + "\r\n").encode("UTF-8")) + fp = s.makefile("rb") + print(fp.readline().strip()) + print(fp.readline().strip()) + print(fp.readline().strip()) + '') + ]; + + networking.firewall.allowedTCPPorts = [ cfg.settings.Port ]; + + services.molly-brown = { + enable = true; + docBase = "/tmp/docs"; + certPath = "/tmp/cert.pem"; + keyPath = "/tmp/key.pem"; + }; + + systemd.services.molly-brown.preStart = '' + ${pkgs.openssl}/bin/openssl genrsa -out "/tmp/key.pem" + ${pkgs.openssl}/bin/openssl req -new \ + -subj "/CN=${config.networking.hostName}" \ + -key "/tmp/key.pem" -out /tmp/request.pem + ${pkgs.openssl}/bin/openssl x509 -req -days 3650 \ + -in /tmp/request.pem -signkey "/tmp/key.pem" -out "/tmp/cert.pem" + + mkdir -p "${cfg.settings.DocBase}" + echo "${testString}" > "${cfg.settings.DocBase}/test.gmi" + ''; + }; + }; + testScript = '' + geminiServer.wait_for_unit("molly-brown") + geminiServer.wait_for_open_port(1965) + geminiServer.succeed("test-gemini") + ''; + + }) |