summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2014-05-04 16:03:53 +0200
committerArthur de Jong <arthur@arthurdejong.org>2014-05-04 16:06:37 +0200
commit18d05b01dc6a53481b67839ca0332f56bf456f1e (patch)
tree7f16a160bac648646329a362e8a7874230cbdf16 /tests
parentfbea2a5d693a36a9899d22a20317b4c82253adbe (diff)
Add a test for setting member attribute mapping
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/test_attmap.c56
2 files changed, 63 insertions, 4 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 862b510..cf1009e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,8 +19,8 @@
# 02110-1301 USA
TESTS = test_dict test_set test_tio test_expr test_getpeercred test_cfg \
- test_myldap.sh test_common test_nsscmds.sh test_pamcmds.sh \
- test_manpages.sh test_clock test_tio_timeout
+ test_attmap test_myldap.sh test_common test_nsscmds.sh \
+ test_pamcmds.sh test_manpages.sh test_clock test_tio_timeout
if HAVE_PYTHON
TESTS += test_pycompile.sh test_pylint.sh
endif
@@ -32,8 +32,8 @@ AM_TESTS_ENVIRONMENT = PYTHON='@PYTHON@'; export PYTHON; \
builddir=$(builddir); export builddir;
check_PROGRAMS = test_dict test_set test_tio test_expr test_getpeercred \
- test_cfg test_myldap test_common test_clock test_tio_timeout \
- lookup_netgroup lookup_shadow
+ test_cfg test_attmap test_myldap test_common test_clock \
+ test_tio_timeout lookup_netgroup lookup_shadow
EXTRA_DIST = README nslcd-test.conf usernames.txt testenv.sh test_myldap.sh \
test_nsscmds.sh test_pamcmds.sh test_pamcmds.expect \
@@ -76,6 +76,9 @@ common_nslcd_LDADD = ../nslcd/log.o ../nslcd/common.o ../nslcd/invalidator.o \
test_cfg_SOURCES = test_cfg.c common.h
test_cfg_LDADD = $(common_nslcd_LDADD)
+test_attmap_SOURCES = test_attmap.c common.h
+test_attmap_LDADD = ../nslcd/cfg.o $(common_nslcd_LDADD)
+
test_myldap_SOURCES = test_myldap.c common.h
test_myldap_LDADD = ../nslcd/cfg.o $(common_nslcd_LDADD)
diff --git a/tests/test_attmap.c b/tests/test_attmap.c
new file mode 100644
index 0000000..112d5fa
--- /dev/null
+++ b/tests/test_attmap.c
@@ -0,0 +1,56 @@
+/*
+ test_cfg.c - simple test for the cfg module
+ This file is part of the nss-pam-ldapd library.
+
+ Copyright (C) 2014 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 <assert.h>
+
+#include "common.h"
+
+#include "nslcd/attmap.h"
+
+static void test_member_map(void)
+{
+ const char **var;
+ const char *res;
+ var = attmap_get_var(LM_GROUP, "member");
+ assert(var != NULL);
+ /* expected mapping */
+ res = attmap_set_mapping(var, "uniqueMember");
+ assert(res != NULL);
+ assertstreq(res, "uniqueMember");
+ /* no support for expressions */
+ res = attmap_set_mapping(var, "\"$fred\"");
+ assert(res == NULL);
+ /* but support empty string */
+ res = attmap_set_mapping(var, "\"\"");
+ assert(res != NULL);
+ assertstreq(res, "\"\"");
+}
+
+int main(int UNUSED(argc), char UNUSED(*argv[]))
+{
+ test_member_map();
+ return EXIT_SUCCESS;
+}