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

Commit 859070f

Browse files
committed
ENH: refs #237. Test: default API key created upon user registration
1 parent 356505c commit 859070f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

modules/api/tests/controllers/ApiKeyControllerTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testChangePasswordChangesDefaultApiKey()
2929
{
3030
$usersFile = $this->loadData('User', 'default');
3131
$userDao = $this->User->load($usersFile[0]->getKey());
32-
32+
3333
$modelLoad = new MIDAS_ModelLoader();
3434
$userApiModel = $modelLoad->loadModel('Userapi', 'api');
3535
$userApiModel->createDefaultApiKey($userDao);
@@ -44,7 +44,7 @@ public function testChangePasswordChangesDefaultApiKey()
4444

4545
$page = $this->webroot.'user/settings';
4646
$this->dispatchUrI($page, $userDao);
47-
47+
4848
$postKey = $userApiModel->getByAppAndUser('Default', $userDao)->getApikey();
4949
$this->assertNotEquals($preKey, $postKey);
5050
$passwordPrefix = Zend_Registry::get('configGlobal')->password->prefix;
@@ -54,5 +54,22 @@ public function testChangePasswordChangesDefaultApiKey()
5454
/** Make sure adding a new user adds a default api key */
5555
public function testNewUserGetsDefaultApiKey()
5656
{
57+
// Register a new user
58+
$this->params['email'] = 'some.user@server.com';
59+
$this->params['password1'] = 'midas';
60+
$this->params['password2'] = 'midas';
61+
$this->params['firstname'] = 'some';
62+
$this->params['lastname'] = 'user';
63+
$this->request->setMethod('POST');
64+
65+
$page = $this->webroot.'user/register';
66+
$this->dispatchUrI($page);
67+
68+
// Check that their default api key was created
69+
$modelLoad = new MIDAS_ModelLoader();
70+
$userApiModel = $modelLoad->loadModel('Userapi', 'api');
71+
$key = $userApiModel->getByAppAndEmail('Default', 'some.user@server.com')->getApikey();
72+
$passwordPrefix = Zend_Registry::get('configGlobal')->password->prefix;
73+
$this->assertEquals($key, md5('some.user@server.com'.md5($passwordPrefix.'midas').'Default'));
5774
}
5875
}

0 commit comments

Comments
 (0)