1f95ecbbfSAngus Gratton<?php 2f95ecbbfSAngus Gratton 3f95ecbbfSAngus Gratton/** 4f95ecbbfSAngus Gratton * These tests are designed to test the capacity of pluginauth to handle 5f95ecbbfSAngus Gratton * correct escaping of colon field delimiters and backslashes in user content. 6f95ecbbfSAngus Gratton * 7f95ecbbfSAngus Gratton * (Note that these tests set some Real Names, etc. that are may not be 8f95ecbbfSAngus Gratton * valid in the broader dokuwiki context, but the tests ensure that 9f95ecbbfSAngus Gratton * authplain won't get unexpectedly surprised.) 10f95ecbbfSAngus Gratton * 11f95ecbbfSAngus Gratton * @group plugin_authplain 12f95ecbbfSAngus Gratton * @group plugins 13f95ecbbfSAngus Gratton */ 14f95ecbbfSAngus Grattonclass helper_plugin_authplain_escaping_test extends DokuWikiTest { 15f95ecbbfSAngus Gratton 16*6c8c1f46SChristopher Smith protected $pluginsEnabled = array('authplainharness'); 17f95ecbbfSAngus Gratton protected $auth; 18f95ecbbfSAngus Gratton 19f95ecbbfSAngus Gratton protected function reloadUsers() { 20f95ecbbfSAngus Gratton /* auth caches data loaded from file, but recreated object forces reload */ 21*6c8c1f46SChristopher Smith $this->auth = new auth_plugin_authplainharness(); 22f95ecbbfSAngus Gratton } 23f95ecbbfSAngus Gratton 24f95ecbbfSAngus Gratton function setUp() { 25f95ecbbfSAngus Gratton global $config_cascade; 26f95ecbbfSAngus Gratton parent::setUp(); 27f95ecbbfSAngus Gratton $name = $config_cascade['plainauth.users']['default']; 28f95ecbbfSAngus Gratton copy($name, $name.".orig"); 29f95ecbbfSAngus Gratton $this->reloadUsers(); 30f95ecbbfSAngus Gratton } 31f95ecbbfSAngus Gratton 32f95ecbbfSAngus Gratton function tearDown() { 33f95ecbbfSAngus Gratton global $config_cascade; 34f95ecbbfSAngus Gratton parent::tearDown(); 35f95ecbbfSAngus Gratton $name = $config_cascade['plainauth.users']['default']; 36f95ecbbfSAngus Gratton copy($name.".orig", $name); 37f95ecbbfSAngus Gratton } 38f95ecbbfSAngus Gratton 39f95ecbbfSAngus Gratton public function testMediawikiPasswordHash() { 40f95ecbbfSAngus Gratton global $conf; 41f95ecbbfSAngus Gratton $conf['passcrypt'] = 'mediawiki'; 42f95ecbbfSAngus Gratton $this->auth->createUser("mwuser", "12345", "Mediawiki User", "me@example.com"); 43f95ecbbfSAngus Gratton $this->reloadUsers(); 44f95ecbbfSAngus Gratton $this->assertTrue($this->auth->checkPass("mwuser", "12345")); 45f95ecbbfSAngus Gratton $mwuser = $this->auth->getUserData("mwuser"); 46f95ecbbfSAngus Gratton $this->assertStringStartsWith(":B:",$mwuser['pass']); 47f95ecbbfSAngus Gratton $this->assertEquals("Mediawiki User",$mwuser['name']); 48f95ecbbfSAngus Gratton } 49f95ecbbfSAngus Gratton 50f95ecbbfSAngus Gratton public function testNameWithColons() { 51f95ecbbfSAngus Gratton $name = ":Colon: User:"; 52f95ecbbfSAngus Gratton $this->auth->createUser("colonuser", "password", $name, "me@example.com"); 53f95ecbbfSAngus Gratton $this->reloadUsers(); 54f95ecbbfSAngus Gratton $user = $this->auth->getUserData("colonuser"); 55f95ecbbfSAngus Gratton $this->assertEquals($name,$user['name']); 56f95ecbbfSAngus Gratton } 57f95ecbbfSAngus Gratton 58f95ecbbfSAngus Gratton public function testNameWithBackslashes() { 59f95ecbbfSAngus Gratton $name = "\\Slash\\ User\\"; 60f95ecbbfSAngus Gratton $this->auth->createUser("slashuser", "password", $name, "me@example.com"); 61f95ecbbfSAngus Gratton $this->reloadUsers(); 62f95ecbbfSAngus Gratton $user = $this->auth->getUserData("slashuser"); 63f95ecbbfSAngus Gratton $this->assertEquals($name,$user['name']); 64f95ecbbfSAngus Gratton } 65f95ecbbfSAngus Gratton 66f95ecbbfSAngus Gratton public function testModifyUser() { 67f95ecbbfSAngus Gratton global $conf; 68f95ecbbfSAngus Gratton $conf['passcrypt'] = 'mediawiki'; 69f95ecbbfSAngus Gratton $user = $this->auth->getUserData("testuser"); 70f95ecbbfSAngus Gratton $user['name'] = "\\New:Crazy:Name\\"; 71f95ecbbfSAngus Gratton $user['pass'] = "awesome new password"; 72f95ecbbfSAngus Gratton $this->auth->modifyUser("testuser", $user); 73f95ecbbfSAngus Gratton $this->reloadUsers(); 74f95ecbbfSAngus Gratton 75f95ecbbfSAngus Gratton $saved = $this->auth->getUserData("testuser"); 76f95ecbbfSAngus Gratton $this->assertEquals($saved['name'], $user['name']); 77f95ecbbfSAngus Gratton $this->assertTrue($this->auth->checkPass("testuser", $user['pass'])); 78f95ecbbfSAngus Gratton } 79f95ecbbfSAngus Gratton 80*6c8c1f46SChristopher Smith // really only required for developers to ensure this plugin will 81*6c8c1f46SChristopher Smith // work with systems running on PCRE 6.6 and lower. 82*6c8c1f46SChristopher Smith public function testLineSplit(){ 83*6c8c1f46SChristopher Smith $this->auth->setPregsplit_safe(false); 84*6c8c1f46SChristopher Smith 85*6c8c1f46SChristopher Smith $names = array( 86*6c8c1f46SChristopher Smith 'plain', 87*6c8c1f46SChristopher Smith 'ut-fठ8', 88*6c8c1f46SChristopher Smith 'colon:', 89*6c8c1f46SChristopher Smith 'backslash\\', 90*6c8c1f46SChristopher Smith 'alltogether\\ठ:' 91*6c8c1f46SChristopher Smith ); 92*6c8c1f46SChristopher Smith $userpass = 'user:password_hash:'; 93*6c8c1f46SChristopher Smith $other_user_data = ':email@address:group1,group2'; 94*6c8c1f46SChristopher Smith 95*6c8c1f46SChristopher Smith foreach ($names as $testname) { 96*6c8c1f46SChristopher Smith $escaped = str_replace(array('\\',':'),array('\\\\','\\:'),$testname); // escape : & \ 97*6c8c1f46SChristopher Smith $test_line = $userpass.$escaped.$other_user_data; 98*6c8c1f46SChristopher Smith $result = $this->auth->splitUserData($test_line); 99*6c8c1f46SChristopher Smith 100*6c8c1f46SChristopher Smith $this->assertEquals($testname, $result[2]); 101*6c8c1f46SChristopher Smith } 102f95ecbbfSAngus Gratton } 103f95ecbbfSAngus Gratton 104*6c8c1f46SChristopher Smith} 105*6c8c1f46SChristopher Smith 106*6c8c1f46SChristopher Smithclass auth_plugin_authplainharness extends auth_plugin_authplain { 107*6c8c1f46SChristopher Smith 108*6c8c1f46SChristopher Smith public function setPregsplit_safe($bool) { 109*6c8c1f46SChristopher Smith $this->_pregsplit_safe = $bool; 110*6c8c1f46SChristopher Smith } 111*6c8c1f46SChristopher Smith 112*6c8c1f46SChristopher Smith public function getPregsplit_safe(){ 113*6c8c1f46SChristopher Smith return $this->_pregsplit_safe; 114*6c8c1f46SChristopher Smith } 115*6c8c1f46SChristopher Smith 116*6c8c1f46SChristopher Smith public function splitUserData($line){ 117*6c8c1f46SChristopher Smith return $this->_splitUserData($line); 118*6c8c1f46SChristopher Smith } 119*6c8c1f46SChristopher Smith}