3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2015 Marcin Haba
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 configuration file (settings.conf).
30 class ConfigurationManagerApplicationSettingsTest 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 testSetApplicationConfigPostgreSQL() {
54 $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
55 $testData['db']['type'] = 'pgsql';
56 $testData['db']['name'] = 'my database 123';
57 $testData['db']['login'] = 'admin321';
58 $testData['db']['password'] = 'Str0NgPa$$w0Rd';
59 $testData['db']['ip_addr'] = '127.0.0.1';
60 $testData['db']['port'] = '5433';
61 $testData['db']['path'] = '';
62 $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
63 $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
64 $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/bconsole-{user}.conf';
65 $testData['bconsole']['use_sudo'] = 1;
66 $testData['baculum']['login'] = 'ganiuszka';
67 $testData['baculum']['password'] = 'AnOTHe3Str0n6 Pass W OR d';
68 $testData['baculum']['debug'] = 0;
69 $testData['baculum']['lang'] = 'pl';
70 $resultContent = '[db]
72 name = "my database 123"
74 password = "Str0NgPa$$w0Rd"
80 bin_path = "/usr/local/bacula/sbin/bconsole"
81 cfg_path = "/usr/local/bacula/etc/bconsole.conf"
82 cfg_custom_path = "/etc/bacula/bconsole-{user}.conf"
87 password = "AnOTHe3Str0n6 Pass W OR d"
92 // check if config does not exist
93 $result = self::$application->getModule('configuration')->isApplicationConfig();
94 $this->assertFalse($result);
96 // check saving config
97 self::$application->getModule('configuration')->setApplicationConfig($testData);
98 $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
99 // compare written config with expected string
100 $this->assertEquals($resultContent, $result);
102 // check if config already exists
103 $result = self::$application->getModule('configuration')->isApplicationConfig();
104 $this->assertTrue($result);
106 // check reading config
107 $configRead = self::$application->getModule('configuration')->getApplicationConfig();
108 // compare test data array with read application config as array
109 $this->assertEquals($testData, $configRead);
112 public function testSetApplicationConfigMySQL() {
113 $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
114 $testData['db']['type'] = 'mysql';
115 $testData['db']['name'] = 'mydatabase538';
116 $testData['db']['login'] = 'administrator';
117 $testData['db']['password'] = '#Str0NgPa$##$w0Rd^$#!&#*$@';
118 $testData['db']['ip_addr'] = '192.168.0.4';
119 $testData['db']['port'] = '3306';
120 $testData['db']['path'] = '';
121 $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
122 $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
123 $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/bconsole-{user}.conf';
124 $testData['bconsole']['use_sudo'] = 0;
125 $testData['baculum']['login'] = 'ganiuszka';
126 $testData['baculum']['password'] = 'Str0n6 Pass4W2OR d';
127 $testData['baculum']['debug'] = 1;
128 $testData['baculum']['lang'] = 'en';
129 $resultContent = '[db]
131 name = "mydatabase538"
132 login = "administrator"
133 password = "#Str0NgPa$##$w0Rd^$#!&#*$@"
134 ip_addr = "192.168.0.4"
139 bin_path = "/usr/local/bacula/sbin/bconsole"
140 cfg_path = "/usr/local/bacula/etc/bconsole.conf"
141 cfg_custom_path = "/etc/bacula/bconsole-{user}.conf"
146 password = "Str0n6 Pass4W2OR d"
152 // check if config does not exist
153 $result = self::$application->getModule('configuration')->isApplicationConfig();
154 $this->assertFalse($result);
156 // check saving config
157 self::$application->getModule('configuration')->setApplicationConfig($testData);
158 $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
159 // compare written config with expected string
160 $this->assertEquals($resultContent, $result);
162 // check if config already exists
163 $result = self::$application->getModule('configuration')->isApplicationConfig();
164 $this->assertTrue($result);
166 // check reading config
167 $configRead = self::$application->getModule('configuration')->getApplicationConfig();
168 // compare test data array with read application config as array
169 $this->assertEquals($testData, $configRead);
172 public function testSetApplicationConfigSQLite() {
173 $testData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
174 $testData['db']['type'] = 'sqlite';
175 $testData['db']['name'] = 'bacula';
176 $testData['db']['login'] = 'bacula';
177 $testData['db']['password'] = '';
178 $testData['db']['ip_addr'] = '';
179 $testData['db']['port'] = '';
180 $testData['db']['path'] = '/home/gani/mydatabase.db';
181 $testData['bconsole']['bin_path'] = '/usr/local/bacula/sbin/bconsole';
182 $testData['bconsole']['cfg_path'] = '/usr/local/bacula/etc/bconsole.conf';
183 $testData['bconsole']['cfg_custom_path'] = '/etc/bacula/users/bconsole-{user}.conf';
184 $testData['bconsole']['use_sudo'] = 0;
185 $testData['baculum']['login'] = 'kekeke';
186 $testData['baculum']['password'] = 'kekeke';
187 $testData['baculum']['debug'] = 1;
188 $testData['baculum']['lang'] = 'en';
189 $resultContent = '[db]
196 path = "/home/gani/mydatabase.db"
199 bin_path = "/usr/local/bacula/sbin/bconsole"
200 cfg_path = "/usr/local/bacula/etc/bconsole.conf"
201 cfg_custom_path = "/etc/bacula/users/bconsole-{user}.conf"
211 // check if config does not exist
212 $result = self::$application->getModule('configuration')->isApplicationConfig();
213 $this->assertFalse($result);
215 // check saving config
216 self::$application->getModule('configuration')->setApplicationConfig($testData);
217 $result = file_get_contents(BACULUM_ROOT_DIR . 'protected/Data/settings.conf');
218 // compare written config with expected string
219 $this->assertEquals($resultContent, $result);
221 // check if config already exists
222 $result = self::$application->getModule('configuration')->isApplicationConfig();
223 $this->assertTrue($result);
225 // check reading config
226 $configRead = self::$application->getModule('configuration')->getApplicationConfig();
227 // compare test data array with read application config as array
228 $this->assertEquals($testData, $configRead);