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

Commit 4e2f7c9

Browse files
author
Michael Grauer
committed
BUG: Refs #212. Only admin users allowed on batchmake config page, with tests.
1 parent 10cbbb2 commit 4e2f7c9

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

core/tests/databaseDataset/default.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747

4848
<user user_id="1" firstname="FirstName1" lastname="LastName1"
4949
email="user1@user1.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:09:02"
50-
folder_id="1000" publicfolder_id="1001" privatefolder_id="1002" />
50+
folder_id="1000" publicfolder_id="1001" privatefolder_id="1002" admin="0" />
51+
52+
<user user_id="3" firstname="Admin" lastname="User"
53+
email="admin@user.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:09:02" admin="1" />
5154

5255
<user2group group_id="3000" user_id="1" />
5356
<user2group group_id="3002" user_id="1" />

modules/batchmake/controllers/ConfigController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ protected function createDefaultConfig($currentConfig)
9797
*/
9898
public function indexAction()
9999
{
100+
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
101+
{
102+
throw new Zend_Exception("You should be an administrator");
103+
}
104+
100105
// get all the properties, not just the batchmake config
101106
$fullConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties(null, false);
102107
// now get just the batchmake ones

modules/batchmake/tests/controllers/ConfigControllerTest.php

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ConfigControllerTest extends BatchmakeControllerTest
2525
public function setUp()
2626
{
2727
$this->setupDatabase(array('default'));
28+
$this->_daos = array('User');
2829
$this->_models = array('User');
2930
$this->enabledModules = array('batchmake');
3031
parent::setUp();
@@ -37,10 +38,43 @@ public function setUp()
3738

3839

3940

41+
4042
/** test index action*/
4143
public function testIndexAction()
4244
{
43-
$this->dispatchUrI("/batchmake/config/index");
45+
// first try to bring up the page without logging in, should get an exception
46+
$usersFile = $this->loadData('User', 'default');
47+
$nullUserDao = null;
48+
foreach($usersFile as $userDao)
49+
{
50+
if($userDao->getFirstname() === 'Admin')
51+
{
52+
$adminUserDao = $userDao;
53+
}
54+
else if($userDao->getFirstname() === 'FirstName1')
55+
{
56+
$nonAdminUserDao = $userDao;
57+
}
58+
}
59+
60+
$withException = true;
61+
$page = '/batchmake/config/index';
62+
$this->params = array();
63+
$this->getRequest()->setMethod('GET');
64+
$this->dispatchUrI($page, $nullUserDao, $withException);
65+
66+
// now login with a non-admin account, should get an exception
67+
$this->resetAll();
68+
$this->params = array();
69+
$this->getRequest()->setMethod('GET');
70+
$this->dispatchUrI($page, $nonAdminUserDao, $withException);
71+
72+
// now login with an admin account
73+
$this->resetAll();
74+
$this->params = array();
75+
$this->getRequest()->setMethod('GET');
76+
$this->dispatchUrI($page, $adminUserDao);
77+
4478
$body = $this->getBody();
4579

4680
$this->assertModule("batchmake");
@@ -52,20 +86,6 @@ public function testIndexAction()
5286
}
5387

5488
$this->assertQuery("form#configForm");
55-
$applicationConfig = $this->setupAndGetConfig();
56-
$this->params = array();
57-
$this->params[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY];
58-
$this->params[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY];
59-
$this->params[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
60-
$this->params[MIDAS_BATCHMAKE_APP_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY];
61-
$this->params[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY];
62-
$this->params[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY];
63-
// @TODO get these tests to a better state, testing more
64-
// luckily, almost all of the functionality goes through KWBatchmakeComponent
65-
// which is reasonably well tested
66-
$this->params['submit'] = 'submitConfig';
67-
$this->request->setMethod('POST');
68-
$this->dispatchUrI("/batchmake/config", null, true);
6989
}
7090

7191

0 commit comments

Comments
 (0)