1 import ./make-test-python.nix ({ pkgs, ... }: let
7 dn: ou=users,dc=example
8 objectClass: organizationalUnit
15 objectClass: olcGlobal
18 dn: cn=schema,cn=config
20 objectClass: olcSchemaConfig
22 include: file://${pkgs.openldap}/etc/schema/core.ldif
23 include: file://${pkgs.openldap}/etc/schema/cosine.ldif
24 include: file://${pkgs.openldap}/etc/schema/inetorgperson.ldif
26 dn: olcDatabase={0}config,cn=config
27 olcDatabase: {0}config
28 objectClass: olcDatabaseConfig
29 olcRootDN: cn=root,cn=config
30 olcRootPW: configpassword
32 dn: olcDatabase={1}mdb,cn=config
33 objectClass: olcDatabaseConfig
34 objectClass: olcMdbConfig
36 olcDbDirectory: /var/db/openldap
37 olcDbIndex: objectClass eq
39 olcRootDN: cn=root,dc=example
40 olcRootPW: notapassword
54 nodes.machine = { pkgs, ... }: {
55 environment.etc."openldap/root_password".text = "notapassword";
57 users.ldap = ldapClientConfig;
61 urlList = [ "ldapi:///" "ldap://" ];
64 "cn=schema".includes = [
65 "${pkgs.openldap}/etc/schema/core.ldif"
66 "${pkgs.openldap}/etc/schema/cosine.ldif"
67 "${pkgs.openldap}/etc/schema/inetorgperson.ldif"
68 "${pkgs.openldap}/etc/schema/nis.ldif"
70 "olcDatabase={0}config" = {
72 objectClass = [ "olcDatabaseConfig" ];
73 olcDatabase = "{0}config";
74 olcRootDN = "cn=root,cn=config";
75 olcRootPW = "configpassword";
78 "olcDatabase={1}mdb" = {
79 # This tests string, base64 and path values, as well as lists of string values
81 objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
82 olcDatabase = "{1}mdb";
83 olcDbDirectory = "/var/lib/openldap/db";
84 olcSuffix = "dc=example";
87 base64 = "Y249cm9vdCxkYz1leGFtcGxl";
90 path = "/etc/openldap/root_password";
99 declarativeContents.configuration = { ... }: {
100 services.openldap.declarativeContents."dc=example" = dbContents;
102 mutableConfig.configuration = { ... }: {
103 services.openldap = {
104 declarativeContents."dc=example" = dbContents;
105 mutableConfig = true;
109 inheritParentConfig = false;
110 configuration = { ... }: {
111 users.ldap = ldapClientConfig;
112 services.openldap = {
114 configDir = "/var/db/slapd.d";
120 testScript = { nodes, ... }: let
121 specializations = "${nodes.machine.config.system.build.toplevel}/specialisation";
123 dn: olcDatabase={1}mdb,cn=config
129 # Test startup with empty DB
130 machine.wait_for_unit("openldap.service")
132 with subtest("declarative contents"):
133 machine.succeed('${specializations}/declarativeContents/bin/switch-to-configuration test')
134 machine.wait_for_unit("openldap.service")
135 machine.succeed('ldapsearch -LLL -D "cn=root,dc=example" -w notapassword')
136 machine.fail('ldapmodify -D cn=root,cn=config -w configpassword -f ${pkgs.writeText "rootpw.ldif" changeRootPw}')
138 with subtest("mutable config"):
139 machine.succeed('${specializations}/mutableConfig/bin/switch-to-configuration test')
140 machine.succeed('ldapsearch -LLL -D "cn=root,dc=example" -w notapassword')
141 machine.succeed('ldapmodify -D cn=root,cn=config -w configpassword -f ${pkgs.writeText "rootpw.ldif" changeRootPw}')
142 machine.succeed('ldapsearch -LLL -D "cn=root,dc=example" -w foobar')
144 with subtest("manual config dir"):
146 'mkdir /var/db/slapd.d /var/db/openldap',
147 'slapadd -F /var/db/slapd.d -n0 -l ${pkgs.writeText "config.ldif" ldifConfig}',
148 'slapadd -F /var/db/slapd.d -n1 -l ${pkgs.writeText "contents.ldif" dbContents}',
149 'chown -R openldap:openldap /var/db/slapd.d /var/db/openldap',
150 '${specializations}/manualConfigDir/bin/switch-to-configuration test',
152 machine.succeed('ldapsearch -LLL -D "cn=root,dc=example" -w notapassword')
153 machine.succeed('ldapmodify -D cn=root,cn=config -w configpassword -f ${pkgs.writeText "rootpw.ldif" changeRootPw}')
154 machine.succeed('ldapsearch -LLL -D "cn=root,dc=example" -w foobar')