summaryrefslogtreecommitdiff
path: root/_test/tests/inc/auth_deleteprofile.test.php
blob: dc38fcd16faa10b6467f6ccc4399ba99cf2a8b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php

class Mock_Auth_Plugin extends DokuWiki_Auth_Plugin {

	public $loggedOff = false;

    public function __construct($canDeleteUser = true) {
		$this->cando['delUser'] = $canDeleteUser;
    }

    public function checkPass($user, $pass) {
        return $pass == 'password';
    }

    public function deleteUsers($users) {
    	return in_array($_SERVER['REMOTE_USER'], $users);
    }

    public function logoff() {
    	$this->loggedOff = true;
    }

}

class auth_deleteprofile_test extends DokuWikiTest {

    /*
     * Tests:
     *
     * 1.   It works and the user is logged off 
     * 2.   Password matches when config requires it
     * 3,4. Auth plugin can prevent & wiki config can prevent
     * 5.  Any of invalid security token, missing/not set 'delete' flag, missing/unchecked 'confirm_delete'
     *
     */

    function test_success() {

        global $ACT, $INPUT, $conf, $auth;

        $ACT = 'profile_delete';
        $conf['profileconfirm'] = false;
    	$_SERVER['REMOTE_USER'] = 'testuser';

        $input = array(
            'do'                 => $ACT,
            'sectok'             => getSecurityToken(),
            'delete'             => '1',
            'confirm_delete'     => '1',
        );

        $_POST = $input;
        $_REQUEST = $input;
        $INPUT = new Input();

        $auth = new Mock_Auth_Plugin();

        $this->assertTrue(auth_deleteprofile());
        $this->assertTrue($auth->loggedOff);
    }

    function test_confirmation_required() {

        global $ACT, $INPUT, $conf, $auth;

        $ACT = 'profile_delete';
        $conf['profileconfirm'] = true;
    	$_SERVER['REMOTE_USER'] = 'testuser';

        $input = array(
            'do'                 => $ACT,
            'sectok'             => getSecurityToken(),
            'delete'             => '1',
            'confirm_delete'     => '1',
            'oldpass'            => 'wrong',
        );

        $_POST = $input;
        $_REQUEST = $input;
        $INPUT = new Input();

        $auth = new Mock_Auth_Plugin();

        // password check required - it fails, so don't delete profile
        $this->assertFalse(auth_deleteprofile());

        // now it passes, we're good to go
        $INPUT->set('oldpass','password');
        $INPUT->post->set('oldpass','password');
        $this->assertTrue(auth_deleteprofile());
    }

    function test_authconfig_prevents() {

        global $ACT, $INPUT, $conf, $auth;

        $ACT = 'profile_delete';
        $conf['profileconfirm'] = false;
    	$_SERVER['REMOTE_USER'] = 'testuser';

        $input = array(
            'do'                 => $ACT,
            'sectok'             => getSecurityToken(),
            'delete'             => '1',
            'confirm_delete'     => '1',
        );

        $_POST = $input;
        $_REQUEST = $input;
        $INPUT = new Input();

        $auth = new Mock_Auth_Plugin(false);
        $conf['disableactions'] = '';
        $this->assertFalse(auth_deleteprofile());
    }

    function test_wikiconfig_prevents() {

        global $ACT, $INPUT, $conf, $auth;

        $ACT = 'profile_delete';
        $conf['profileconfirm'] = false;
    	$_SERVER['REMOTE_USER'] = 'testuser';

        $input = array(
            'do'                 => $ACT,
            'sectok'             => getSecurityToken(),
            'delete'             => '1',
            'confirm_delete'     => '1',
        );

        $_POST = $input;
        $_REQUEST = $input;
        $INPUT = new Input();

        $auth = new Mock_Auth_Plugin();
        $conf['disableactions'] = 'profile_delete';

        $this->assertFalse(actionOK('profile_delete'));
        $this->assertTrue($auth->canDo('delUser'));

        $this->assertFalse(auth_deleteprofile());
    }

    function test_basic_parameters() {

        global $ACT, $INPUT, $conf, $auth;

        $ACT = 'profile_delete';
        $conf['profileconfirm'] = true;
    	$_SERVER['REMOTE_USER'] = 'testuser';

        $input = array(
            'do'                 => $ACT,
            'sectok'             => getSecurityToken(),
            'delete'             => '1',
            'confirm_delete'     => '1',
            'oldpass'            => 'password',
        );

        $_POST = $input;
        $_REQUEST = $input;
        $input_foundation = new Input();

        $auth = new Mock_Auth_Plugin();

        $INPUT = clone $input_foundation;
        $INPUT->remove('delete');
        $this->assertFalse(auth_deleteprofile());

        $INPUT = clone $input_foundation;
        $INPUT->set('sectok','wrong');
        $this->assertFalse(auth_deleteprofile());

        $INPUT = clone $input_foundation;
        $INPUT->remove('confirm_delete');
        $this->assertFalse(auth_deleteprofile());
    }
}