]> git.sur5r.net Git - openldap/blob - tests/scripts/test004-modify
2a55239ef1406ab734cb74283c1374122dde7f20
[openldap] / tests / scripts / test004-modify
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2015 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 mkdir -p $TESTDIR $DBDIR1
20
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
23 $SLAPADD -f $CONF1 -l $LDIFORDERED
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Starting slapd on TCP/IP port $PORT1..."
31 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
32 PID=$!
33 if test $WAIT != 0 ; then
34     echo PID $PID
35     read foo
36 fi
37 KILLPIDS="$PID"
38
39 sleep 1
40
41 echo "Testing slapd modify operations..."
42 for i in 0 1 2 3 4 5; do
43         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
44                 'objectclass=*' > /dev/null 2>&1
45         RC=$?
46         if test $RC = 0 ; then
47                 break
48         fi
49         echo "Waiting 5 seconds for slapd to start..."
50         sleep 5
51 done
52
53 if test $RC != 0 ; then
54         echo "ldapsearch failed ($RC)!"
55         test $KILLSERVERS != no && kill -HUP $KILLPIDS
56         exit $RC
57 fi
58
59 echo "Testing modify, add, and delete..."
60 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
61         $TESTOUT 2>&1 << EOMODS
62 version: 1
63
64 # LEADING COMMENT AND WHITE SPACE
65
66 dn: cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com
67 # EMBEDDED COMMENT
68 changetype: modify
69 add: drink
70 drink: Pils
71 -
72 add: drink
73 drink: Orange Juice
74 -
75 delete: drink
76 drink: Pils
77 -
78 delete: sn
79 sn: Jones
80 -
81 add: sn
82 sn: Jones
83
84 dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
85 changetype: modify
86 # EMBEDDED COMMENT
87  CONTINUED
88 replace: description
89 description: The replaced multiLineDescription $ Blah Woof.
90 -
91 replace: drink
92 drink: Iced Tea
93 drink: Mad Dog 20/20
94
95 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
96 changetype: modify
97 delete: uniquemember
98 uniquemember: cn=James A Jones 2,ou=Information Technology Division,
99  ou=People,dc=example,dc=com
100 uniquemember: cn=Bjorn Jensen,ou=Information Technology Division,
101  ou=People,dc=example,dc=com
102 -
103 add: uniquemember
104 uniquemember: cn=Dorothy Stevens,ou=Alumni Association,
105  ou=People,dc=example,dc=com
106 uniquemember: cn=James A Jones 1,ou=Alumni Association,
107  ou=People,dc=example,dc=com
108 -
109 add: objectClass
110 objectClass: OpenLDAPdisplayableObject
111 objectClass: pkiUser
112 objectClass: userSecurityInformation
113 -
114 delete: objectClass
115 objectClass: userSecurityInformation
116 objectClass: pkiUser
117 objectClass: OpenLDAPdisplayableObject
118
119 dn: cn=All Staff,ou=Groups,dc=example,dc=com
120 changetype: modify
121 delete: member
122 -
123 add: member
124 member: cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com
125 -
126 delete: description
127 -
128 add: objectClass
129 objectClass: OpenLDAPdisplayableObject
130 objectClass: pkiUser
131 objectClass: userSecurityInformation
132 -
133 delete: objectClass
134 objectClass: OpenLDAPdisplayableObject
135 objectClass: pkiUser
136 objectClass: userSecurityInformation
137
138 dn: cn=Gern Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
139 changetype: add
140 objectclass: testPerson
141 cn: Gern Jensen
142 sn: Jensen
143 uid: gjensen
144 title: Chief Investigator, ITD
145 postaladdress: ITD $ 535 W. William St $ Anytown, MI 48103
146 seealso: cn=All Staff,ou=Groups,dc=example,dc=com
147 drink: Coffee
148 homepostaladdress: 844 Brown St. Apt. 4 $ Anytown, MI 48104
149 description: Very odd
150 facsimiletelephonenumber: +1 313 555 7557
151 telephonenumber: +1 313 555 8343
152 mail: gjensen@mailgw.example.com
153 homephone: +1 313 555 8844
154 testTime: 20050304001801.234Z
155
156 dn: cn=James A Jones 2,ou=Information Technology Division,ou=People,dc=example,dc=com
157 changetype: delete
158 # TRAILING COMMENT AND WHITE SPACE
159
160 dn: ou=People,dc=example,dc=com
161 changetype: modify
162 increment: uidNumber
163 uidNumber: 1
164 -
165 increment: gidNumber
166 gidNumber: -1
167
168 dn: dc=example,dc=com
169 changetype: modify
170 # EMPTY SEQUENCE OF CHANGE
171
172 EOMODS
173
174 RC=$?
175 if test $RC != 0 ; then
176         echo "ldapmodify failed ($RC)!"
177         test $KILLSERVERS != no && kill -HUP $KILLPIDS
178         exit $RC
179 fi
180
181 echo "Using ldapmodify to add an empty entry (should fail with protocolError)..."
182 $LDAPMODIFY -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
183          >> $TESTOUT 2>&1 << EOMODS
184 dn: cn=Foo Bar,dc=example,dc=com
185 changetype: add
186 # EMPTY SEQUENCE OF ATTRS
187 EOMODS
188
189 RC=$?
190 case $RC in
191 2)
192         echo "  ldapmodify failed ($RC)"
193         ;;
194 0)
195         echo "  ldapmodify should have failed ($RC)!"
196         test $KILLSERVERS != no && kill -HUP $KILLPIDS
197         exit -1
198         ;;
199 *)
200         echo "  ldapmodify failed ($RC)!"
201         test $KILLSERVERS != no && kill -HUP $KILLPIDS
202         exit $RC
203         ;;
204 esac
205
206 echo "Using ldapsearch to retrieve all the entries..."
207 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
208             'objectClass=*' > $SEARCHOUT 2>&1
209 RC=$?
210 test $KILLSERVERS != no && kill -HUP $KILLPIDS
211 if test $RC != 0 ; then
212         echo "ldapsearch failed ($RC)!"
213         exit $RC
214 fi
215
216 LDIF=$MODIFYOUTMASTER
217
218 echo "Filtering ldapsearch results..."
219 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
220 echo "Filtering original ldif used to create database..."
221 $LDIFFILTER < $LDIF > $LDIFFLT
222 echo "Comparing filter output..."
223 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
224
225 if test $? != 0 ; then
226         echo "comparison failed - modify operations did not complete correctly"
227         exit 1
228 fi
229
230 echo ">>>>> Test succeeded"
231
232 test $KILLSERVERS != no && wait
233
234 exit 0