3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21
GalleryCoreApi::requireOnce('modules/httpauth/classes/HttpAuthPlugin.class');
27
* @author Jack Bates<ms419@freezone.co.uk>
28
* @version $Revision: 15759 $
30
class HttpAuthPluginTest extends GalleryTestCase {
32
function HttpAuthPluginTest($methodName) {
33
$this->GalleryTestCase($methodName);
40
/* Create test user */
41
list ($ret, $this->_user) = $this->_createRandomUser(null, 'password');
43
print $ret->getAsHtml();
44
return $this->failWithStatus($ret);
46
$this->_markForCleanup($this->_user);
47
$_SERVER['AUTH_TYPE'] = 'Test';
49
$this->_plugin = new HttpAuthPlugin();
51
$this->_saveSession = $gallery->_session;
52
$gallery->_session = new HttpAuthPluginTestSession();
54
$this->_listener = new NullEventListener();
55
$this->_registerTestEventListener('Gallery::FailedLogin', $this->_listener);
60
$gallery->_session = $this->_saveSession;
62
$ret = GalleryCoreApi::removeAllMapEntries('FailedLoginsMap');
64
$this->failWithStatus($ret);
70
function testValidUser() {
72
$session =& $gallery->getSession();
74
$_SERVER['PHP_AUTH_USER'] = $this->_user->getUserName();
75
$_SERVER['PHP_AUTH_PW'] = 'password';
77
list ($ret, $user) = $this->_plugin->getUser();
79
return $this->failWithStatus($ret);
82
$this->assertEquals($this->_user, $user);
83
$this->assert(!isset($this->_listener->_event), 'There was a FailedLogin event!');
84
$this->assert($session->regenerateWasCalled(), 'Session has not been regenerated!');
87
function testInvalidUser() {
88
$_SERVER['PHP_AUTH_USER'] = 'bogusUser-' . rand();
89
$_SERVER['PHP_AUTH_PW'] = 'password';
91
list ($ret, $user) = $this->_plugin->getUser();
93
return $this->failWithStatus($ret);
96
$this->assert(!isset($user));
98
if (!isset($this->_listener->_event)) {
99
$this->assert(false, 'Listener didn\'t receive event!');
101
$eventData = $this->_listener->_event->getData();
102
$this->assertEquals($_SERVER['PHP_AUTH_USER'], $eventData['userName']);
106
function testValidUserInvalidPassword() {
107
$_SERVER['PHP_AUTH_USER'] = $this->_user->getUserName();
108
$_SERVER['PHP_AUTH_PW'] = 'wrongPassword';
110
list ($ret, $user) = $this->_plugin->getUser();
112
return $this->failWithStatus($ret);
115
$this->assert(!isset($user));
117
if (!isset($this->_listener->_event)) {
118
$this->assert(false, 'Listener didn\'t receive event!');
120
$eventData = $this->_listener->_event->getData();
121
$this->assertEquals($this->_user->getUserName(), $eventData['userName']);
125
function testNoFailedLoginEventForSpecialLogoutUsername() {
126
$_SERVER['PHP_AUTH_USER'] = '__LOGOUT__' . rand();
127
$_SERVER['PHP_AUTH_PW'] = 'somepassword';
129
list ($ret, $user) = $this->_plugin->getUser();
131
return $this->failWithStatus($ret);
134
$this->assert(!isset($user));
135
$this->assert(!isset($this->_listener->_event), 'There was a FailedLogin event!');
142
class HttpAuthPluginTestSession {
143
function HttpAuthPluginTestSession() {
144
$this->_regenerateWasCalled = false;
147
function getUserId() {
151
function regenerate() {
152
$this->_regenerateWasCalled = true;
155
function regenerateWasCalled() {
156
return $this->_regenerateWasCalled;