infra/tests/keycloak.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
3.1 KiB
Nix
Raw Normal View History

{
self,
2024-08-28 21:54:59 +00:00
system,
pkgs,
lib,
config,
...
2024-08-25 00:41:29 +00:00
}:
let
realm-export = pkgs.writeTextFile {
name = "realm-export.json";
text = builtins.readFile ./support/keycloak-realm-export/realm-export.json;
};
2024-08-25 00:41:29 +00:00
in
{
name = "keycloak";
hostPkgs = pkgs;
node.pkgs = pkgs;
node.specialArgs = self.outputs.nixosConfigurations.nachtigall._module.specialArgs;
nodes = {
2024-08-28 21:54:59 +00:00
dns-server.imports = [ ./support/dns-server.nix ];
acme-server.imports = [ ./support/acme-server.nix ];
mail-server.imports = [ ./support/mail-server.nix ];
client.imports = [ ./support/client.nix ];
nachtigall = {
imports = [
self.inputs.agenix.nixosModules.default
self.nixosModules.home-manager
self.nixosModules.core
self.nixosModules.backups
self.nixosModules.nginx
self.nixosModules.keycloak
self.nixosModules.postgresql
./support/global.nix
];
2024-08-25 00:41:29 +00:00
systemd.tmpfiles.rules = [ "f /tmp/dbf 1777 root root 10d password" ];
virtualisation.memorySize = 4096;
pub-solar-os.auth = {
enable = true;
database-password-file = "/tmp/dbf";
};
services.keycloak.database.createLocally = true;
2024-08-28 21:54:59 +00:00
services.keycloak.initialAdminPassword = "password";
};
};
2024-08-28 21:54:59 +00:00
testScript = { ... }: ''
def puppeteer_run(cmd):
client.succeed(f'puppeteer-run \'{cmd}\' ')
2024-08-25 00:41:29 +00:00
start_all()
2024-08-28 21:54:59 +00:00
acme_server.wait_for_unit("system.slice")
mail_server.wait_for_unit("dovecot2.service")
mail_server.wait_for_unit("postfix.service")
2024-08-25 00:41:29 +00:00
nachtigall.wait_for_unit("system.slice")
nachtigall.succeed("ping 127.0.0.1 -c 2")
nachtigall.wait_for_unit("nginx.service")
2024-08-27 13:16:57 +00:00
2024-08-25 00:41:29 +00:00
nachtigall.wait_until_succeeds("curl http://127.0.0.1:8080/")
nachtigall.wait_until_succeeds("curl https://auth.test.pub.solar/")
2024-08-28 21:54:59 +00:00
nachtigall.succeed("${pkgs.keycloak}/bin/kcadm.sh create realms -f ${realm-export} --server http://localhost:8080 --realm master --user admin --password password --no-config")
2024-08-25 00:41:29 +00:00
client.wait_for_unit("system.slice")
client.wait_for_file("/tmp/puppeteer.sock")
2024-08-27 13:16:57 +00:00
puppeteer_run('page.goto("https://auth.test.pub.solar")')
puppeteer_run('page.waitForNetworkIdle()')
client.screenshot("initial")
puppeteer_run('page.locator("::-p-text(Sign in)").click()')
puppeteer_run('page.waitForNetworkIdle()')
client.screenshot("sign-in")
puppeteer_run('page.locator("::-p-text(Register)").click()')
puppeteer_run('page.waitForNetworkIdle()')
client.screenshot("register")
puppeteer_run('page.locator("[name=username]").fill("test-user")')
puppeteer_run('page.locator("[name=email]").fill("test-user@test.pub.solar")')
puppeteer_run('page.locator("[name=password]").fill("Password1234")')
puppeteer_run('page.locator("[name=password-confirm]").fill("Password1234")')
client.screenshot("register-filled-in")
puppeteer_run('page.locator("button::-p-text(Register)").click()')
puppeteer_run('page.waitForNetworkIdle()')
client.screenshot("after-register")
client.succeed("offlineimap")
2024-08-25 00:41:29 +00:00
'';
}