3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 Kern Sibbald
8 * The main author of Baculum is Marcin Haba.
9 * The original author of Bacula is Kern Sibbald, with contributions
10 * from many others, a complete list can be found in the file AUTHORS.
12 * You may use this file and others of this release according to the
13 * license defined in the LICENSE file, which includes the Affero General
14 * Public License, v3.0 ("AGPLv3") and some additional permissions and
15 * terms pursuant to its AGPLv3 Section 7.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 require_once('test_common.php');
26 * Test cases to read/write/check Baculum users file (baculum.users).
30 class ConfigurationManagerUsersConfigTest extends PHPUnit_Framework_TestCase {
32 public static $application = null;
34 public function setUp() {
35 if (self::$application === null) {
36 self::$application = new TApplicationTest(BACULUM_ROOT_DIR . 'protected');
37 self::$application->run();
39 if (file_exists(BACULUM_ROOT_DIR . 'protected/Data')) {
40 copy_path(BACULUM_ROOT_DIR . 'protected/Data', BACKUP_FILES_PATH);
41 remove_path(BACULUM_ROOT_DIR . 'protected/Data', true);
45 public function tearDown() {
46 if (file_exists(BACKUP_FILES_PATH)) {
47 remove_path(BACKUP_FILES_PATH . 'protected/Data', true);
48 copy_path(BACKUP_FILES_PATH, BACULUM_ROOT_DIR . 'protected/Data');
49 remove_path(BACKUP_FILES_PATH);
53 public function testSetUsersConfig() {
55 $testData[] = array( // create new user admin432
58 'password' => 'myStrOnGPa$$!',
62 'result' => 'admin432:bXOrb7VkxRBYY'
64 $testData[] = array( // add user willyWonka to config
66 'user' => 'willyWonka',
67 'password' => '#=ChOcOlAtEE=#',
68 'firstusage' => false,
71 'result' => "admin432:bXOrb7VkxRBYY\nwillyWonka:IzGy5zT.vOaeI"
73 $testData[] = array( // clear users config and create user willyWonka again
75 'user' => 'willyWonka',
76 'password' => '#=ChOcOlAtEE=#',
80 'result' => "willyWonka:IzGy5zT.vOaeI"
82 $testData[] = array( // add user donkamillo to config
84 'user' => 'donkamillo',
85 'password' => '!@#$%^&*()_+}{|"\'<>?/.,',
86 'firstusage' => false,
89 'result' => "willyWonka:IzGy5zT.vOaeI\ndonkamillo:IU029IHEUYWhY"
91 $testData[] = array( // rename user willyWonka to user johny11
94 'password' => '#=ChOcOlAtEE=#',
95 'firstusage' => false,
96 'olduser' => 'willyWonka'
98 'result' => "donkamillo:IU029IHEUYWhY\njohny11:IzGy5zT.vOaeI"
100 $testData[] = array( // change password for user johny11
103 'password' => 'CoffeeAndTee!@#$%^&*()_+}{|"\'<>?/.:,',
104 'firstusage' => false,
107 'result' => "donkamillo:IU029IHEUYWhY\njohny11:Q2XfKovUGQe52"
109 $testData[] = array( // input the same password again for user johny11
112 'password' => 'CoffeeAndTee!@#$%^&*()_+}{|"\'<>?/.:,',
113 'firstusage' => false,
116 'result' => "donkamillo:IU029IHEUYWhY\njohny11:Q2XfKovUGQe52"
118 for ($i = 0; $i < count($testData); $i++) {
119 $result = self::$application->getModule('configuration')->setUsersConfig(
120 $testData[$i]['data']['user'],
121 $testData[$i]['data']['password'],
122 $testData[$i]['data']['firstusage'],
123 $testData[$i]['data']['olduser']
125 $this->assertTrue($result);
126 $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/baculum.users');
127 $this->assertEquals($testData[$i]['result'], $result);
131 public function testCheckAndClearUsersConfig() {
132 $testData[] = array( // input the same password again for user johny11
135 'password' => 'CoffeeAndTee!@#$%^&*()_+}{|"\'<>?/.:,',
136 'firstusage' => false,
139 'result' => "johny11:Q2XfKovUGQe52"
141 $result = self::$application->getModule('configuration')->isUsersConfig();
142 $this->assertFalse($result);
143 for ($i = 0; $i < count($testData); $i++) {
144 $result = self::$application->getModule('configuration')->setUsersConfig(
145 $testData[$i]['data']['user'],
146 $testData[$i]['data']['password'],
147 $testData[$i]['data']['firstusage'],
148 $testData[$i]['data']['olduser']
150 $this->assertTrue($result);
151 $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/baculum.users');
152 $this->assertEquals($testData[$i]['result'], $result);
154 $result = self::$application->getModule('configuration')->isUsersConfig();
155 $this->assertTrue($result);
156 $result = self::$application->getModule('configuration')->clearUsersConfig();
157 $this->assertTrue($result);
160 public function testGetAllUsers() {
163 'user' => 'hmS2Tbx4VispuvjgRcDPIqadG3ylkn9AELeo1FYQCHWKOZw8N6J5MfBtX7rUz',
164 'password' => 'enEzofZKX2/wM'
167 'user' => 'hmS2Tbx4VispuvjgRcDPIqadG3ylkn9AELeo1FYQCHWKOZw8N6J5MfBtX7rUz$',
168 'password' => 'xbe9m5cgdFzc2'
171 'user' => 'ąśźćłóżźćń',
172 'password' => 'ąśźćłóżźćń'
176 'password' => 'enEzofZK!X2/wM'
180 'password' => '!@#$%^&*()_)O(*&^%$#@@!}{PO|":L?><M~><][\';/.,<'
183 'user' => '(myUsEr$^)',
184 'password' => ':::::'
187 'user' => 'abcd#$@!',
188 'password' => 'MzfDL89YPyQeM'
191 'user' => '^$$#@@!!!:-)',
192 'password' => 'PTwuUMPFz/0PE'
195 // check if config does not exist
196 $result = self::$application->getModule('configuration')->isUsersConfig();
197 $this->assertFalse($result);
199 // add users to config
200 for ($i = 0; $i < count($testData); $i++) {
201 $result = self::$application->getModule('configuration')->setUsersConfig(
202 $testData[$i]['user'],
203 $testData[$i]['password']
205 $this->assertTrue($result);
208 // read users from config
209 $result = self::$application->getModule('configuration')->getAllUsers();
211 $this->assertEquals(count($testData), count($result));
214 * Check if users (and passwords) added to config and users (and passwords) read from
215 * config are the same
217 for ($i = 0; $i < count($result); $i++) {
218 $user = $testData[$i]['user'];
219 $plain_pwd = $testData[$i]['password'];
220 $this->assertTrue(array_key_exists($user, $result));
221 $enc_pwd = self::$application->getModule('configuration')->getCryptedPassword($plain_pwd);
222 $this->assertEquals($enc_pwd, $result[$testData[$i]['user']]);