[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 use dokuwiki\test\mock\AuthCaseInsensitivePlugin; 4 use dokuwiki\test\mock\AuthPlugin; 5 6 class auth_admin_test extends DokuWikiTest 7 { 8 9 private $oldauth; 10 11 function setUp() : void 12 { 13 parent::setUp(); 14 global $auth; 15 $this->oldauth = $auth; 16 } 17 18 function setSensitive() 19 { 20 global $auth; 21 $auth = new AuthPlugin(); 22 } 23 24 function setInSensitive() 25 { 26 global $auth; 27 $auth = new AuthCaseInsensitivePlugin(); 28 } 29 30 public function authenticateAdmin() 31 { 32 global $USERINFO; 33 $_SERVER['REMOTE_USER'] = 'testadmin'; 34 $USERINFO['grps'] = ['admin', 'foo', 'bar']; 35 36 global $auth; 37 $auth = new \auth_plugin_authplain(); 38 } 39 40 public function authenticateNonadmin() 41 { 42 global $USERINFO; 43 $_SERVER['REMOTE_USER'] = 'testuser'; 44 $USERINFO['grps'] = ['foo', 'bar']; 45 46 global $auth; 47 $auth = new \auth_plugin_authplain(); 48 } 49 50 function tearDown() : void 51 { 52 global $auth; 53 global $AUTH_ACL; 54 unset($AUTH_ACL); 55 $auth = $this->oldauth; 56 } 57 58 function test_ismanager_insensitive() 59 { 60 $this->setInSensitive(); 61 global $conf; 62 $conf['superuser'] = 'john,@admin,@Mötly Görls, Dörte'; 63 $conf['manager'] = 'john,@managers,doe, @Mötly Böys, Dänny'; 64 65 // anonymous user 66 $this->assertFalse(auth_ismanager('jill', null, false, true)); 67 68 // admin or manager users 69 $this->assertTrue(auth_ismanager('john', null, false, true)); 70 $this->assertTrue(auth_ismanager('doe', null, false, true)); 71 72 $this->assertTrue(auth_ismanager('dörte', null, false, true)); 73 $this->assertTrue(auth_ismanager('dänny', null, false, true)); 74 75 // admin or manager groups 76 $this->assertTrue(auth_ismanager('jill', array('admin'), false, true)); 77 $this->assertTrue(auth_ismanager('jill', array('managers'), false, true)); 78 79 $this->assertTrue(auth_ismanager('jill', array('mötly görls'), false, true)); 80 $this->assertTrue(auth_ismanager('jill', array('mötly böys'), false, true)); 81 } 82 83 function test_isadmin_insensitive() 84 { 85 $this->setInSensitive(); 86 global $conf; 87 $conf['superuser'] = 'john,@admin,doe,@roots'; 88 89 // anonymous user 90 $this->assertFalse(auth_ismanager('jill', null, true, true)); 91 92 // admin user 93 $this->assertTrue(auth_ismanager('john', null, true, true)); 94 $this->assertTrue(auth_ismanager('doe', null, true, true)); 95 96 // admin groups 97 $this->assertTrue(auth_ismanager('jill', array('admin'), true, true)); 98 $this->assertTrue(auth_ismanager('jill', array('roots'), true, true)); 99 $this->assertTrue(auth_ismanager('john', array('admin'), true, true)); 100 $this->assertTrue(auth_ismanager('doe', array('admin'), true, true)); 101 } 102 103 function test_ismanager_sensitive() 104 { 105 $this->setSensitive(); 106 global $conf; 107 $conf['superuser'] = 'john,@admin,@Mötly Görls, Dörte'; 108 $conf['manager'] = 'john,@managers,doe, @Mötly Böys, Dänny'; 109 110 // anonymous user 111 $this->assertFalse(auth_ismanager('jill', null, false, true)); 112 113 // admin or manager users 114 $this->assertTrue(auth_ismanager('john', null, false, true)); 115 $this->assertTrue(auth_ismanager('doe', null, false, true)); 116 117 $this->assertFalse(auth_ismanager('dörte', null, false, true)); 118 $this->assertFalse(auth_ismanager('dänny', null, false, true)); 119 120 // admin or manager groups 121 $this->assertTrue(auth_ismanager('jill', array('admin'), false, true)); 122 $this->assertTrue(auth_ismanager('jill', array('managers'), false, true)); 123 124 $this->assertFalse(auth_ismanager('jill', array('mötly görls'), false, true)); 125 $this->assertFalse(auth_ismanager('jill', array('mötly böys'), false, true)); 126 } 127 128 function test_isadmin_sensitive() 129 { 130 $this->setSensitive(); 131 global $conf; 132 $conf['superuser'] = 'john,@admin,doe,@roots'; 133 134 // anonymous user 135 $this->assertFalse(auth_ismanager('jill', null, true, true)); 136 137 // admin user 138 $this->assertTrue(auth_ismanager('john', null, true, true)); 139 $this->assertFalse(auth_ismanager('Doe', null, true, true)); 140 141 // admin groups 142 $this->assertTrue(auth_ismanager('jill', array('admin'), true, true)); 143 $this->assertTrue(auth_ismanager('jill', array('roots'), true, true)); 144 $this->assertTrue(auth_ismanager('john', array('admin'), true, true)); 145 $this->assertTrue(auth_ismanager('doe', array('admin'), true, true)); 146 $this->assertTrue(auth_ismanager('Doe', array('admin'), true, true)); 147 } 148 149 public function test_ismanager_authenticated_admin() 150 { 151 $this->authenticateAdmin(); 152 153 global $conf; 154 $conf['superuser'] = '@admin'; 155 $conf['manager'] = '@managers'; 156 157 global $auth; 158 $auth->createUser( 159 'alice', 160 '179ad45c6ce2cb97cf1029e212046e81', 161 'Alice', 162 'alice@example.com', 163 [ 164 'foo' 165 ] 166 ); 167 $auth->createUser( 168 'bob', 169 '179ad45c6ce2cb97cf1029e212046e81', 170 'Robert', 171 'bob@example.com', 172 [ 173 'managers' 174 ] 175 ); 176 177 $this->assertFalse(auth_ismanager('alice', null, false, true)); 178 $this->assertTrue(auth_ismanager('bob', null, false, true)); 179 } 180 181 public function test_isadmin_authenticated_nonadmin() 182 { 183 $this->authenticateNonadmin(); 184 185 global $conf; 186 $conf['superuser'] = '@admin'; 187 188 global $auth; 189 $auth->createUser( 190 'camilla', 191 '179ad45c6ce2cb97cf1029e212046e81', 192 'Camilla', 193 'camilla@example.com', 194 [ 195 'admin' 196 ] 197 ); 198 199 $this->assertTrue(auth_ismanager('camilla', null, true, true)); 200 } 201 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body