2021-02-18 11:56:58 +00:00
|
|
|
{ pkgs ? (import ../.. { inherit system; config = { }; })
|
|
|
|
, system ? builtins.currentSystem
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2020-08-24 00:07:24 +01:00
|
|
|
dbContents = ''
|
2020-08-02 23:52:37 +01:00
|
|
|
dn: dc=example
|
|
|
|
objectClass: domain
|
|
|
|
dc: example
|
2018-03-03 18:53:16 +00:00
|
|
|
|
2020-08-02 23:52:37 +01:00
|
|
|
dn: ou=users,dc=example
|
|
|
|
objectClass: organizationalUnit
|
|
|
|
ou: users
|
|
|
|
'';
|
2018-03-03 18:53:16 +00:00
|
|
|
testScript = ''
|
2019-12-02 20:41:58 +00:00
|
|
|
machine.wait_for_unit("openldap.service")
|
|
|
|
machine.succeed(
|
|
|
|
'ldapsearch -LLL -D "cn=root,dc=example" -w notapassword -b "dc=example"',
|
|
|
|
)
|
2018-03-03 18:53:16 +00:00
|
|
|
'';
|
2020-08-02 23:52:37 +01:00
|
|
|
in {
|
|
|
|
# New-style configuration
|
2021-02-18 11:56:58 +00:00
|
|
|
current = import ./make-test-python.nix ({ pkgs, ... }: {
|
2020-08-02 23:52:37 +01:00
|
|
|
inherit testScript;
|
|
|
|
name = "openldap";
|
|
|
|
|
|
|
|
machine = { pkgs, ... }: {
|
2020-09-27 18:03:40 +01:00
|
|
|
environment.etc."openldap/root_password".text = "notapassword";
|
2020-08-02 23:52:37 +01:00
|
|
|
services.openldap = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
children = {
|
2020-09-27 23:23:31 +01: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-02 23:52:37 +01:00
|
|
|
"olcDatabase={1}mdb" = {
|
2020-09-27 18:03:40 +01:00
|
|
|
# This tests string, base64 and path values, as well as lists of string values
|
2020-08-02 23:52:37 +01:00
|
|
|
attrs = {
|
|
|
|
objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
|
|
|
|
olcDatabase = "{1}mdb";
|
|
|
|
olcDbDirectory = "/var/db/openldap";
|
|
|
|
olcSuffix = "dc=example";
|
2020-09-27 18:03:40 +01:00
|
|
|
olcRootDN = {
|
|
|
|
# cn=root,dc=example
|
|
|
|
base64 = "Y249cm9vdCxkYz1leGFtcGxl";
|
|
|
|
};
|
|
|
|
olcRootPW = {
|
|
|
|
path = "/etc/openldap/root_password";
|
|
|
|
};
|
2020-08-02 23:52:37 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-08-24 00:07:24 +01:00
|
|
|
declarativeContents."dc=example" = dbContents;
|
2020-08-02 23:52:37 +01:00
|
|
|
};
|
|
|
|
};
|
2021-02-18 11:56:58 +00:00
|
|
|
}) { inherit pkgs system; };
|
2020-08-02 23:52:37 +01:00
|
|
|
|
|
|
|
# Old-style configuration
|
2021-02-18 11:56:58 +00:00
|
|
|
oldOptions = import ./make-test-python.nix ({ pkgs, ... }: {
|
2020-08-02 23:52:37 +01:00
|
|
|
inherit testScript;
|
|
|
|
name = "openldap";
|
|
|
|
|
|
|
|
machine = { pkgs, ... }: {
|
|
|
|
services.openldap = {
|
|
|
|
enable = true;
|
2020-09-27 21:50:25 +01:00
|
|
|
logLevel = "stats acl";
|
|
|
|
defaultSchemas = true;
|
|
|
|
database = "mdb";
|
2020-08-02 23:52:37 +01:00
|
|
|
suffix = "dc=example";
|
|
|
|
rootdn = "cn=root,dc=example";
|
|
|
|
rootpw = "notapassword";
|
2020-09-27 21:50:25 +01:00
|
|
|
declarativeContents."dc=example" = dbContents;
|
2020-08-02 23:52:37 +01:00
|
|
|
};
|
|
|
|
};
|
2021-02-18 11:56:58 +00:00
|
|
|
}) { inherit system pkgs; };
|
2020-08-02 23:52:37 +01:00
|
|
|
|
|
|
|
# Manually managed configDir, for example if dynamic config is essential
|
2021-02-18 11:56:58 +00:00
|
|
|
manualConfigDir = import ./make-test-python.nix ({ pkgs, ... }: {
|
2020-08-02 23:52:37 +01:00
|
|
|
name = "openldap";
|
|
|
|
|
|
|
|
machine = { pkgs, ... }: {
|
|
|
|
services.openldap = {
|
|
|
|
enable = true;
|
|
|
|
configDir = "/var/db/slapd.d";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = let
|
2020-08-24 00:07:24 +01:00
|
|
|
contents = pkgs.writeText "data.ldif" dbContents;
|
2020-08-02 23:52:37 +01: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 11:56:58 +00:00
|
|
|
}) { inherit system pkgs; };
|
2018-03-03 18:53:16 +00:00
|
|
|
}
|