[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 use dokuwiki\Remote\AccessDeniedException; 4 use dokuwiki\Remote\Api; 5 use dokuwiki\Remote\RemoteException; 6 use dokuwiki\test\mock\AuthPlugin; 7 use dokuwiki\test\mock\AuthCreatePlugin; 8 9 /** 10 * Class remoteapicore_test 11 */ 12 class remoteapicore_createuser_test extends DokuWikiTest { 13 14 protected $userinfo; 15 protected $oldAuthAcl; 16 /** @var Api */ 17 protected $remote; 18 19 public function setUp() : void { 20 // we need a clean setup before each single test: 21 DokuWikiTest::setUpBeforeClass(); 22 23 parent::setUp(); 24 global $conf; 25 global $USERINFO; 26 global $AUTH_ACL; 27 global $auth; 28 $this->oldAuthAcl = $AUTH_ACL; 29 $this->userinfo = $USERINFO; 30 $auth = new AuthPlugin(); 31 32 $conf['remote'] = 1; 33 $conf['remoteuser'] = '@user'; 34 $conf['useacl'] = 0; 35 36 $this->remote = new Api(); 37 } 38 39 public function tearDown() : void { 40 parent::tearDown(); 41 42 global $USERINFO; 43 global $AUTH_ACL; 44 45 $USERINFO = $this->userinfo; 46 $AUTH_ACL = $this->oldAuthAcl; 47 } 48 49 public function test_createUser() 50 { 51 global $conf, $auth; 52 $conf['remote'] = 1; 53 $conf['remoteuser'] = 'testuser'; 54 $_SERVER['REMOTE_USER'] = 'testuser'; 55 56 $auth = new AuthCreatePlugin(); 57 // $user, $pwd, $name, $mail, $grps = null 58 $params = [ 59 [ 60 'user' => 'user1', 61 'password' => 'password1', 62 'name' => 'user1', 63 'mail' => 'user1@localhost', 64 'groups' => [ 65 'user', 66 'test' 67 ], 68 'notify' => false 69 ] 70 ]; 71 72 $actualCallResult = $this->remote->call('dokuwiki.createUser', $params); 73 $this->assertTrue($actualCallResult); 74 75 // if the user exists, no data is overwritten 76 $actualCallResult = $this->remote->call('dokuwiki.createUser', $params); 77 $this->assertFalse($actualCallResult); 78 } 79 80 public function test_createUserAuthPlain() 81 { 82 global $conf, $auth; 83 $conf['remote'] = 1; 84 $conf['remoteuser'] = 'testuser'; 85 $_SERVER['REMOTE_USER'] = 'testuser'; 86 $auth = new auth_plugin_authplain(); 87 $params = [ 88 [ 89 'user' => 'user1', 90 'password' => 'password1', 91 'name' => 'user1', 92 'mail' => 'user1@localhost', 93 'groups' => [ 94 'user', 95 'test' 96 ], 97 'notify' => false 98 ] 99 100 ]; 101 102 $callResult = $this->remote->call('dokuwiki.createUser', $params); 103 $this->assertTrue($callResult); 104 } 105 106 public function test_createUserAuthPlainUndefinedUser() 107 { 108 global $conf, $auth; 109 $conf['remote'] = 1; 110 $conf['remoteuser'] = 'testuser'; 111 $_SERVER['REMOTE_USER'] = 'testuser'; 112 $auth = new auth_plugin_authplain(); 113 $params = [ 114 [ 115 'user' => '' 116 ], 117 ]; 118 119 $this->expectException(RemoteException::class); 120 $this->expectExceptionCode(401); 121 $this->remote->call('dokuwiki.createUser', $params); 122 } 123 124 public function test_createUserAuthPlainUndefinedName() 125 { 126 global $conf, $auth; 127 $conf['remote'] = 1; 128 $conf['remoteuser'] = 'testuser'; 129 $_SERVER['REMOTE_USER'] = 'testuser'; 130 $auth = new auth_plugin_authplain(); 131 $params = [ 132 [ 133 'user' => 'hello' 134 ], 135 ]; 136 137 $this->expectException(RemoteException::class); 138 $this->expectExceptionCode(402); 139 $this->remote->call('dokuwiki.createUser', $params); 140 } 141 142 public function test_createUserAuthPlainBadEmail() 143 { 144 global $conf, $auth; 145 $conf['remote'] = 1; 146 $conf['remoteuser'] = 'testuser'; 147 $_SERVER['REMOTE_USER'] = 'testuser'; 148 $auth = new auth_plugin_authplain(); 149 $params = [ 150 [ 151 'user' => 'hello', 152 'name' => 'A new user', 153 'mail' => 'this is not an email address' 154 ], 155 ]; 156 157 $this->expectException(RemoteException::class); 158 $this->expectExceptionCode(403); 159 $this->remote->call('dokuwiki.createUser', $params); 160 } 161 162 public function test_createUserAuthCanNotDoAddUser() 163 { 164 $this->expectException(AccessDeniedException::class); 165 $this->expectExceptionMessageMatches('/can\'t do addUser/'); 166 global $conf, $auth; 167 $conf['remote'] = 1; 168 $conf['remoteuser'] = 'testuser'; 169 $_SERVER['REMOTE_USER'] = 'testuser'; 170 171 $auth = new AuthCreatePlugin(false); 172 $params = [ 173 [ 174 'user' => 'user1', 175 'password' => 'password1', 176 'name' => 'user1', 177 'mail' => 'user1@localhost', 178 'groups' => [ 179 'user', 180 'test' 181 ], 182 'notify' => false 183 ], 184 ]; 185 $this->remote->call('dokuwiki.createUser', $params); 186 } 187 188 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body