1
0
Fork 0
selfhostblocks/test/blocks/authelia.nix

115 lines
3.8 KiB
Nix
Raw Normal View History

2023-12-11 06:56:31 +01:00
{ pkgs, lib, ... }:
let
2024-03-20 06:50:41 +01:00
pkgs' = pkgs;
2023-12-11 06:56:31 +01:00
ldapAdminPassword = "ldapAdminPassword";
in
{
2024-03-20 06:50:41 +01:00
basic = pkgs.testers.runNixOSTest {
2023-12-11 06:56:31 +01:00
name = "authelia-basic";
nodes.machine = { config, pkgs, ... }: {
imports = [
2024-03-20 06:50:41 +01:00
(pkgs'.path + "/nixos/modules/profiles/headless.nix")
(pkgs'.path + "/nixos/modules/profiles/qemu-guest.nix")
2023-12-11 06:56:31 +01:00
{
options = {
shb.backup = lib.mkOption { type = lib.types.anything; };
};
}
../../modules/blocks/authelia.nix
../../modules/blocks/ldap.nix
../../modules/blocks/postgresql.nix
];
shb.ldap = {
enable = true;
dcdomain = "dc=example,dc=com";
subdomain = "ldap";
domain = "machine";
2023-12-11 06:56:31 +01:00
ldapUserPasswordFile = pkgs.writeText "user_password" ldapAdminPassword;
jwtSecretFile = pkgs.writeText "jwt_secret" "securejwtsecret";
};
shb.authelia = {
enable = true;
subdomain = "authelia";
domain = "machine";
2023-12-11 06:56:31 +01:00
ldapEndpoint = "ldap://127.0.0.1:${builtins.toString config.shb.ldap.ldapPort}";
dcdomain = config.shb.ldap.dcdomain;
secrets = {
jwtSecretFile = pkgs.writeText "jwtSecretFile" "jwtSecretFile";
ldapAdminPasswordFile = pkgs.writeText "ldapAdminPasswordFile" ldapAdminPassword;
sessionSecretFile = pkgs.writeText "sessionSecretFile" "sessionSecretFile";
storageEncryptionKeyFile = pkgs.writeText "storageEncryptionKeyFile" "storageEncryptionKeyFile";
identityProvidersOIDCHMACSecretFile = pkgs.writeText "identityProvidersOIDCHMACSecretFile" "identityProvidersOIDCHMACSecretFile";
# This needs to be of the correct shape and at least 2048 bits. Generated with:
# nix run nixpkgs#openssl -- genrsa -out keypair.pem 2048
identityProvidersOIDCIssuerPrivateKeyFile = pkgs.writeText "identityProvidersOIDCIssuerPrivateKeyFile" (builtins.readFile ./keypair.pem);
};
oidcClients = [
{
id = "client1";
description = "My Client 1";
2024-03-01 00:34:53 +01:00
secret.source = pkgs.writeText "secret" "mysecuresecret";
public = false;
2023-12-11 06:56:31 +01:00
authorization_policy = "one_factor";
redirect_uris = [ "http://client1.machine/redirect" ];
}
{
id = "client2";
description = "My Client 2";
2024-03-01 00:34:53 +01:00
secret.source = pkgs.writeText "secret" "myothersecret";
public = false;
authorization_policy = "one_factor";
redirect_uris = [ "http://client2.machine/redirect" ];
2023-12-11 06:56:31 +01:00
}
];
};
};
testScript = { nodes, ... }: ''
import json
2023-12-11 06:56:31 +01:00
start_all()
machine.wait_for_unit("lldap.service")
machine.wait_for_unit("authelia-authelia.machine.service")
machine.wait_for_open_port(${toString nodes.machine.services.authelia.instances."authelia.machine".settings.server.port})
endpoints = json.loads(machine.succeed("curl -s http://machine/.well-known/openid-configuration"))
auth_endpoint = endpoints['authorization_endpoint']
machine.succeed(
"curl -f -s '"
+ auth_endpoint
+ "?client_id=other"
+ "&redirect_uri=http://client1.machine/redirect"
+ "&scope=openid%20profile%20email"
+ "&response_type=code"
+ "&state=99999999'"
)
machine.succeed(
"curl -f -s '"
+ auth_endpoint
+ "?client_id=client1"
+ "&redirect_uri=http://client1.machine/redirect"
+ "&scope=openid%20profile%20email"
+ "&response_type=code"
+ "&state=11111111'"
)
2023-12-11 06:56:31 +01:00
machine.succeed(
"curl -f -s '"
+ auth_endpoint
+ "?client_id=client2"
+ "&redirect_uri=http://client2.machine/redirect"
+ "&scope=openid%20profile%20email"
+ "&response_type=code"
+ "&state=22222222'"
)
2023-12-11 06:56:31 +01:00
'';
};
}