Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed up test.lua, added a script to run it during the build #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lualdap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ install: src/$(LIBNAME)

clean:
rm -f $(OBJS) src/$(LIBNAME)

check:
LUA_CPATH="src/?.so.$V" tests/run-tests.sh
73 changes: 73 additions & 0 deletions lualdap/tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
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

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: [email protected]
userPassword: $(slappasswd -s "$password")
EOF

slapd -F "$d/slapd-config" -h ldap://localhost:3899/
trap 'kill -TERM $(cat "$d/slapd.pid")' EXIT

lua tests/test.lua localhost:3899 dc=example,dc=invalid uid=ldapuser,dc=example,dc=invalid "$password"
10 changes: 5 additions & 5 deletions lualdap/tests/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function print_attrs (dn, attrs)
if tv == "string" then
io.write (values)
elseif tv == "table" then
local n = table.getn (values)
local n = #values
for i = 1, n-1 do
io.write (values[i]..",")
end
Expand Down Expand Up @@ -77,7 +77,7 @@ function test_object (obj, objmethods)
-- trying to set metatable.
assert2 (false, pcall (setmetatable, ENV, {}))
-- checking existence of object's methods.
for i = 1, table.getn (objmethods) do
for i = 1, #objmethods do
local method = obj[objmethods[i]]
assert2 ("function", type(method))
assert2 (false, pcall (method), "no 'self' parameter accepted")
Expand Down Expand Up @@ -128,7 +128,7 @@ end
-- checks return value which should be a function AND also its return value.
---------------------------------------------------------------------
function check_future (ret, method, ...)
local ok, f = pcall (method, unpack (arg))
local ok, f = pcall (method, ...)
assert (ok, f)
assert2 ("function", type(f))
assert2 (ret, f())
Expand Down Expand Up @@ -377,7 +377,7 @@ tests = {
-- Main
---------------------------------------------------------------------

if table.getn(arg) < 1 then
if #arg < 1 then
print (string.format ("Usage %s host[:port] base [who [password]]", arg[0]))
os.exit()
end
Expand All @@ -390,7 +390,7 @@ PASSWORD = arg[4]
require"lualdap"
assert (type(lualdap)=="table", "couldn't load LDAP library")

for i = 1, table.getn (tests) do
for i = 1, #tests do
local t = tests[i]
io.write (t[1].." ...")
t[2] ()
Expand Down