PEP8: fix E401: multiple imports on one line
[samba.git] / python / samba / tests / samba_tool / edit.sh
1 #!/bin/sh
2 #
3 # Test for 'samba-tool user edit'
4
5 if [ $# -lt 3 ]; then
6 cat <<EOF
7 Usage: edit.sh SERVER USERNAME PASSWORD
8 EOF
9 exit 1;
10 fi
11
12 SERVER="$1"
13 USERNAME="$2"
14 PASSWORD="$3"
15
16 STpath=$(pwd)
17 . $STpath/testprogs/blackbox/subunit.sh
18
19 # create editor.sh
20 # this has to be hard linked to /tmp or 'samba-tool user edit' cannot find it
21 tmpeditor=$(mktemp --suffix .sh -p $STpath/bin samba-tool-editor-XXXXXXXX)
22
23 cat >$tmpeditor <<-'EOF'
24 #!/usr/bin/env bash
25 user_ldif="$1"
26 SED=$(which sed)
27 $SED -i -e 's/userAccountControl: 512/userAccountControl: 514/' $user_ldif
28 EOF
29
30 chmod +x $tmpeditor
31
32 failed=0
33
34 # Create a test user
35 subunit_start_test "Create_User"
36 output=$(${STpath}/source4/scripting/bin/samba-tool user create sambatool1 --random-password \
37 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD")
38 status=$?
39 if [ "x$status" = "x0" ]; then
40     subunit_pass_test "Create_User"
41 else
42     echo "$output" | subunit_fail_test "Create_User"
43     failed=$((failed + 1))
44 fi
45
46 # Edit test user
47 subunit_start_test "Edit_User"
48 output=$(${STpath}/source4/scripting/bin/samba-tool user edit sambatool1 --editor=$tmpeditor \
49 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD")
50 status=$?
51 if [ "x$status" = "x0" ]; then
52     subunit_pass_test "Edit_User"
53 else
54     echo "$output" | subunit_fail_test "Edit_User"
55     failed=$((failed + 1))
56 fi
57
58 # Delete test user
59 subunit_start_test "Delete_User"
60 output=$(${STpath}/source4/scripting/bin/samba-tool user delete sambatool1 \
61 -H "ldap://$SERVER" "-U$USERNAME" "--password=$PASSWORD")
62 status=$?
63 if [ "x$status" = "x0" ]; then
64     subunit_pass_test "Delete_User"
65 else
66     echo "$output" | subunit_fail_test "Delete_User"
67     failed=$((failed + 1))
68 fi
69
70 rm -f $tmpeditor
71
72 exit $failed