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 166c8c1f46SChristopher 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 */ 216c8c1f46SChristopher 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 806c8c1f46SChristopher Smith // really only required for developers to ensure this plugin will 816c8c1f46SChristopher Smith // work with systems running on PCRE 6.6 and lower. 826c8c1f46SChristopher Smith public function testLineSplit(){ 836c8c1f46SChristopher Smith $this->auth->setPregsplit_safe(false); 846c8c1f46SChristopher Smith 856c8c1f46SChristopher Smith $names = array( 866c8c1f46SChristopher Smith 'plain', 876c8c1f46SChristopher Smith 'ut-fठ8', 886c8c1f46SChristopher Smith 'colon:', 896c8c1f46SChristopher Smith 'backslash\\', 906c8c1f46SChristopher Smith 'alltogether\\ठ:' 916c8c1f46SChristopher Smith ); 926c8c1f46SChristopher Smith $userpass = 'user:password_hash:'; 936c8c1f46SChristopher Smith $other_user_data = ':email@address:group1,group2'; 946c8c1f46SChristopher Smith 956c8c1f46SChristopher Smith foreach ($names as $testname) { 966c8c1f46SChristopher Smith $escaped = str_replace(array('\\',':'),array('\\\\','\\:'),$testname); // escape : & \ 976c8c1f46SChristopher Smith $test_line = $userpass.$escaped.$other_user_data; 986c8c1f46SChristopher Smith $result = $this->auth->splitUserData($test_line); 996c8c1f46SChristopher Smith 100*9d846ff4SChristopher Smith $this->assertEquals($escaped, $result[2]); 1016c8c1f46SChristopher Smith } 102f95ecbbfSAngus Gratton } 103f95ecbbfSAngus Gratton 1046c8c1f46SChristopher Smith} 1056c8c1f46SChristopher Smith 1066c8c1f46SChristopher Smithclass auth_plugin_authplainharness extends auth_plugin_authplain { 1076c8c1f46SChristopher Smith 1086c8c1f46SChristopher Smith public function setPregsplit_safe($bool) { 1096c8c1f46SChristopher Smith $this->_pregsplit_safe = $bool; 1106c8c1f46SChristopher Smith } 1116c8c1f46SChristopher Smith 1126c8c1f46SChristopher Smith public function getPregsplit_safe(){ 1136c8c1f46SChristopher Smith return $this->_pregsplit_safe; 1146c8c1f46SChristopher Smith } 1156c8c1f46SChristopher Smith 1166c8c1f46SChristopher Smith public function splitUserData($line){ 1176c8c1f46SChristopher Smith return $this->_splitUserData($line); 1186c8c1f46SChristopher Smith } 1196c8c1f46SChristopher Smith}