summary refs log tree commit diff
diff options
context:
space:
mode:
authorElis Hirwing <elis@hirwing.se>2021-07-18 09:51:49 +0200
committerElis Hirwing <elis@hirwing.se>2021-07-19 07:33:03 +0200
commitf8b6ba005e8dc259a6ae065b1322bb879380aa57 (patch)
tree7582b238f4e5663b5210ed084ad9e2e51a05f2b0
parent09a49354b6dab9ea9807359ec3f7434b54730eab (diff)
downloadnixpkgs-f8b6ba005e8dc259a6ae065b1322bb879380aa57.tar
nixpkgs-f8b6ba005e8dc259a6ae065b1322bb879380aa57.tar.gz
nixpkgs-f8b6ba005e8dc259a6ae065b1322bb879380aa57.tar.bz2
nixpkgs-f8b6ba005e8dc259a6ae065b1322bb879380aa57.tar.lz
nixpkgs-f8b6ba005e8dc259a6ae065b1322bb879380aa57.tar.xz
nixpkgs-f8b6ba005e8dc259a6ae065b1322bb879380aa57.tar.zst
nixpkgs-f8b6ba005e8dc259a6ae065b1322bb879380aa57.zip
nixos/tests: Init hockeypuck tests
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/hockeypuck.nix63
-rw-r--r--pkgs/servers/hockeypuck/server.nix4
-rw-r--r--pkgs/servers/hockeypuck/web.nix4
4 files changed, 70 insertions, 2 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index fd502a473b1..746139c4816 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -174,6 +174,7 @@ in
   hitch = handleTest ./hitch {};
   hledger-web = handleTest ./hledger-web.nix {};
   hocker-fetchdocker = handleTest ./hocker-fetchdocker {};
+  hockeypuck = handleTest ./hockeypuck.nix { };
   home-assistant = handleTest ./home-assistant.nix {};
   hostname = handleTest ./hostname.nix {};
   hound = handleTest ./hound.nix {};
diff --git a/nixos/tests/hockeypuck.nix b/nixos/tests/hockeypuck.nix
new file mode 100644
index 00000000000..79313f314fd
--- /dev/null
+++ b/nixos/tests/hockeypuck.nix
@@ -0,0 +1,63 @@
+import ./make-test-python.nix ({ lib, pkgs, ... }:
+let
+  gpgKeyring = (pkgs.runCommandNoCC "gpg-keyring" { buildInputs = [ pkgs.gnupg ]; } ''
+    mkdir -p $out
+    export GNUPGHOME=$out
+    cat > foo <<EOF
+      %echo Generating a basic OpenPGP key
+      %no-protection
+      Key-Type: DSA
+      Key-Length: 1024
+      Subkey-Type: ELG-E
+      Subkey-Length: 1024
+      Name-Real: Foo Example
+      Name-Email: foo@example.org
+      Expire-Date: 0
+      # Do a commit here, so that we can later print "done"
+      %commit
+      %echo done
+    EOF
+    gpg --batch --generate-key foo
+    rm $out/S.gpg-agent $out/S.gpg-agent.*
+  '');
+in {
+  name = "hockeypuck";
+  meta.maintainers = with lib.maintainers; [ etu ];
+
+  machine = { ... }: {
+    # Used for test
+    environment.systemPackages = [ pkgs.gnupg ];
+
+    services.hockeypuck.enable = true;
+
+    services.postgresql = {
+      enable = true;
+      ensureDatabases = [ "hockeypuck" ];
+      ensureUsers = [{
+        name = "hockeypuck";
+        ensurePermissions."DATABASE hockeypuck" = "ALL PRIVILEGES";
+      }];
+    };
+  };
+
+  testScript = ''
+    machine.wait_for_unit("hockeypuck.service")
+    machine.wait_for_open_port(11371)
+
+    response = machine.succeed("curl -vvv -s http://127.0.0.1:11371/")
+
+    assert "<title>OpenPGP Keyserver</title>" in response, "HTML title not found"
+
+    # Copy the keyring
+    machine.succeed("cp -R ${gpgKeyring} /tmp/GNUPGHOME")
+
+    # Extract our GPG key id
+    keyId = machine.succeed("GNUPGHOME=/tmp/GNUPGHOME gpg --list-keys | grep dsa1024 --after-context=1 | grep -v dsa1024").strip()
+
+    # Send the key to our local keyserver
+    machine.succeed("GNUPGHOME=/tmp/GNUPGHOME gpg --keyserver hkp://127.0.0.1:11371 --send-keys " + keyId)
+
+    # Recieve the key from our local keyserver to a separate directory
+    machine.succeed("GNUPGHOME=$(mktemp -d) gpg --keyserver hkp://127.0.0.1:11371 --recv-keys " + keyId)
+  '';
+})
diff --git a/pkgs/servers/hockeypuck/server.nix b/pkgs/servers/hockeypuck/server.nix
index 5a95f227832..cf48fd5716c 100644
--- a/pkgs/servers/hockeypuck/server.nix
+++ b/pkgs/servers/hockeypuck/server.nix
@@ -1,4 +1,4 @@
-{ lib, buildGoModule, fetchFromGitHub }:
+{ lib, buildGoModule, fetchFromGitHub, nixosTests }:
 
 let
   sources = (import ./sources.nix) { inherit fetchFromGitHub; };
@@ -10,6 +10,8 @@ buildGoModule {
   vendorSha256 = null;
   doCheck = false; # Uses networking for tests
 
+  passthru.tests = nixosTests.hockeypuck;
+
   meta = with lib; {
     description = "OpenPGP Key Server";
     homepage = "https://github.com/hockeypuck/hockeypuck";
diff --git a/pkgs/servers/hockeypuck/web.nix b/pkgs/servers/hockeypuck/web.nix
index eda5317e8c4..32f2b1acd22 100644
--- a/pkgs/servers/hockeypuck/web.nix
+++ b/pkgs/servers/hockeypuck/web.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, fetchFromGitHub }:
+{ stdenv, lib, fetchFromGitHub, nixosTests }:
 
 let
   sources = (import ./sources.nix) { inherit fetchFromGitHub; };
@@ -17,6 +17,8 @@ stdenv.mkDerivation {
     cp -vr contrib/templates $out/share/
   '';
 
+  passthru.tests = nixosTests.hockeypuck;
+
   meta = with lib; {
     description = "OpenPGP Key Server web resources";
     homepage = "https://github.com/hockeypuck/hockeypuck";