Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/nss-ldapd-test.conf29
-rw-r--r--tests/test_myldap.c280
3 files changed, 1 insertions, 316 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c9da7ea..7d46911 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,7 +20,7 @@
TESTS = test_dict test_tio test_cfg
-check_PROGRAMS = test_dict test_tio test_cfg test_myldap
+check_PROGRAMS = test_dict test_tio test_cfg
noinst_PROGRAMS = test_aliases test_ethers test_group test_hosts \
test_netgroup test_networks test_passwd test_protocols \
@@ -50,12 +50,6 @@ test_cfg_LDADD = ../nslcd/log.o ../nslcd/attmap.o ../common/dict.o \
../nslcd/service.o ../nslcd/shadow.o \
@nslcd_LIBS@ ../common/libtio.a ../common/libdict.a
-test_myldap_SOURCES = test_myldap.c
-test_myldap_CFLAGS = -pthread
-test_myldap_LDADD = ../nslcd/log.o ../common/dict.o \
- ../nslcd/common.o ../nslcd/cfg.o \
- ../nslcd/ldap-nss.o ../nslcd/pagectrl.o @nslcd_LIBS@
-
common_SOURCES = ../nss/common.c ../nslcd.h ../nss/prototypes.h \
../common/tio.c ../common/tio.h
diff --git a/tests/nss-ldapd-test.conf b/tests/nss-ldapd-test.conf
deleted file mode 100644
index bfbb3d2..0000000
--- a/tests/nss-ldapd-test.conf
+++ /dev/null
@@ -1,29 +0,0 @@
-# nss-ldapd-test.conf
-# nss-ldapd configuration file for test environment.
-# See nss-ldapd.conf(5) for details.
-
-# The location at which the LDAP server(s) should be reachable.
-uri ldap://127.0.0.1/
-
-# The search base that will be used for all queries.
-base dc=test,dc=tld
-
-# The LDAP protocol version to use.
-#ldap_version 3
-
-# The DN to bind with for normal lookups.
-#binddn cn=annonymous,dc=example,dc=net
-#bindpw *removed*
-
-# The DN to bind with for lookups as root.
-#rootbinddn cn=administrator,dc=example,dc=net
-#rootbindpw *removed*
-
-# The search scope.
-#scope sub
-
-# The number of answers to request in a single search.
-pagesize 3
-
-# The timeout for network operations.
-timelimit 4
diff --git a/tests/test_myldap.c b/tests/test_myldap.c
deleted file mode 100644
index 7398e3a..0000000
--- a/tests/test_myldap.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- test_myldap.c - simple test for the myldap module
- This file is part of the nss-ldapd library.
-
- Copyright (C) 2007 Arthur de Jong
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301 USA
-*/
-
-#include "config.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-#include <errno.h>
-#include <assert.h>
-
-#include "nslcd/log.h"
-#include "nslcd/cfg.h"
-#include "nslcd/myldap.h"
-
-struct worker_args {
- int id;
-};
-
-/* this is a simple way to get this into an executable,
- we should probably read a valid config instead */
-const char **base_get_var(int map) {return NULL;}
-int *scope_get_var(int map) {return NULL;}
-const char **filter_get_var(int map) {return NULL;}
-const char **attmap_get_var(int map,const char *name) {return NULL;}
-
-/* This is a very basic search test, it performs a test to get ceirtain
- entries from the database. It currently just prints out the DNs for
- the entries. */
-static void test_search(void)
-{
- MYLDAP_SESSION *session;
- MYLDAP_SEARCH *search;
- MYLDAP_ENTRY *entry;
- const char *attrs[] = { "uid", "cn", "gid", NULL };
-
- /* initialize session */
- printf("test_search(): getting session...\n");
- session=myldap_create_session();
- assert(session!=NULL);
-
- /* perform search */
- printf("test_search(): doing search...\n");
- search=myldap_search(session,nslcd_cfg->ldc_base,
- LDAP_SCOPE_SUBTREE,
- "(objectclass=posixaccount)",
- attrs);
- assert(search!=NULL);
-
- /* go over results */
- printf("test_search(): get results...\n");
- while ((entry=myldap_get_entry(search))!=NULL)
- {
- printf("test_search(): DN %s\n",myldap_get_dn(entry));
- }
- /* perform another search */
- printf("test_search(): doing search...\n");
- search=myldap_search(session,nslcd_cfg->ldc_base,
- LDAP_SCOPE_SUBTREE,
- "(objectclass=posixGroup)",
- attrs);
- assert(search!=NULL);
-
- /* go over results */
- printf("test_search(): get results...\n");
- while ((entry=myldap_get_entry(search))!=NULL)
- {
- printf("test_search(): DN %s\n",myldap_get_dn(entry));
- }
-
- /* TODO: call myldap_session_cleanup() or myldap_search_free() */
-}
-
-/* This search prints a number of attributes from a search */
-static void test_get_values(void)
-{
- MYLDAP_SESSION *session;
- MYLDAP_SEARCH *search;
- MYLDAP_ENTRY *entry;
- const char *attrs[] = { "uidNumber", "cn", "gidNumber", "uid", "objectClass", NULL };
- const char **vals;
- const char *rdnval;
-
- /* initialize session */
- printf("test_get_values(): getting session...\n");
- session=myldap_create_session();
- assert(session!=NULL);
-
- /* perform search */
- search=myldap_search(session,nslcd_cfg->ldc_base,
- LDAP_SCOPE_SUBTREE,
- "(&(objectClass=posixAccount)(uid=*))",
- attrs);
- assert(search!=NULL);
-
- /* go over results */
- while ((entry=myldap_get_entry(search))!=NULL)
- {
- printf("test_get_values(): DN %s\n",myldap_get_dn(entry));
- /* try to get uid from attribute */
- vals=myldap_get_values(entry,"uidNumber");
- assert((vals!=NULL)&&(vals[0]!=NULL));
- printf("test_get_values(): uidNumber=%s\n",vals[0]);
- /* try to get gid from attribute */
- vals=myldap_get_values(entry,"gidNumber");
- assert((vals!=NULL)&&(vals[0]!=NULL));
- printf("test_get_values(): gidNumber=%s\n",vals[0]);
- /* write LDF_STRING(PASSWD_NAME) */
- vals=myldap_get_values(entry,"uid");
- assert((vals!=NULL)&&(vals[0]!=NULL));
- printf("test_get_values(): uid=%s\n",vals[0]);
- /* get rdn values */
- rdnval=myldap_get_rdn_value(entry,"cn");
- printf("test_get_values(): cdrdn=%s\n",rdnval);
- rdnval=myldap_get_rdn_value(entry,"uid");
- printf("test_get_values(): uidrdn=%s\n",rdnval);
- /* check objectclass */
- assert(myldap_has_objectclass(entry,"posixAccount"));
- }
-
- /* TODO: call myldap_session_cleanup() or myldap_search_free() */
-
-}
-
-/* this method tests to see if we can perform two searches within
- one session */
-static void test_two_searches(void)
-{
- MYLDAP_SESSION *session;
- MYLDAP_SEARCH *search1,*search2;
- MYLDAP_ENTRY *entry;
- const char *attrs[] = { "uidNumber", "cn", "gidNumber", "uid", "objectClass", NULL };
- const char **vals;
- const char *rdnval;
-
- /* initialize session */
- printf("test_two_searches(): getting session...\n");
- session=myldap_create_session();
- assert(session!=NULL);
-
- /* perform search1 */
- search1=myldap_search(session,nslcd_cfg->ldc_base,
- LDAP_SCOPE_SUBTREE,
- "(&(objectClass=posixAccount)(uid=*))",
- attrs);
- assert(search1!=NULL);
-
- /* get a result from search1 */
- entry=myldap_get_entry(search1);
- assert(entry!=NULL);
- printf("test_two_searches(): [search1] DN %s\n",myldap_get_dn(entry));
- vals=myldap_get_values(entry,"cn");
- assert((vals!=NULL)&&(vals[0]!=NULL));
- printf("test_two_searches(): [search1] cn=%s\n",vals[0]);
-
- /* start a second search */
- search2=myldap_search(session,nslcd_cfg->ldc_base,
- LDAP_SCOPE_SUBTREE,
- "(&(objectclass=posixGroup)(gidNumber=6100))",
- attrs);
- assert(search1!=NULL);
-
- /* get a result from search2 */
- entry=myldap_get_entry(search2);
- assert(entry!=NULL);
- printf("test_two_searches(): [search2] DN %s\n",myldap_get_dn(entry));
- vals=myldap_get_values(entry,"cn");
- assert((vals!=NULL)&&(vals[0]!=NULL));
- printf("test_two_searches(): [search2] cn=%s\n",vals[0]);
-
- /* get another result from search1 */
- entry=myldap_get_entry(search1);
- assert(entry!=NULL);
- printf("test_two_searches(): [search1] DN %s\n",myldap_get_dn(entry));
- vals=myldap_get_values(entry,"cn");
- assert((vals!=NULL)&&(vals[0]!=NULL));
- printf("test_two_searches(): [search1] cn=%s\n",vals[0]);
-
-
- /* TODO: call myldap_session_cleanup() or myldap_search_free() */
-
-}
-
-/* perform a simple search */
-static void *worker(void *arg)
-{
- MYLDAP_SESSION *session;
- MYLDAP_SEARCH *search;
- MYLDAP_ENTRY *entry;
- const char *attrs[] = { "uid", "cn", "gid", NULL };
- struct worker_args *args=(struct worker_args *)arg;
-
- /* initialize session */
- session=myldap_create_session();
- assert(session!=NULL);
-
- /* perform search */
- search=myldap_search(session,nslcd_cfg->ldc_base,
- LDAP_SCOPE_SUBTREE,
- "(objectclass=posixaccount)",
- attrs);
- assert(search!=NULL);
-
- /* go over results */
- while ((entry=myldap_get_entry(search))!=NULL)
- {
- printf("test_threads(): [worker %d] DN %s\n",args->id,myldap_get_dn(entry));
- }
-
- printf("test_threads(): [worker %d] DONE\n",args->id);
-
- return 0;
-}
-
-/* thread ids of all running threads */
-#define NUM_THREADS 5
-pthread_t my_threads[NUM_THREADS];
-
-static void test_threads(void)
-{
- int i;
- struct worker_args args[NUM_THREADS];
-
- /* partially initialize logging */
- log_setdefaultloglevel(LOG_DEBUG);
-
- /* start worker threads */
- for (i=0;i<NUM_THREADS;i++)
- {
- args[i].id=i;
- if (pthread_create(&my_threads[i],NULL,worker,&(args[i])))
- {
- log_log(LOG_ERR,"unable to start worker thread %d: %s",i,strerror(errno));
- exit(1);
- }
- }
-
- /* wait for all threads to die */
- for (i=0;i<NUM_THREADS;i++)
- {
- if (pthread_join(my_threads[i],NULL))
- {
- log_log(LOG_ERR,"unable to wait for worker thread %d: %s",i,strerror(errno));
- exit(1);
- }
- }
-
-}
-
-/* the main program... */
-int main(int argc,char *argv[])
-{
- cfg_init("nss-ldapd-test.conf");
- /* partially initialize logging */
- log_setdefaultloglevel(LOG_DEBUG);
- test_search();
- test_get_values();
- test_two_searches();
- test_threads();
- return 0;
-}