samba-tool tests: add additional tests for "samba-tool user edit" command
authorBjörn Baumbach <bb@sernet.de>
Thu, 14 Mar 2019 13:04:28 +0000 (14:04 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 4 Jul 2019 02:07:20 +0000 (02:07 +0000)
Especially test handling of base64 encoded attribute values here.

Add selftest/knownfail.d/samba_tool.user_edit.
Tests fail, because:
 - can not work with ldif without a trailing new line
 - can not handle base64 strings

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14003

Signed-off-by: Björn Baumbach <bb@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/samba_tool/user_edit.sh
selftest/knownfail.d/samba_tool.user_edit [new file with mode: 0644]

index 166d45ae4d65d7699fcf72f3ddc4e5dd28203d02..0535efedbdd4181ef64adc41051ec66bd5410b77 100755 (executable)
@@ -16,6 +16,13 @@ PASSWORD="$3"
 STpath=$(pwd)
 . $STpath/testprogs/blackbox/subunit.sh
 
+display_name="Björn"
+display_name_b64="QmrDtnJu"
+display_name_new="Renamed Bjoern"
+# attribute value including control character
+# echo -e "test \a string" | base64
+display_name_con_b64="dGVzdCAHIHN0cmluZwo="
+
 tmpeditor=$(mktemp --suffix .sh -p $STpath/bin samba-tool-editor-XXXXXXXX)
 chmod +x $tmpeditor
 
@@ -39,6 +46,89 @@ EOF
        -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
 }
 
+# Test edit user - add base64 attributes
+add_attribute_base64() {
+       # create editor.sh
+       cat >$tmpeditor <<EOF
+#!/usr/bin/env bash
+user_ldif="\$1"
+
+grep -v '^$' \$user_ldif > \${user_ldif}.tmp
+echo "displayName:: $display_name_b64" >> \${user_ldif}.tmp
+
+mv \${user_ldif}.tmp \$user_ldif
+EOF
+
+       $PYTHON ${STpath}/source4/scripting/bin/samba-tool user edit \
+               sambatool1 --editor=$tmpeditor \
+               -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
+}
+
+get_attribute_base64() {
+       $PYTHON ${STpath}/source4/scripting/bin/samba-tool user show \
+               sambatool1 --attributes=displayName \
+               -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
+}
+
+delete_attribute() {
+       # create editor.sh
+       cat >$tmpeditor <<EOF
+#!/usr/bin/env bash
+user_ldif="\$1"
+
+grep -v '^displayName' \$user_ldif >> \${user_ldif}.tmp
+mv \${user_ldif}.tmp \$user_ldif
+EOF
+       $PYTHON ${STpath}/source4/scripting/bin/samba-tool user edit \
+               sambatool1 --editor=$tmpeditor \
+               -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
+}
+
+# Test edit user - add base64 attribute value including control character
+add_attribute_base64_control() {
+       # create editor.sh
+       cat >$tmpeditor <<EOF
+#!/usr/bin/env bash
+user_ldif="\$1"
+
+grep -v '^$' \$user_ldif > \${user_ldif}.tmp
+echo "displayName:: $display_name_con_b64" >> \${user_ldif}.tmp
+
+mv \${user_ldif}.tmp \$user_ldif
+EOF
+       $PYTHON ${STpath}/source4/scripting/bin/samba-tool user edit \
+               sambatool1 --editor=$tmpeditor \
+               -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
+}
+
+get_attribute_base64_control() {
+       $PYTHON ${STpath}/source4/scripting/bin/samba-tool user show \
+               sambatool1 --attributes=displayName \
+               -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
+}
+
+
+# Test edit user - change base64 attribute value including control character
+change_attribute_base64_control() {
+       # create editor.sh
+       cat >$tmpeditor <<EOF
+#!/usr/bin/env bash
+user_ldif="\$1"
+
+sed -i -e 's/displayName:: $display_name_con_b64/displayName: $display_name/' \
+       \$user_ldif
+EOF
+       $PYTHON ${STpath}/source4/scripting/bin/samba-tool user edit \
+               sambatool1 --editor=$tmpeditor \
+               -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
+}
+
+get_attribute_base64_control() {
+       $PYTHON ${STpath}/source4/scripting/bin/samba-tool user show \
+               sambatool1 --attributes=displayName \
+               -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD"
+}
+
 delete_user() {
        $PYTHON ${STpath}/source4/scripting/bin/samba-tool \
                user delete sambatool1 \
@@ -49,6 +139,13 @@ failed=0
 
 testit "create_test_user" create_test_user || failed=`expr $failed + 1`
 testit "edit_user" edit_user || failed=`expr $failed + 1`
+testit "add_attribute_base64" add_attribute_base64 || failed=`expr $failed + 1`
+testit_grep "get_attribute_base64" "^displayName:: $display_name_b64" get_attribute_base64 || failed=`expr $failed + 1`
+testit "delete_attribute" delete_attribute || failed=`expr $failed + 1`
+testit "add_attribute_base64_control" add_attribute_base64_control || failed=`expr $failed + 1`
+testit_grep "get_attribute_base64_control" "^displayName:: $display_name_con_b64" get_attribute_base64_control || failed=`expr $failed + 1`
+testit "change_attribute_base64_control" change_attribute_base64_control || failed=`expr $failed + 1`
+testit_grep "get_attribute_base64_control" "^displayName:: $display_name_b64" get_attribute_base64_control || failed=`expr $failed + 1`
 testit "delete_user" delete_user || failed=`expr $failed + 1`
 
 rm -f $tmpeditor
diff --git a/selftest/knownfail.d/samba_tool.user_edit b/selftest/knownfail.d/samba_tool.user_edit
new file mode 100644 (file)
index 0000000..46a1f2b
--- /dev/null
@@ -0,0 +1,3 @@
+samba.tests.samba_tool.user_edit.add_attribute_base64
+samba.tests.samba_tool.user_edit.add_attribute_base64_control
+samba.tests.samba_tool.user_edit.change_attribute_base64_control