2018-11-11 08:41:11 +00:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
2023-03-02 16:51:50 +00:00
|
|
|
giteaPackage ? pkgs.gitea,
|
2018-11-11 08:41:11 +00:00
|
|
|
pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
2018-11-06 02:06:30 +00:00
|
|
|
|
2019-10-27 10:24:26 +00:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
2018-11-06 02:06:30 +00:00
|
|
|
with pkgs.lib;
|
|
|
|
|
2019-12-06 17:59:37 +00:00
|
|
|
let
|
2023-03-01 22:44:21 +00:00
|
|
|
## gpg --faked-system-time='20230301T010000!' --quick-generate-key snakeoil ed25519 sign
|
|
|
|
signingPrivateKey = ''
|
|
|
|
-----BEGIN PGP PRIVATE KEY BLOCK-----
|
|
|
|
|
|
|
|
lFgEY/6jkBYJKwYBBAHaRw8BAQdADXiZRV8RJUyC9g0LH04wLMaJL9WTc+szbMi7
|
|
|
|
5fw4yP8AAQCl8EwGfzSLm/P6fCBfA3I9znFb3MEHGCCJhJ6VtKYyRw7ktAhzbmFr
|
|
|
|
ZW9pbIiUBBMWCgA8FiEE+wUM6VW/NLtAdSixTWQt6LZ4x50FAmP+o5ACGwMFCQPC
|
|
|
|
ZwAECwkIBwQVCgkIBRYCAwEAAh4FAheAAAoJEE1kLei2eMedFTgBAKQs1oGFZrCI
|
|
|
|
TZP42hmBTKxGAI1wg7VSdDEWTZxut/2JAQDGgo2sa4VHMfj0aqYGxrIwfP2B7JHO
|
|
|
|
GCqGCRf9O/hzBA==
|
|
|
|
=9Uy3
|
|
|
|
-----END PGP PRIVATE KEY BLOCK-----
|
|
|
|
'';
|
|
|
|
signingPrivateKeyId = "4D642DE8B678C79D";
|
|
|
|
|
2019-12-06 17:59:37 +00:00
|
|
|
supportedDbTypes = [ "mysql" "postgres" "sqlite3" ];
|
|
|
|
makeGiteaTest = type: nameValuePair type (makeTest {
|
2023-02-24 01:59:30 +00:00
|
|
|
name = "${giteaPackage.pname}-${type}";
|
2023-05-21 14:00:44 +00:00
|
|
|
meta.maintainers = with maintainers; [ aanderse emilylange kolaente ma27 ];
|
2019-12-11 01:43:17 +00:00
|
|
|
|
|
|
|
nodes = {
|
|
|
|
server = { config, pkgs, ... }: {
|
2023-05-09 13:21:53 +00:00
|
|
|
virtualisation.memorySize = 2047;
|
2019-12-11 01:43:17 +00:00
|
|
|
services.gitea = {
|
|
|
|
enable = true;
|
|
|
|
database = { inherit type; };
|
2023-02-24 01:59:30 +00:00
|
|
|
package = giteaPackage;
|
2023-10-06 23:21:21 +00:00
|
|
|
metricsTokenFile = (pkgs.writeText "metrics_secret" "fakesecret").outPath;
|
2022-09-07 07:42:30 +00:00
|
|
|
settings.service.DISABLE_REGISTRATION = true;
|
2023-03-01 22:44:21 +00:00
|
|
|
settings."repository.signing".SIGNING_KEY = signingPrivateKeyId;
|
2023-04-28 22:53:46 +00:00
|
|
|
settings.actions.ENABLED = true;
|
2023-10-06 23:21:21 +00:00
|
|
|
settings.metrics.ENABLED = true;
|
2019-12-11 01:43:17 +00:00
|
|
|
};
|
2023-03-01 22:44:21 +00:00
|
|
|
environment.systemPackages = [ giteaPackage pkgs.gnupg pkgs.jq ];
|
2019-12-11 01:43:17 +00:00
|
|
|
services.openssh.enable = true;
|
2023-04-28 22:53:46 +00:00
|
|
|
|
|
|
|
specialisation.runner = {
|
|
|
|
inheritParentConfig = true;
|
|
|
|
|
|
|
|
configuration.services.gitea-actions-runner.instances."test" = {
|
|
|
|
enable = true;
|
|
|
|
name = "ci";
|
|
|
|
url = "http://localhost:3000";
|
|
|
|
labels = [
|
|
|
|
# don't require docker/podman
|
|
|
|
"native:host"
|
|
|
|
];
|
|
|
|
tokenFile = "/var/lib/gitea/runner_token";
|
|
|
|
};
|
|
|
|
};
|
2019-12-11 01:43:17 +00:00
|
|
|
};
|
|
|
|
client1 = { config, pkgs, ... }: {
|
|
|
|
environment.systemPackages = [ pkgs.git ];
|
|
|
|
};
|
|
|
|
client2 = { config, pkgs, ... }: {
|
|
|
|
environment.systemPackages = [ pkgs.git ];
|
2018-11-06 02:06:30 +00:00
|
|
|
};
|
2019-12-06 17:59:37 +00:00
|
|
|
};
|
2018-11-06 02:06:30 +00:00
|
|
|
|
2023-04-28 22:53:46 +00:00
|
|
|
testScript = { nodes, ... }: let
|
2019-12-11 01:43:17 +00:00
|
|
|
inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
|
2023-04-28 22:53:46 +00:00
|
|
|
serverSystem = nodes.server.system.build.toplevel;
|
2019-12-11 01:43:17 +00:00
|
|
|
in ''
|
|
|
|
GIT_SSH_COMMAND = "ssh -i $HOME/.ssh/privk -o StrictHostKeyChecking=no"
|
|
|
|
REPO = "gitea@server:test/repo"
|
|
|
|
PRIVK = "${snakeOilPrivateKey}"
|
|
|
|
|
2019-10-27 10:24:26 +00:00
|
|
|
start_all()
|
2018-11-06 02:06:30 +00:00
|
|
|
|
2019-12-11 01:43:17 +00:00
|
|
|
client1.succeed("mkdir /tmp/repo")
|
|
|
|
client1.succeed("mkdir -p $HOME/.ssh")
|
|
|
|
client1.succeed(f"cat {PRIVK} > $HOME/.ssh/privk")
|
|
|
|
client1.succeed("chmod 0400 $HOME/.ssh/privk")
|
|
|
|
client1.succeed("git -C /tmp/repo init")
|
|
|
|
client1.succeed("echo hello world > /tmp/repo/testfile")
|
|
|
|
client1.succeed("git -C /tmp/repo add .")
|
|
|
|
client1.succeed("git config --global user.email test@localhost")
|
|
|
|
client1.succeed("git config --global user.name test")
|
|
|
|
client1.succeed("git -C /tmp/repo commit -m 'Initial import'")
|
|
|
|
client1.succeed(f"git -C /tmp/repo remote add origin {REPO}")
|
|
|
|
|
|
|
|
server.wait_for_unit("gitea.service")
|
|
|
|
server.wait_for_open_port(3000)
|
2023-04-19 07:11:00 +00:00
|
|
|
server.wait_for_open_port(22)
|
2019-12-11 01:43:17 +00:00
|
|
|
server.succeed("curl --fail http://localhost:3000/")
|
|
|
|
|
2023-03-01 22:44:21 +00:00
|
|
|
server.succeed(
|
|
|
|
"su -l gitea -c 'gpg --homedir /var/lib/gitea/data/home/.gnupg "
|
|
|
|
+ "--import ${toString (pkgs.writeText "gitea.key" signingPrivateKey)}'"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert "BEGIN PGP PUBLIC KEY BLOCK" in server.succeed("curl http://localhost:3000/api/v1/signing-key.gpg")
|
|
|
|
|
2019-12-11 01:43:17 +00:00
|
|
|
server.succeed(
|
|
|
|
"curl --fail http://localhost:3000/user/sign_up | grep 'Registration is disabled. "
|
|
|
|
+ "Please contact your site administrator.'"
|
|
|
|
)
|
|
|
|
server.succeed(
|
2021-04-11 11:39:39 +00:00
|
|
|
"su -l gitea -c 'GITEA_WORK_DIR=/var/lib/gitea gitea admin user create "
|
2019-12-11 01:43:17 +00:00
|
|
|
+ "--username test --password totallysafe --email test@localhost'"
|
2019-10-27 10:24:26 +00:00
|
|
|
)
|
2019-12-11 01:43:17 +00:00
|
|
|
|
|
|
|
api_token = server.succeed(
|
|
|
|
"curl --fail -X POST http://test:totallysafe@localhost:3000/api/v1/users/test/tokens "
|
|
|
|
+ "-H 'Accept: application/json' -H 'Content-Type: application/json' -d "
|
2023-03-20 13:32:10 +00:00
|
|
|
+ "'{\"name\":\"token\",\"scopes\":[\"all\"]}' | jq '.sha1' | xargs echo -n"
|
2019-12-11 01:43:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
server.succeed(
|
|
|
|
"curl --fail -X POST http://localhost:3000/api/v1/user/repos "
|
|
|
|
+ "-H 'Accept: application/json' -H 'Content-Type: application/json' "
|
|
|
|
+ f"-H 'Authorization: token {api_token}'"
|
|
|
|
+ ' -d \'{"auto_init":false, "description":"string", "license":"mit", "name":"repo", "private":false}\'''
|
|
|
|
)
|
|
|
|
|
|
|
|
server.succeed(
|
|
|
|
"curl --fail -X POST http://localhost:3000/api/v1/user/keys "
|
|
|
|
+ "-H 'Accept: application/json' -H 'Content-Type: application/json' "
|
|
|
|
+ f"-H 'Authorization: token {api_token}'"
|
|
|
|
+ ' -d \'{"key":"${snakeOilPublicKey}","read_only":true,"title":"SSH"}\'''
|
|
|
|
)
|
|
|
|
|
|
|
|
client1.succeed(
|
|
|
|
f"GIT_SSH_COMMAND='{GIT_SSH_COMMAND}' git -C /tmp/repo push origin master"
|
|
|
|
)
|
|
|
|
|
|
|
|
client2.succeed("mkdir -p $HOME/.ssh")
|
|
|
|
client2.succeed(f"cat {PRIVK} > $HOME/.ssh/privk")
|
|
|
|
client2.succeed("chmod 0400 $HOME/.ssh/privk")
|
|
|
|
client2.succeed(f"GIT_SSH_COMMAND='{GIT_SSH_COMMAND}' git clone {REPO}")
|
|
|
|
client2.succeed('test "$(cat repo/testfile | xargs echo -n)" = "hello world"')
|
|
|
|
|
2023-07-17 09:59:35 +00:00
|
|
|
server.wait_until_succeeds(
|
2019-12-11 01:43:17 +00:00
|
|
|
'test "$(curl http://localhost:3000/api/v1/repos/test/repo/commits '
|
|
|
|
+ '-H "Accept: application/json" | jq length)" = "1"'
|
|
|
|
)
|
2023-04-28 22:53:46 +00:00
|
|
|
|
2023-10-06 23:21:21 +00:00
|
|
|
with subtest("Testing metrics endpoint"):
|
|
|
|
server.succeed('curl '
|
|
|
|
+ '-H "Authorization: Bearer fakesecret" '
|
|
|
|
+ 'http://localhost:3000/metrics '
|
|
|
|
+ '| grep gitea_accesses')
|
|
|
|
|
2023-04-28 22:53:46 +00:00
|
|
|
with subtest("Testing runner registration"):
|
|
|
|
server.succeed(
|
|
|
|
"su -l gitea -c 'GITEA_WORK_DIR=/var/lib/gitea gitea actions generate-runner-token' | sed 's/^/TOKEN=/' | tee /var/lib/gitea/runner_token"
|
|
|
|
)
|
|
|
|
server.succeed("${serverSystem}/specialisation/runner/bin/switch-to-configuration test")
|
|
|
|
server.wait_for_unit("gitea-runner-test.service")
|
|
|
|
server.succeed("journalctl -o cat -u gitea-runner-test.service | grep -q 'Runner registered successfully'")
|
2018-11-06 02:06:30 +00:00
|
|
|
'';
|
2019-12-06 17:59:37 +00:00
|
|
|
});
|
|
|
|
in
|
|
|
|
|
|
|
|
listToAttrs (map makeGiteaTest supportedDbTypes)
|