]> git.sur5r.net Git - openldap/blob - tests/scripts/test064-constraint
Merge remote branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_4
[openldap] / tests / scripts / test064-constraint
1 #!/bin/bash
2
3 echo "running defines.sh"
4 . $SRCDIR/scripts/defines.sh
5
6 if test $CONSTRAINT = constraintno; then
7         echo "Constraint overlay not available, test skipped"
8         exit 0
9 fi
10
11 CONSTRAINTDIR="$DATADIR/constraint"
12 ROOTLDIF="$CONSTRAINTDIR/root.ldif"
13 USERLDIF="$CONSTRAINTDIR/user.ldif"
14 RESULTOUT="$CONSTRAINTDIR/constraint.out"
15 SCRIPTOUT="$TESTDIR/constraint.out"
16 USERDN="cn=John Doe,$BASEDN"
17
18 CONFDIR=$TESTDIR/slapd.d
19 mkdir -p $TESTDIR $CONFDIR $DBDIR1
20
21 $SLAPPASSWD -g -n >$CONFIGPWF
22
23 cat > $TESTDIR/config.ldif <<EOF
24 dn: cn=config
25 objectClass: olcGlobal
26 cn: config
27 olcArgsFile: $TESTDIR/slapd.args
28 olcPidFile: $TESTDIR/slapd.pid
29
30 dn: cn=schema,cn=config
31 objectClass: olcSchemaConfig
32 cn: schema
33
34 include: file://$TESTWD/schema/core.ldif
35 include: file://$TESTWD/schema/cosine.ldif
36 include: file://$TESTWD/schema/inetorgperson.ldif
37
38 dn: olcDatabase=config,cn=config
39 objectClass: olcDatabaseConfig
40 olcDatabase: config
41 olcRootPW:< file://$CONFIGPWF
42 EOF
43
44 if [ "$BACKENDTYPE" = mod ]; then
45         cat >> $TESTDIR/config.ldif <<EOF
46
47 dn: cn=module,cn=config
48 objectClass: olcModuleList
49 cn: module
50 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
51 olcModuleLoad: back_$BACKEND.la
52 EOF
53 fi
54
55 if [ "$CONSTRAINT" = constraintmod ]; then
56         cat >> $TESTDIR/config.ldif <<EOF
57
58 dn: cn=module,cn=config
59 objectClass: olcModuleList
60 cn: module
61 olcModulePath: $TESTWD/../servers/slapd/overlays
62 olcModuleLoad: constraint.la
63 EOF
64 fi
65
66 cat >> $TESTDIR/config.ldif <<EOF
67
68 dn: olcDatabase={1}$BACKEND,cn=config
69 objectClass: olcDatabaseConfig
70 objectClass: olc${BACKEND}Config
71 olcDatabase: $BACKEND
72 olcSuffix: $BASEDN
73 olcRootDN: $MANAGERDN
74 olcRootPW: $PASSWD
75 olcDbDirectory: $TESTDIR/db.1.a
76 EOF
77
78 if [ "$INDEXDB" = indexdb ]; then
79         cat >> $TESTDIR/config.ldif <<EOF
80 olcDbIndex: objectClass eq,pres
81 olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
82 EOF
83 fi
84
85 cat >> $TESTDIR/config.ldif <<EOF
86
87 dn: olcOverlay=constraint,olcDatabase={1}$BACKEND,cn=config
88 objectClass: olcOverlayConfig
89 objectClass: olcConstraintConfig
90 olcOverlay: constraint
91 olcConstraintAttribute: mail count 3
92 olcConstraintAttribute: mail regex ^[[:alnum:]]+@example.com$
93 olcConstraintAttribute: description count 2
94 # cn value has to be concatenated givenName SP sn
95 olcConstraintAttribute: cn,sn,givenName
96   set "(this/givenName + [ ] + this/sn) & this/cn"
97   restrict="ldap:///$USERDN??sub?(objectClass=inetOrgPerson)"
98 EOF
99
100 $SLAPADD -F $CONFDIR -n 0 -l $TESTDIR/config.ldif
101
102 echo "Starting slapd on TCP/IP port $PORT1..."
103 $SLAPD -F $CONFDIR -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
104 PID=$!
105 if test $WAIT != 0 ; then
106         echo PID $PID
107         read foo
108 fi
109 sleep 1
110
111 echo "Adding basic structure..."
112 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $ROOTLDIF &>/dev/null
113 RC=$?
114 if test $RC != 0 ; then
115         echo "ldapadd failed ($RC)!"
116         test $KILLSERVERS != no && kill -HUP $PID
117         exit $RC
118 fi
119 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $USERLDIF &>/dev/null
120 RC=$?
121 if test $RC != 0 ; then
122         echo "ldapadd failed ($RC)!"
123         test $KILLSERVERS != no && kill -HUP $PID
124         exit $RC
125 fi
126
127 echo "Running constraint tests..."
128 for ldif in $SRCDIR/data/constraint/{*ok*,*fail*}.ldif; do
129         ### reload
130         $LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD "$USERDN" &>/dev/null
131         RC=$?
132         if test $RC != 0 ; then
133                 echo "ldapdelete failed ($RC)!"
134                 test $KILLSERVERS != no && kill -HUP $PID
135                 exit $RC
136         fi
137         $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $USERLDIF &>/dev/null
138         RC=$?
139         if test $RC != 0 ; then
140                 echo "ldapadd failed ($RC)!"
141                 test $KILLSERVERS != no && kill -HUP $PID
142                 exit $RC
143         fi
144
145         ### info
146         echo -n "  [$ldif]: "
147
148         ### modify
149         $LDAPMODIFY -H $URI1 -x -D "$MANAGERDN" -f $ldif -w $PASSWD &>/dev/null
150         RC=$?
151         if test $RC == 0 ; then
152                 echo "OK" | tee -a $SCRIPTOUT
153         elif test $RC == 19 ; then
154                 echo "FAIL" | tee -a $SCRIPTOUT
155         else
156                 echo "UNEXPECTED ($RC)"
157         fi
158 done
159
160 echo "Comparing output..."
161 $DIFF $SCRIPTOUT $RESULTOUT > $CMPOUT
162 RC=$?
163 if test $RC != 0 ; then
164         echo "Comparison failed"
165         test $KILLSERVERS != no && kill -HUP $PID
166         exit $RC
167 fi
168
169 test $KILLSERVERS != no && kill -HUP $PID
170
171 echo ">>>>> Test succeeded"
172
173 test $KILLSERVERS != no && wait
174
175 exit 0