2021-02-18 12:56:58 +01:00
|
|
|
{ pkgs ? (import ../.. { inherit system; config = { }; })
|
|
|
|
, system ? builtins.currentSystem
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2020-08-24 01:07:24 +02:00
|
|
|
dbContents = ''
|
2020-08-03 00:52:37 +02:00
|
|
|
dn: dc=example
|
|
|
|
objectClass: domain
|
|
|
|
dc: example
|
2018-03-03 19:53:16 +01:00
|
|
|
|
2020-08-03 00:52:37 +02:00
|
|
|
dn: ou=users,dc=example
|
|
|
|
objectClass: organizationalUnit
|
|
|
|
ou: users
|
|
|
|
'';
|
2018-03-03 19:53:16 +01:00
|
|
|
testScript = ''
|
2019-12-02 21:41:58 +01:00
|
|
|
machine.wait_for_unit("openldap.service")
|
|
|
|
machine.succeed(
|
|
|
|
'ldapsearch -LLL -D "cn=root,dc=example" -w notapassword -b "dc=example"',
|
|
|
|
)
|
2018-03-03 19:53:16 +01:00
|
|
|
'';
|
2020-08-03 00:52:37 +02:00
|
|
|
in {
|
|
|
|
# New-style configuration
|
2021-02-18 12:56:58 +01:00
|
|
|
current = import ./make-test-python.nix ({ pkgs, ... }: {
|
2020-08-03 00:52:37 +02:00
|
|
|
inherit testScript;
|
|
|
|
name = "openldap";
|
|
|
|
|
2022-03-21 00:15:30 +01:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2020-09-27 19:03:40 +02:00
|
|
|
environment.etc."openldap/root_password".text = "notapassword";
|
2020-08-03 00:52:37 +02:00
|
|
|
services.openldap = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
children = {
|
2020-09-28 00:23:31 +02:00
|
|
|
"cn=schema".includes = [
|
|
|
|
"${pkgs.openldap}/etc/schema/core.ldif"
|
|
|
|
"${pkgs.openldap}/etc/schema/cosine.ldif"
|
|
|
|
"${pkgs.openldap}/etc/schema/inetorgperson.ldif"
|
|
|
|
"${pkgs.openldap}/etc/schema/nis.ldif"
|
|
|
|
];
|
2020-08-03 00:52:37 +02:00
|
|
|
"olcDatabase={1}mdb" = {
|
2020-09-27 19:03:40 +02:00
|
|
|
# This tests string, base64 and path values, as well as lists of string values
|
2020-08-03 00:52:37 +02:00
|
|
|
attrs = {
|
|
|
|
objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
|
|
|
|
olcDatabase = "{1}mdb";
|
|
|
|
olcDbDirectory = "/var/db/openldap";
|
|
|
|
olcSuffix = "dc=example";
|
2020-09-27 19:03:40 +02:00
|
|
|
olcRootDN = {
|
|
|
|
# cn=root,dc=example
|
|
|
|
base64 = "Y249cm9vdCxkYz1leGFtcGxl";
|
|
|
|
};
|
|
|
|
olcRootPW = {
|
|
|
|
path = "/etc/openldap/root_password";
|
|
|
|
};
|
2020-08-03 00:52:37 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-08-24 01:07:24 +02:00
|
|
|
declarativeContents."dc=example" = dbContents;
|
2020-08-03 00:52:37 +02:00
|
|
|
};
|
|
|
|
};
|
2021-02-18 12:56:58 +01:00
|
|
|
}) { inherit pkgs system; };
|
2020-08-03 00:52:37 +02:00
|
|
|
|
|
|
|
# Old-style configuration
|
2021-02-18 12:56:58 +01:00
|
|
|
oldOptions = import ./make-test-python.nix ({ pkgs, ... }: {
|
2020-08-03 00:52:37 +02:00
|
|
|
inherit testScript;
|
|
|
|
name = "openldap";
|
|
|
|
|
2022-03-21 00:15:30 +01:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2020-08-03 00:52:37 +02:00
|
|
|
services.openldap = {
|
|
|
|
enable = true;
|
2020-09-27 22:50:25 +02:00
|
|
|
logLevel = "stats acl";
|
|
|
|
defaultSchemas = true;
|
|
|
|
database = "mdb";
|
2020-08-03 00:52:37 +02:00
|
|
|
suffix = "dc=example";
|
|
|
|
rootdn = "cn=root,dc=example";
|
|
|
|
rootpw = "notapassword";
|
2020-09-27 22:50:25 +02:00
|
|
|
declarativeContents."dc=example" = dbContents;
|
2020-08-03 00:52:37 +02:00
|
|
|
};
|
|
|
|
};
|
2021-02-18 12:56:58 +01:00
|
|
|
}) { inherit system pkgs; };
|
2020-08-03 00:52:37 +02:00
|
|
|
|
|
|
|
# Manually managed configDir, for example if dynamic config is essential
|
2021-02-18 12:56:58 +01:00
|
|
|
manualConfigDir = import ./make-test-python.nix ({ pkgs, ... }: {
|
2020-08-03 00:52:37 +02:00
|
|
|
name = "openldap";
|
|
|
|
|
2022-03-21 00:15:30 +01:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2020-08-03 00:52:37 +02:00
|
|
|
services.openldap = {
|
|
|
|
enable = true;
|
|
|
|
configDir = "/var/db/slapd.d";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = let
|
2020-08-24 01:07:24 +02:00
|
|
|
contents = pkgs.writeText "data.ldif" dbContents;
|
2020-08-03 00:52:37 +02:00
|
|
|
config = pkgs.writeText "config.ldif" ''
|
|
|
|
dn: cn=config
|
|
|
|
cn: config
|
|
|
|
objectClass: olcGlobal
|
|
|
|
olcLogLevel: stats
|
|
|
|
olcPidFile: /run/slapd/slapd.pid
|
|
|
|
|
|
|
|
dn: cn=schema,cn=config
|
|
|
|
cn: schema
|
|
|
|
objectClass: olcSchemaConfig
|
|
|
|
|
|
|
|
include: file://${pkgs.openldap}/etc/schema/core.ldif
|
|
|
|
include: file://${pkgs.openldap}/etc/schema/cosine.ldif
|
|
|
|
include: file://${pkgs.openldap}/etc/schema/inetorgperson.ldif
|
|
|
|
|
|
|
|
dn: olcDatabase={1}mdb,cn=config
|
|
|
|
objectClass: olcDatabaseConfig
|
|
|
|
objectClass: olcMdbConfig
|
|
|
|
olcDatabase: {1}mdb
|
|
|
|
olcDbDirectory: /var/db/openldap
|
|
|
|
olcDbIndex: objectClass eq
|
|
|
|
olcSuffix: dc=example
|
|
|
|
olcRootDN: cn=root,dc=example
|
|
|
|
olcRootPW: notapassword
|
|
|
|
'';
|
|
|
|
in ''
|
|
|
|
machine.succeed(
|
|
|
|
"mkdir -p /var/db/slapd.d /var/db/openldap",
|
|
|
|
"slapadd -F /var/db/slapd.d -n0 -l ${config}",
|
|
|
|
"slapadd -F /var/db/slapd.d -n1 -l ${contents}",
|
|
|
|
"chown -R openldap:openldap /var/db/slapd.d /var/db/openldap",
|
|
|
|
"systemctl restart openldap",
|
|
|
|
)
|
|
|
|
'' + testScript;
|
2021-02-18 12:56:58 +01:00
|
|
|
}) { inherit system pkgs; };
|
2018-03-03 19:53:16 +01:00
|
|
|
}
|