Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 37ce159

Browse files
committed
ENH: refs #952. Fix failing user-related tests
They broke as a result of the password hashing changes
1 parent 73f3ff4 commit 37ce159

File tree

8 files changed

+56
-54
lines changed

8 files changed

+56
-54
lines changed

core/tests/controllers/UserControllerTest.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ public function testLoginAction()
9494
$this->assertTrue(is_string($resp->message) && strlen($resp->message) > 0);
9595
$this->assertFalse(Zend_Auth::getInstance()->hasIdentity());
9696

97-
// Must set the password here since our salt is dynamic
9897
$userDao = $this->User->getByEmail('user1@user1.com');
99-
$userDao->setPassword(md5(Zend_Registry::get('configGlobal')->password->prefix.'test'));
98+
$this->User->changePassword($userDao, 'test');
10099
$this->User->save($userDao);
101100

102101
$this->resetAll();
@@ -139,7 +138,7 @@ public function testRecoverpasswordAction()
139138
$this->dispatchUrI("/user/recoverpassword", null);
140139

141140
$userDao2 = $this->User->getByEmail($this->params['email']);
142-
$this->assertNotEquals($userDao->getPassword(), $userDao2->getPassword(), 'Unable to change password');
141+
$this->assertNotEquals($userDao->getSalt(), $userDao2->getSalt(), 'Salt should have changed');
143142
$this->setupDatabase(array('default'));
144143
}
145144

@@ -243,14 +242,25 @@ public function testSettingsAction()
243242
$this->params['newPassword'] = 'newPassword';
244243
$this->request->setMethod('POST');
245244
$this->dispatchUrI("/user/settings", $userDao);
245+
$resp = json_decode($this->getBody());
246+
$this->assertTrue($resp[0] == false);
246247

247-
$userCheckDao = $this->User->getByEmail($userDao->getEmail());
248-
// Must set the password here since our salt is dynamic
249-
$userCheckDao->setPassword(md5(Zend_Registry::get('configGlobal')->password->prefix.'test'));
250-
$this->User->save($userCheckDao);
251-
252-
$this->assertNotEquals($userDao->getPassword(), $userCheckDao->getPassword(), 'Unable to change password');
248+
// Store old password so it will authenticate
249+
$instanceSalt = Zend_Registry::get('configGlobal')->password->prefix;
250+
$this->User->storePasswordHash(hash('sha256', $instanceSalt.$userDao->getSalt().'test'));
251+
$this->resetAll();
252+
$this->params = array();
253+
$this->params['modifyPassword'] = 'true';
254+
$this->params['oldPassword'] = 'test';
255+
$this->params['newPassword'] = 'newPassword';
256+
$this->request->setMethod('POST');
257+
$this->dispatchUrI("/user/settings", $userDao);
258+
$resp = json_decode($this->getBody());
259+
$this->assertTrue($resp[0] == true);
253260

261+
$userCheckDao = $this->User->getByEmail($userDao->getEmail());
262+
$this->assertNotEquals($userDao->getSalt(), $userCheckDao->getSalt(), 'Salt should have changed');
263+
$this->assertTrue($this->User->hashExists(hash('sha256', $instanceSalt.$userCheckDao->getSalt().'newPassword')), 'New hash should have been added to password table');
254264
$this->setupDatabase(array('default'));
255265

256266
$this->resetAll();
@@ -407,9 +417,8 @@ public function testUserexistsAction()
407417
$resp = json_decode($this->getBody());
408418
$this->assertTrue($resp->status == false);
409419

410-
// Must set the password here since our salt is dynamic
411420
$userDao = $this->User->getByEmail('user1@user1.com');
412-
$userDao->setPassword(md5(Zend_Registry::get('configGlobal')->password->prefix.'test'));
421+
$this->User->changePassword($userDao, 'test');
413422
$this->User->save($userDao);
414423

415424
$this->resetAll();

