forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiColumnAuthenticateTest.php
More file actions
152 lines (137 loc) · 4.36 KB
/
Copy pathMultiColumnAuthenticateTest.php
File metadata and controls
152 lines (137 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* MultiColumnAuthenticateTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Auth
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AuthComponent', 'Controller/Component');
App::uses('MultiColumnAuthenticate', 'Authenticate.Controller/Component/Auth');
App::uses('AppModel', 'Model');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
/**
* Test case for FormAuthentication
*
* @package Cake.Test.Case.Controller.Component.Auth
*/
class MultiColumnAuthenticateTest extends CakeTestCase {
public $fixtures = array('plugin.authenticate.multi_user');
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Collection = $this->getMock('ComponentCollection');
$this->auth = new MultiColumnAuthenticate($this->Collection, array(
'fields' => array('username' => 'user', 'password' => 'password'),
'userModel' => 'MultiUser',
'columns' => array('user', 'email')
));
$password = Security::hash('password', null, true);
$User = ClassRegistry::init('MultiUser');
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
$this->response = $this->getMock('CakeResponse');
}
/**
* test authenticate email or username
*
* @return void
*/
public function testAuthenticateEmailOrUsername() {
$request = new CakeRequest('posts/index', false);
$expected = array(
'id' => 1,
'user' => 'mariano',
'email' => 'mariano@example.com',
'token' => '12345',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
);
$request->data = array('MultiUser' => array(
'user' => 'mariano',
'password' => 'password'
));
$result = $this->auth->authenticate($request, $this->response);
$this->assertEquals($expected, $result);
$request->data = array('MultiUser' => array(
'user' => 'mariano@example.com',
'password' => 'password'
));
$result = $this->auth->authenticate($request, $this->response);
$this->assertEquals($expected, $result);
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoData() {
$request = new CakeRequest('posts/index', false);
$request->data = array();
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoUsername() {
$request = new CakeRequest('posts/index', false);
$request->data = array('MultiUser' => array('password' => 'foobar'));
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoPassword() {
$request = new CakeRequest('posts/index', false);
$request->data = array('MultiUser' => array('user' => 'mariano'));
$this->assertFalse($this->auth->authenticate($request, $this->response));
$request->data = array('MultiUser' => array('user' => 'mariano@example.com'));
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateInjection() {
$request = new CakeRequest('posts/index', false);
$request->data = array(
'MultiUser' => array(
'user' => '> 1',
'password' => "' OR 1 = 1"
));
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test scope failure.
*
* @return void
*/
public function testAuthenticateScopeFail() {
$this->auth->settings['scope'] = array('user' => 'nate');
$request = new CakeRequest('posts/index', false);
$request->data = array('User' => array(
'user' => 'mariano',
'password' => 'password'
));
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
}