]> git.sur5r.net Git - openldap/blob - tests/scripts/test064-constraint
Merge remote-tracking branch 'origin/mdb.master'
[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,ou=users,$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
92   count 3
93   restrict="ldap:///ou=users,$BASEDN??one?(objectClass=inetOrgPerson)"
94 # check if restrict works (if not, this will apply to ou=users subtree as well
95 # and some tests will fail)
96 olcConstraintAttribute: mail count 1 restrict="ldap:///ou=groups,$BASEDN??one"
97 olcConstraintAttribute: mail regex ^[[:alnum:]]+@example.com$
98 olcConstraintAttribute: description count 2
99 # cn value has to be concatenated givenName SP sn
100 olcConstraintAttribute: cn,sn,givenName
101   set "(this/givenName + [ ] + this/sn) & this/cn"
102   restrict="ldap:///$USERDN??sub?(objectClass=inetOrgPerson)"
103 olcConstraintAttribute: uid
104   uri "ldap:///ou=groups,$BASEDN?uid?one?(objectClass=inetOrgPerson)"
105   restrict="ldap:///ou=users,$BASEDN??one"
106 EOF
107
108 $SLAPADD -F $CONFDIR -n 0 -l $TESTDIR/config.ldif
109
110 echo "Starting slapd on TCP/IP port $PORT1..."
111 $SLAPD -F $CONFDIR -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
112 PID=$!
113 if test $WAIT != 0 ; then
114         echo PID $PID
115         read foo
116 fi
117 sleep 1
118
119 echo "Adding basic structure..."
120 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $ROOTLDIF &>/dev/null
121 RC=$?
122 if test $RC != 0 ; then
123         echo "ldapadd failed ($RC)!"
124         test $KILLSERVERS != no && kill -HUP $PID
125         exit $RC
126 fi
127 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $USERLDIF &>/dev/null
128 RC=$?
129 if test $RC != 0 ; then
130         echo "ldapadd failed ($RC)!"
131         test $KILLSERVERS != no && kill -HUP $PID
132         exit $RC
133 fi
134
135 echo "Running constraint tests..."
136 for ldif in $SRCDIR/data/constraint/{*ok*,*fail*}.ldif; do
137         ### reload
138         $LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD "$USERDN" &>/dev/null
139         RC=$?
140         if test $RC != 0 ; then
141                 echo "ldapdelete failed ($RC)!"
142                 test $KILLSERVERS != no && kill -HUP $PID
143                 exit $RC
144         fi
145         $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $USERLDIF &>/dev/null
146         RC=$?
147         if test $RC != 0 ; then
148                 echo "ldapadd failed ($RC)!"
149                 test $KILLSERVERS != no && kill -HUP $PID
150                 exit $RC
151         fi
152
153         ### info
154         echo -n "  [$ldif]: "
155
156         ### modify
157         $LDAPMODIFY -H $URI1 -x -D "$MANAGERDN" -f $ldif -w $PASSWD &>/dev/null
158         RC=$?
159         if test $RC == 0 ; then
160                 echo "OK" | tee -a $SCRIPTOUT
161         elif test $RC == 19 ; then
162                 echo "FAIL" | tee -a $SCRIPTOUT
163         else
164                 echo "UNEXPECTED ($RC)"
165         fi
166 done
167
168 echo "Comparing output..."
169 $DIFF $SCRIPTOUT $RESULTOUT > $CMPOUT
170 RC=$?
171 if test $RC != 0 ; then
172         echo "Comparison failed"
173         test $KILLSERVERS != no && kill -HUP $PID
174         exit $RC
175 fi
176
177 test $KILLSERVERS != no && kill -HUP $PID
178
179 echo ">>>>> Test succeeded"
180
181 test $KILLSERVERS != no && wait
182
183 exit 0