ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / tests / samba_tool / group_edit.sh
blob3db2c66ea603fd4d6a4dab56b558bc00bb6be634
1 #!/bin/sh
3 # Test for 'samba-tool group edit'
5 if [ $# -lt 3 ]; then
6 cat <<EOF
7 Usage: group_edit.sh SERVER USERNAME PASSWORD
8 EOF
9 exit 1
12 SERVER="$1"
13 USERNAME="$2"
14 PASSWORD="$3"
16 samba_ldbsearch=ldbsearch
17 if test -x $BINDIR/ldbsearch; then
18 samba_ldbsearch=$BINDIR/ldbsearch
21 STpath=$(pwd)
22 . $STpath/testprogs/blackbox/subunit.sh
24 display_name="Users in Göttingen"
25 display_name_b64="VXNlcnMgaW4gR8O2dHRpbmdlbg=="
26 display_name_new="Users in Goettingen"
27 # attribute value including control character
28 # echo -e "test \a string" | base64
29 display_name_con_b64="dGVzdCAHIHN0cmluZwo="
31 tmpeditor=$(mktemp --suffix .sh -p $SELFTEST_TMPDIR samba-tool-editor-XXXXXXXX)
32 chmod +x $tmpeditor
34 create_test_group()
36 $PYTHON ${STpath}/source4/scripting/bin/samba-tool \
37 group add testgroup1 \
38 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
41 delete_test_group()
43 $PYTHON ${STpath}/source4/scripting/bin/samba-tool \
44 group delete testgroup1 \
45 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
48 create_test_user()
50 $PYTHON ${STpath}/source4/scripting/bin/samba-tool \
51 user create testuser1 --random-password \
52 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
55 delete_test_user()
57 $PYTHON ${STpath}/source4/scripting/bin/samba-tool \
58 user delete testuser1 \
59 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
62 add_member()
64 user_dn=$($PYTHON ${STpath}/source4/scripting/bin/samba-tool \
65 user show testuser1 --attributes=dn \
66 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD" |
67 grep ^dn: | cut -d' ' -f2)
69 # create editor.sh
70 cat >$tmpeditor <<EOF
71 #!/usr/bin/env bash
72 group_ldif="\$1"
74 grep -v '^$' \$group_ldif > \${group_ldif}.tmp
75 echo "member: $user_dn" >> \${group_ldif}.tmp
77 mv \${group_ldif}.tmp \$group_ldif
78 EOF
80 $PYTHON ${STpath}/source4/scripting/bin/samba-tool \
81 group edit testgroup1 --editor=$tmpeditor \
82 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
85 get_member()
87 $PYTHON ${STpath}/source4/scripting/bin/samba-tool \
88 group listmembers testgroup1 \
89 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
92 # Test edit group - add base64 attributes
93 add_attribute_base64()
95 # create editor.sh
96 cat >$tmpeditor <<EOF
97 #!/usr/bin/env bash
98 group_ldif="\$1"
100 grep -v '^$' \$group_ldif > \${group_ldif}.tmp
101 echo "displayName:: $display_name_b64" >> \${group_ldif}.tmp
103 mv \${group_ldif}.tmp \$group_ldif
106 $PYTHON ${STpath}/source4/scripting/bin/samba-tool group edit \
107 testgroup1 --editor=$tmpeditor \
108 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
111 get_attribute_base64()
113 $samba_ldbsearch '(sAMAccountName=testgroup1)' displayName \
114 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
117 delete_attribute()
119 # create editor.sh
120 cat >$tmpeditor <<EOF
121 #!/usr/bin/env bash
122 group_ldif="\$1"
124 grep -v '^displayName' \$group_ldif >> \${group_ldif}.tmp
125 mv \${group_ldif}.tmp \$group_ldif
127 $PYTHON ${STpath}/source4/scripting/bin/samba-tool group edit \
128 testgroup1 --editor=$tmpeditor \
129 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
132 # Test edit group - add base64 attribute value including control character
133 add_attribute_base64_control()
135 # create editor.sh
136 cat >$tmpeditor <<EOF
137 #!/usr/bin/env bash
138 group_ldif="\$1"
140 grep -v '^$' \$group_ldif > \${group_ldif}.tmp
141 echo "displayName:: $display_name_con_b64" >> \${group_ldif}.tmp
143 mv \${group_ldif}.tmp \$group_ldif
145 $PYTHON ${STpath}/source4/scripting/bin/samba-tool group edit \
146 testgroup1 --editor=$tmpeditor \
147 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
150 get_attribute_base64_control()
152 $PYTHON ${STpath}/source4/scripting/bin/samba-tool group show \
153 testgroup1 --attributes=displayName \
154 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
157 get_attribute_force_no_base64()
159 # LDB_FLAG_FORCE_NO_BASE64_LDIF should be used here.
160 $PYTHON ${STpath}/source4/scripting/bin/samba-tool group show \
161 testgroup1 --attributes=displayName \
162 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
165 # Test edit group - change base64 attribute value including control character
166 change_attribute_base64_control()
168 # create editor.sh
169 cat >$tmpeditor <<EOF
170 #!/usr/bin/env bash
171 group_ldif="\$1"
173 sed -i -e 's/displayName:: $display_name_con_b64/displayName: $display_name/' \
174 \$group_ldif
176 $PYTHON ${STpath}/source4/scripting/bin/samba-tool group edit \
177 testgroup1 --editor=$tmpeditor \
178 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
181 # Test edit group - change attributes with LDB_FLAG_FORCE_NO_BASE64_LDIF
182 change_attribute_force_no_base64()
184 # create editor.sh
185 # Expects that the original attribute is available as clear text,
186 # because the LDB_FLAG_FORCE_NO_BASE64_LDIF should be used here.
187 cat >$tmpeditor <<EOF
188 #!/usr/bin/env bash
189 group_ldif="\$1"
191 sed -i -e 's/displayName: $display_name/displayName: $display_name_new/' \
192 \$group_ldif
195 $PYTHON ${STpath}/source4/scripting/bin/samba-tool group edit \
196 testgroup1 --editor=$tmpeditor \
197 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
200 get_changed_attribute_force_no_base64()
202 $PYTHON ${STpath}/source4/scripting/bin/samba-tool group show \
203 testgroup1 --attributes=displayName \
204 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
207 failed=0
209 testit "create_test_group" create_test_group || failed=$(expr $failed + 1)
210 testit "create_test_user" create_test_user || failed=$(expr $failed + 1)
211 testit "add_member" add_member || failed=$(expr $failed + 1)
212 testit_grep "get_member" "^testuser1" get_member || failed=$(expr $failed + 1)
213 testit "add_attribute_base64" add_attribute_base64 || failed=$(expr $failed + 1)
214 testit_grep "get_attribute_base64" "^displayName:: $display_name_b64" get_attribute_base64 || failed=$(expr $failed + 1)
215 testit "delete_attribute" delete_attribute || failed=$(expr $failed + 1)
216 testit "add_attribute_base64_control" add_attribute_base64_control || failed=$(expr $failed + 1)
217 testit_grep "get_attribute_base64_control" "^displayName:: $display_name_con_b64" get_attribute_base64_control || failed=$(expr $failed + 1)
218 testit "change_attribute_base64_control" change_attribute_base64_control || failed=$(expr $failed + 1)
219 testit_grep "get_attribute_base64" "^displayName:: $display_name_b64" get_attribute_base64 || failed=$(expr $failed + 1)
220 testit_grep "get_attribute_force_no_base64" "^displayName: $display_name" get_attribute_force_no_base64 || failed=$(expr $failed + 1)
221 testit "change_attribute_force_no_base64" change_attribute_force_no_base64 || failed=$(expr $failed + 1)
222 testit_grep "get_changed_attribute_force_no_base64" "^displayName: $display_name_new" get_changed_attribute_force_no_base64 || failed=$(expr $failed + 1)
223 testit "delete_test_group" delete_test_group || failed=$(expr $failed + 1)
224 testit "delete_test_user" delete_test_user || failed=$(expr $failed + 1)
226 rm -f $tmpeditor
228 exit $failed