nixosTests.sourcehut: test user creation and OAuth token generation

This commit is contained in:
Tomas Antonio Lopez 2023-11-30 16:03:01 +01:00
parent ab1ad2b066
commit 3943aa57c0
3 changed files with 71 additions and 23 deletions

View File

@ -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 {};

View File

@ -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}")
'';
})

View File

@ -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;
};
}