diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 9caffa97ec8c..62588d1f738b 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -768,7 +768,7 @@ in { solanum = handleTest ./solanum.nix {}; sonarr = handleTest ./sonarr.nix {}; sonic-server = handleTest ./sonic-server.nix {}; - sourcehut = handleTest ./sourcehut.nix {}; + sourcehut = handleTest ./sourcehut/sourcehut.nix {}; spacecookie = handleTest ./spacecookie.nix {}; spark = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./spark {}; sqlite3-to-mysql = handleTest ./sqlite3-to-mysql.nix {}; diff --git a/nixos/tests/sourcehut.nix b/nixos/tests/sourcehut/sourcehut.nix similarity index 75% rename from nixos/tests/sourcehut.nix rename to nixos/tests/sourcehut/sourcehut.nix index 2717d5b27b8c..b81767470e41 100644 --- a/nixos/tests/sourcehut.nix +++ b/nixos/tests/sourcehut/sourcehut.nix @@ -1,4 +1,4 @@ -import ./make-test-python.nix ({ pkgs, lib, ... }: +import ../make-test-python.nix ({ pkgs, lib, ... }: let domain = "sourcehut.localdomain"; @@ -118,30 +118,47 @@ in enableTCPIP = false; settings.unix_socket_permissions = "0770"; }; + + environment.systemPackages = with pkgs; [ + (callPackage ./srht-gen-oauth-tok.nix { }) # To automatically generate OAuth tokens + ]; }; - testScript = '' - start_all() - machine.wait_for_unit("multi-user.target") + testScript = + let + userName = "nixos-test"; + userPass = "AutoNixosTestPwd"; + in + '' + start_all() + machine.wait_for_unit("multi-user.target") - # Testing metasrht - machine.wait_for_unit("metasrht-api.service") - machine.wait_for_unit("metasrht.service") - machine.wait_for_unit("metasrht-webhooks.service") - machine.wait_for_open_port(5000) - machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}") - machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}") + # Testing metasrht + machine.wait_for_unit("metasrht-api.service") + machine.wait_for_unit("metasrht.service") + machine.wait_for_unit("metasrht-webhooks.service") + machine.wait_for_open_port(5000) + machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}") + machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}") - # Testing buildsrht - machine.wait_for_unit("buildsrht.service") - machine.wait_for_open_port(5002) - machine.succeed("curl -sL http://localhost:5002 | grep builds.${domain}") - #machine.wait_for_unit("buildsrht-worker.service") + ## Create a test user for subsequent tests + machine.succeed("echo ${userPass} | metasrht-manageuser -ps -e ${userName}@${domain}\ + -t active_free ${userName}"); - # Testing gitsrht - machine.wait_for_unit("gitsrht-api.service") - machine.wait_for_unit("gitsrht.service") - machine.wait_for_unit("gitsrht-webhooks.service") - machine.succeed("curl -sL http://git.${domain} | grep git.${domain}") - ''; + ## Obtain a OAuth token to be used for querying APIs directly + (_, token) = machine.execute("srht-gen-oauth-tok -i ${domain} -q ${userName} ${userPass}") + print(token) + + # Testing buildsrht + machine.wait_for_unit("buildsrht.service") + machine.wait_for_open_port(5002) + machine.succeed("curl -sL http://localhost:5002 | grep builds.${domain}") + #machine.wait_for_unit("buildsrht-worker.service") + + # Testing gitsrht + machine.wait_for_unit("gitsrht-api.service") + machine.wait_for_unit("gitsrht.service") + machine.wait_for_unit("gitsrht-webhooks.service") + machine.succeed("curl -sL http://git.${domain} | grep git.${domain}") + ''; }) diff --git a/nixos/tests/sourcehut/srht-gen-oauth-tok.nix b/nixos/tests/sourcehut/srht-gen-oauth-tok.nix new file mode 100644 index 000000000000..0a6527c9ecbb --- /dev/null +++ b/nixos/tests/sourcehut/srht-gen-oauth-tok.nix @@ -0,0 +1,31 @@ +{ stdenv, pkgs, lib, fetchFromSourcehut }: + +let + perl = pkgs.perl.withPackages (pps: [ + pps.CryptSSLeay + pps.WWWMechanize + pps.XMLLibXML + ]); +in +stdenv.mkDerivation rec { + pname = "srht-gen-oauth-tok"; + version = "0.1"; + + src = fetchFromSourcehut { + domain = "entropic.network"; + owner = "~nessdoor"; + repo = pname; + rev = version; + hash = "sha256-GcqP3XbVw2sR5n4+aLUmA4fthNkuVAGnhV1h7suJYdI="; + }; + + buildInputs = [ perl ]; + nativeBuildInputs = [ perl ]; + + installPhase = "install -Dm755 srht-gen-oauth-tok $out/bin/srht-gen-oauth-tok"; + + meta = { + description = "A script to register a new Sourcehut OAuth token for the given user"; + license = lib.licenses.gpl3; + }; +}