core/tests/databaseDataset/adminUser.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<dataset>
33
<user user_id="11111" firstname="FirstName11111" lastname="LastName11111"
4-
email="user11111@user11111.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:09:02"
4+
email="user11111@user11111.com" creation="2011-01-27 12:09:02" hash_alg="sha256"
55
folder_id="11110" admin="1"/>
66

77
<folder folder_id="11110" name="User 11111 name Folder 1" uuid='4e311fdf82007c245b07d8d6c4fcb4205f2621eb70'

core/tests/databaseDataset/default.xml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,16 @@
4848
name="Community test User 1 Member" />
4949

5050

51-
<user user_id="1" firstname="FirstName1" lastname="LastName1"
52-
email="user1@user1.com" password="35fd8ba86ba403ffcc00feac5355ad20"
53-
creation="2011-01-27 12:09:02" folder_id="1000" admin="0" />
51+
<user user_id="1" firstname="FirstName1" lastname="LastName1" hash_alg="sha256"
52+
email="user1@user1.com" creation="2011-01-27 12:09:02" folder_id="1000" admin="0" />
5453

5554
<!-- To test Export component -->
56-
<user user_id="2" firstname="FirstName2" lastname="LastName2"
57-
email="user2@user2.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:10:02" admin="0" />
55+
<user user_id="2" firstname="FirstName2" lastname="LastName2" hash_alg="sha256"
56+
email="user2@user2.com" creation="2011-01-27 12:10:02" admin="0" />
5857
<folderpolicygroup folder_id="1001" group_id="0" policy="0" />
5958
<!-- To test admin user capabilities -->
60-
<user user_id="3" firstname="Admin" lastname="Admin"
61-
email="admin@admin.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:11:02" admin="1"
62-
folder_id="1006" />
59+
<user user_id="3" firstname="Admin" lastname="Admin" hash_alg="sha256"
60+
email="admin@admin.com" creation="2011-01-27 12:11:02" admin="1" folder_id="1006" />
6361

6462
<user2group group_id="3000" user_id="1" />
6563
<user2group group_id="3002" user_id="1" />
@@ -168,16 +166,17 @@
168166
<itempolicyuser item_id="1006" user_id="1" policy='2' />
169167
<item2folder item_id="1006" folder_id='1014' />
170168

171-
<user user_id="4" firstname="community2001" lastname="Member"
172-
admin="0" email="community2001@member.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:11:02" folder_id="1006" />
169+
<user user_id="4" firstname="community2001" lastname="Member" hash_alg="sha256"
170+
admin="0" email="community2001@member.com" creation="2011-01-27 12:11:02" folder_id="1006" />
173171
<user2group group_id="3005" user_id="4" />
174-
<user user_id="5" firstname="community2001" lastname="Moderator"
175-
admin="0" email="community2001@moderator.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:11:02" folder_id="1006" />
172+
<user user_id="5" firstname="community2001" lastname="Moderator" hash_alg="sha256"
173+
admin="0" email="community2001@moderator.com" creation="2011-01-27 12:11:02" folder_id="1006" />
176174
<user2group group_id="3004" user_id="5" />
177-
<user user_id="6" firstname="community2001" lastname="Admin"
178-
admin="0" email="community2001@admin.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:11:02" folder_id="1006" />
175+
<user user_id="6" firstname="community2001" lastname="Admin" hash_alg="sha256"
176+
admin="0" email="community2001@admin.com" creation="2011-01-27 12:11:02" folder_id="1006" />
179177
<user2group group_id="3003" user_id="6" />
180178

