nixos/tests/forgejo: test cfg.secrets using /metrics endpoint

Heavily inspired by b59e5a34e7 (gitea).
This commit is contained in:
emilylange 2024-05-17 23:24:26 +02:00
parent 694db856ed
commit fd58d2299b
No known key found for this signature in database
GPG Key ID: 0AD773CE46FD0F87

View File

@ -41,6 +41,8 @@ let
hash = "sha256-h2/UIp8IjPo3eE4Gzx52Fb7pcgG/Ww7u31w5fdKVMos=";
};
metricSecret = "fakesecret";
supportedDbTypes = [ "mysql" "postgres" "sqlite3" ];
makeForgejoTest = type: nameValuePair type (makeTest {
name = "forgejo-${type}";
@ -59,6 +61,8 @@ let
ENABLE_PUSH_CREATE_USER = true;
DEFAULT_PUSH_CREATE_PRIVATE = false;
};
settings.metrics.ENABLED = true;
secrets.metrics.TOKEN = pkgs.writeText "metrics_secret" metricSecret;
};
environment.systemPackages = [ config.services.forgejo.package pkgs.gnupg pkgs.jq pkgs.file pkgs.htmlq ];
services.openssh.enable = true;
@ -192,6 +196,10 @@ let
timeout=10
)
with subtest("Testing /metrics endpoint with token from cfg.secrets"):
server.fail("curl --fail http://localhost:3000/metrics")
server.succeed('curl --fail http://localhost:3000/metrics -H "Authorization: Bearer ${metricSecret}"')
with subtest("Testing runner registration and action workflow"):
server.succeed(
"su -l forgejo -c 'GITEA_WORK_DIR=/var/lib/forgejo gitea actions generate-runner-token' | sed 's/^/TOKEN=/' | tee /var/lib/forgejo/runner_token"