1*f95ecbbfSAngus Gratton<?php 2*f95ecbbfSAngus Gratton 3*f95ecbbfSAngus Gratton/** 4*f95ecbbfSAngus Gratton * These tests are designed to test the capacity of pluginauth to handle 5*f95ecbbfSAngus Gratton * correct escaping of colon field delimiters and backslashes in user content. 6*f95ecbbfSAngus Gratton * 7*f95ecbbfSAngus Gratton * (Note that these tests set some Real Names, etc. that are may not be 8*f95ecbbfSAngus Gratton * valid in the broader dokuwiki context, but the tests ensure that 9*f95ecbbfSAngus Gratton * authplain won't get unexpectedly surprised.) 10*f95ecbbfSAngus Gratton * 11*f95ecbbfSAngus Gratton * @group plugin_authplain 12*f95ecbbfSAngus Gratton * @group plugins 13*f95ecbbfSAngus Gratton */ 14*f95ecbbfSAngus Grattonclass helper_plugin_authplain_escaping_test extends DokuWikiTest { 15*f95ecbbfSAngus Gratton 16*f95ecbbfSAngus Gratton protected $pluginsEnabled = array('authplain'); 17*f95ecbbfSAngus Gratton protected $auth; 18*f95ecbbfSAngus Gratton 19*f95ecbbfSAngus Gratton protected function reloadUsers() { 20*f95ecbbfSAngus Gratton /* auth caches data loaded from file, but recreated object forces reload */ 21*f95ecbbfSAngus Gratton $this->auth = new auth_plugin_authplain(); 22*f95ecbbfSAngus Gratton } 23*f95ecbbfSAngus Gratton 24*f95ecbbfSAngus Gratton function setUp() { 25*f95ecbbfSAngus Gratton global $config_cascade; 26*f95ecbbfSAngus Gratton parent::setUp(); 27*f95ecbbfSAngus Gratton $name = $config_cascade['plainauth.users']['default']; 28*f95ecbbfSAngus Gratton copy($name, $name.".orig"); 29*f95ecbbfSAngus Gratton $this->reloadUsers(); 30*f95ecbbfSAngus Gratton } 31*f95ecbbfSAngus Gratton 32*f95ecbbfSAngus Gratton function tearDown() { 33*f95ecbbfSAngus Gratton global $config_cascade; 34*f95ecbbfSAngus Gratton parent::tearDown(); 35*f95ecbbfSAngus Gratton $name = $config_cascade['plainauth.users']['default']; 36*f95ecbbfSAngus Gratton copy($name.".orig", $name); 37*f95ecbbfSAngus Gratton } 38*f95ecbbfSAngus Gratton 39*f95ecbbfSAngus Gratton public function testMediawikiPasswordHash() { 40*f95ecbbfSAngus Gratton global $conf; 41*f95ecbbfSAngus Gratton $conf['passcrypt'] = 'mediawiki'; 42*f95ecbbfSAngus Gratton $this->auth->createUser("mwuser", "12345", "Mediawiki User", "me@example.com"); 43*f95ecbbfSAngus Gratton $this->reloadUsers(); 44*f95ecbbfSAngus Gratton $this->assertTrue($this->auth->checkPass("mwuser", "12345")); 45*f95ecbbfSAngus Gratton $mwuser = $this->auth->getUserData("mwuser"); 46*f95ecbbfSAngus Gratton $this->assertStringStartsWith(":B:",$mwuser['pass']); 47*f95ecbbfSAngus Gratton $this->assertEquals("Mediawiki User",$mwuser['name']); 48*f95ecbbfSAngus Gratton } 49*f95ecbbfSAngus Gratton 50*f95ecbbfSAngus Gratton public function testNameWithColons() { 51*f95ecbbfSAngus Gratton $name = ":Colon: User:"; 52*f95ecbbfSAngus Gratton $this->auth->createUser("colonuser", "password", $name, "me@example.com"); 53*f95ecbbfSAngus Gratton $this->reloadUsers(); 54*f95ecbbfSAngus Gratton $user = $this->auth->getUserData("colonuser"); 55*f95ecbbfSAngus Gratton $this->assertEquals($name,$user['name']); 56*f95ecbbfSAngus Gratton } 57*f95ecbbfSAngus Gratton 58*f95ecbbfSAngus Gratton public function testNameWithBackslashes() { 59*f95ecbbfSAngus Gratton $name = "\\Slash\\ User\\"; 60*f95ecbbfSAngus Gratton $this->auth->createUser("slashuser", "password", $name, "me@example.com"); 61*f95ecbbfSAngus Gratton $this->reloadUsers(); 62*f95ecbbfSAngus Gratton $user = $this->auth->getUserData("slashuser"); 63*f95ecbbfSAngus Gratton $this->assertEquals($name,$user['name']); 64*f95ecbbfSAngus Gratton } 65*f95ecbbfSAngus Gratton 66*f95ecbbfSAngus Gratton public function testModifyUser() { 67*f95ecbbfSAngus Gratton global $conf; 68*f95ecbbfSAngus Gratton $conf['passcrypt'] = 'mediawiki'; 69*f95ecbbfSAngus Gratton $user = $this->auth->getUserData("testuser"); 70*f95ecbbfSAngus Gratton $user['name'] = "\\New:Crazy:Name\\"; 71*f95ecbbfSAngus Gratton $user['pass'] = "awesome new password"; 72*f95ecbbfSAngus Gratton $this->auth->modifyUser("testuser", $user); 73*f95ecbbfSAngus Gratton $this->reloadUsers(); 74*f95ecbbfSAngus Gratton 75*f95ecbbfSAngus Gratton $saved = $this->auth->getUserData("testuser"); 76*f95ecbbfSAngus Gratton $this->assertEquals($saved['name'], $user['name']); 77*f95ecbbfSAngus Gratton $this->assertTrue($this->auth->checkPass("testuser", $user['pass'])); 78*f95ecbbfSAngus Gratton } 79*f95ecbbfSAngus Gratton 80*f95ecbbfSAngus Gratton} 81*f95ecbbfSAngus Gratton 82*f95ecbbfSAngus Gratton?>