181179
<newuserinvitation newuserinvitation_id="1001" email="dummy@dummy.com" auth_key="12345" inviter_id="4" community_id="2001" group_id="3003" date_creation="2011-01-27 12:11:02" />
182-
<pendinguser pendinguser_id="1001" email="dummy@dummy.com" auth_key="12345" password="abcdef" firstname="Dummy" lastname="Dummy" date_creation="2011-01-27 12:11:02" />
180+
<pendinguser pendinguser_id="1001" email="dummy@dummy.com" auth_key="12345" firstname="Dummy" lastname="Dummy" date_creation="2011-01-27 12:11:02" />
181+
<password hash="dummy_hash" />
183182
</dataset>

core/tests/databaseDataset/policies.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
creation="2011-01-27 12:09:02" privacy="0" folder_id="1003" admingroup_id="3000" moderatorgroup_id="3001"
66
membergroup_id="3002" uuid='4e311fdf82107d245f0798d654fc24205f2621eb72777' />
77

8-
<user user_id="1" firstname="FirstName1" lastname="LastName1" email="user1@user1.com" password="35fd8ba86ba403ffcc00feac5355ad20"
9-
creation="2011-01-27 12:09:02" folder_id="1000" admin="0" />
10-
<user user_id="2" firstname="FirstName2" lastname="LastName2" email="user2@user2.com" password="35fd8ba86ba403ffcc00feac5355ad20"
11-
creation="2011-01-27 12:10:02" admin="0" />
12-
<user user_id="3" firstname="FirstName3" lastname="LastName3" email="user3@user3.com" password="35fd8ba86ba403ffcc00feac5355ad20"
13-
creation="2011-01-27 12:08:02" admin="0" />
14-
<user user_id="4" firstname="Admin" lastname="Admin" email="admin@admin.com" password="35fd8ba86ba403ffcc00feac5355ad20"
15-
creation="2011-01-27 12:11:02" admin="1" />
8+
<user user_id="1" firstname="FirstName1" lastname="LastName1" email="user1@user1.com"
9+
creation="2011-01-27 12:09:02" folder_id="1000" admin="0" hash_alg="sha256" />
10+
<user user_id="2" firstname="FirstName2" lastname="LastName2" email="user2@user2.com"
11+
creation="2011-01-27 12:10:02" admin="0" hash_alg="sha256" />
12+
<user user_id="3" firstname="FirstName3" lastname="LastName3" email="user3@user3.com"
13+
creation="2011-01-27 12:08:02" admin="0" hash_alg="sha256" />
14+
<user user_id="4" firstname="Admin" lastname="Admin" email="admin@admin.com"
15+
creation="2011-01-27 12:11:02" admin="1" hash_alg="sha256" />
1616

1717
<group group_id="3000" community_id="2000" name="Community 1 Admin" />
1818
<group group_id="3001" community_id="2000" name="Community 1 Moderator" />

core/tests/databaseDataset/search.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@
4444
name="Community test User 1 Member" />
4545

4646

47-
<user user_id="1" firstname="Firstname1" lastname="Lastname1"
48-
email="user1@user1.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:09:02"
49-
folder_id="1000" admin="0" />
47+
<user user_id="1" firstname="Firstname1" lastname="Lastname1" email="user1@user1.com" creation="2011-01-27 12:09:02"
48+
folder_id="1000" admin="0" hash_alg="sha256" />
5049

5150
<!-- To test Export component -->
52-
<user user_id="2" firstname="Firstname2" lastname="Lastname2"
53-
email="user2@user2.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:10:02" admin="0" />
51+
<user user_id="2" firstname="Firstname2" lastname="Lastname2" hash_alg="sha256"
52+
email="user2@user2.com" creation="2011-01-27 12:10:02" admin="0" />
5453
<folderpolicygroup folder_id="1001" group_id="0" policy="0" />
5554
<!-- To test admin user capabilities -->
56-
<user user_id="3" firstname="Admin" lastname="Admin"
57-
email="admin@admin.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:11:02" admin="1" />
55+
<user user_id="3" firstname="Admin" lastname="Admin" hash_alg="sha256"
56+
email="admin@admin.com" creation="2011-01-27 12:11:02" admin="1" />
5857

