aboutsummaryrefslogtreecommitdiffstats
path: root/main/lua-ldap/script-to-run-test.lua-against-a-dummy-slapd.patch
blob: 9ec951bd2889eeae424ea05819489957f2a53da7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From d69b83f1464a6326c426f0228bb98c626c7f64bd Mon Sep 17 00:00:00 2001
From: Dan Callaghan <dcallagh@redhat.com>
Date: Mon, 30 Jun 2014 11:27:56 +1000
Subject: [PATCH] Add script to run test.lua against a dummy slapd

Ported from https://src.fedoraproject.org/cgit/rpms/lua-ldap.git/tree/0002-script-to-run-test.lua-against-a-dummy-slapd.patch
Upstream-Issue: https://github.com/bdellegrazie/lualdap/pull/2
---
 Makefile           |  3 ++
 tests/run-tests.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
 create mode 100755 tests/run-tests.sh

diff --git a/Makefile b/Makefile
index 72ee348..9bfa542 100644
--- a/Makefile
+++ b/Makefile
@@ -26,3 +26,6 @@ install: src/$(LIBNAME)
 
 clean:
 	rm -f $(OBJS) src/$(LIBNAME)
+
+check:
+	LUA_CPATH="src/?.so.$V" sh tests/run-tests.sh
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
new file mode 100755
index 0000000..33949c1
--- /dev/null
+++ b/tests/run-tests.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+set -ex
+
+d=$(readlink -f "$(dirname $0)")
+password=thepassword
+
+rm -rf "$d/slapd-config" "$d/slapd-data"
+mkdir "$d/slapd-config" "$d/slapd-data"
+
+# populate slapd config
+slapadd -F "$d/slapd-config" -n0 <<EOF
+dn: cn=config
+objectClass: olcGlobal
+cn: config
+olcPidFile: $d/slapd.pid
+
+dn: cn=schema,cn=config
+objectClass: olcSchemaConfig
+cn: schema
+
+dn: cn=module,cn=config
+objectClass: olcModuleList
+cn: module
+olcModulepath: /usr/lib/openldap
+olcModuleload: back_bdb.so
+
+include: file:///etc/openldap/schema/core.ldif
+include: file:///etc/openldap/schema/cosine.ldif
+include: file:///etc/openldap/schema/inetorgperson.ldif
+include: file:///etc/openldap/schema/nis.ldif
+
+dn: olcDatabase=config,cn=config
+objectClass: olcDatabaseConfig
+olcDatabase: config
+olcAccess: to * by * none
+
+dn: olcDatabase=bdb,cn=config
+objectClass: olcDatabaseConfig
+objectClass: olcBdbConfig
+olcDatabase: bdb
+olcSuffix: dc=example,dc=invalid
+olcDbDirectory: $d/slapd-data
+olcDbIndex: objectClass eq
+olcAccess: to * by * write
+#olcAccess: to * by users write
+EOF
+
+# populate slapd data
+slapadd -F "$d/slapd-config" -n1 <<EOF
+dn: dc=example,dc=invalid
+objectClass: top
+objectClass: domain
+
+#dn: ou=users,dc=example,dc=invalid
+#objectClass: top
+#objectClass: organizationalUnit
+#ou: users
+
+dn: uid=ldapuser,dc=example,dc=invalid
+objectClass: top
+objectClass: person
+objectClass: organizationalperson
+objectClass: inetorgperson
+objectClass: posixAccount
+cn: My LDAP User
+givenName: My
+sn: LDAP User
+uid: ldapuser
+uidNumber: 15549
+gidNumber: 15549
+homeDirectory: /home/lol
+mail: ldapuser@example.invalid
+userPassword: $(slappasswd -s "$password")
+EOF
+
+slapd -F "$d/slapd-config" -h ldap://localhost:3899/
+trap 'kill -TERM $(cat "$d/slapd.pid")' EXIT
+
+${LUA:-lua} tests/test.lua \
+	localhost:3899 \
+	dc=example,dc=invalid \
+	uid=ldapuser,dc=example,dc=invalid \
+	"$password"