5958
<user2group group_id="3000" user_id="1" />
6059
<user2group group_id="3002" user_id="1" />

modules/api/tests/controllers/ApiCallUserMethodsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public function testUserApikeyDefault()
6868

6969
$this->resetAll();
7070

71-
// Must set the password here since our salt is dynamic
72-
$userDao->setPassword(md5(Zend_Registry::get('configGlobal')->password->prefix.'test'));
71+
$this->User->changePassword($userDao, 'test');
7372
$this->User->save($userDao);
7473

7574
$this->params['method'] = 'midas.user.apikey.default';

modules/api/tests/controllers/ApiKeyControllerTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public function testChangePasswordChangesDefaultApiKey()
3838
$usersFile = $this->loadData('User', 'default');
3939
$userDao = $this->User->load($usersFile[0]->getKey());
4040

41-
// Must set the password here since our salt is dynamic
42-
$userDao->setPassword(md5(Zend_Registry::get('configGlobal')->password->prefix.'test'));
41+
$this->User->changePassword($userDao, 'test');
4342
$this->User->save($userDao);
4443

4544
$userApiModel = MidasLoader::loadModel('Userapi', 'api');
@@ -58,8 +57,6 @@ public function testChangePasswordChangesDefaultApiKey()
5857

5958
$postKey = $userApiModel->getByAppAndUser('Default', $userDao)->getApikey();
6059
$this->assertNotEquals($preKey, $postKey);
61-
$passwordPrefix = Zend_Registry::get('configGlobal')->password->prefix;
62-
$this->assertEquals($postKey, md5($userDao->getEmail().md5($passwordPrefix.'test1').'Default'));
6360
}
6461

6562
/** Make sure adding a new user adds a default api key */
@@ -79,8 +76,7 @@ public function testNewUserGetsDefaultApiKey()
7976
// Check that their default api key was created
8077
$userApiModel = MidasLoader::loadModel('Userapi', 'api');
8178
$key = $userApiModel->getByAppAndEmail('Default', 'some.user@server.com')->getApikey();
82-
$passwordPrefix = Zend_Registry::get('configGlobal')->password->prefix;
83-
$this->assertEquals($key, md5('some.user@server.com'.md5($passwordPrefix.'midas').'Default'));
79+
$this->assertNotEmpty($key);
8480
}
8581

8682
/**
@@ -99,6 +95,6 @@ public function testExistingUsersGetDefaultKeysOnInstall()
9995
$userApiDao = $userApiModel->getByAppAndEmail('Default', 'user1@user1.com');
10096

10197
$this->assertTrue($userApiDao != false, 'Api key was not created for existing user');
102-
$this->assertEquals($userApiDao->getApikey(), md5('user1@user1.com35fd8ba86ba403ffcc00feac5355ad20Default'));
98+
$this->assertNotEmpty($userApiDao->getApikey());
10399
}
104100
}

modules/api/tests/models/base/UserApiModelTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public function setUp()
3333
public function testDefaultApiKeyModel()
3434
{
3535
$userApiModel = MidasLoader::loadModel('Userapi', 'api');
36+
$userModel = MidasLoader::loadModel('User');
3637

37-
$userDao = new UserDao();
38+
$userDao = MidasLoader::newDao('UserDao');
3839
$userDao->setUserId(1);
3940
$userDao->setEmail('user1@user1.com');
40-
$userDao->setPassword('35fd8ba86ba403ffcc00feac5355ad20');
41+
4142
$userApiModel->createDefaultApiKey($userDao);
4243

4344
$dao = $userApiModel->getByAppAndEmail('Default', 'user1@user1.com');
4445
$this->assertTrue($dao instanceof Api_UserapiDao);
45-
$this->assertEquals(md5('user1@user1.com35fd8ba86ba403ffcc00feac5355ad20Default'), $dao->getApikey());
4646
}
4747
}

0 commit comments

Comments
 (0)