]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Tweak add rest unit tests to configuration manager
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 1 Jan 2016 08:53:16 +0000 (09:53 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Fri, 1 Jan 2016 11:39:18 +0000 (12:39 +0100)
gui/baculum/tests/units/Class/ConfigurationManagerTest.php
gui/baculum/tests/units/Class/ConfigurationManagerUsersConfigTest.php

index 05cece2110ea0542788f873c62831ed061f29c37..43b1d1fd414097321684033d7ee3db04e2cfc7db 100644 (file)
@@ -108,6 +108,54 @@ class ConfigurationManagerTest extends PHPUnit_Framework_TestCase {
                $result = $mock->getLanguage();
                $this->assertEquals($testData, $result);
        }
+
+       public function testGetCryptedPassword() {
+               $testData = array();
+               $testData[] = array('password' => 'zzzzzzzzz', 'hash' => 'enEzofZKX2/wM');
+               $testData[] = array('password' => 'admin', 'hash' => 'YWG41BPzVAkN6');
+               $testData[] = array('password' => 'a dmin', 'hash' => 'YSz/JgtyVAHuc');
+               $testData[] = array('password' => 'a', 'hash' => 'YQebj.HAzzu1c');
+               $testData[] = array('password' => 'ADMIN', 'hash' => 'QUtX9W0NVx75o');
+               $testData[] = array('password' => ' ', 'hash' => 'IAeLKSsdm161I');
+               $testData[] = array('password' => 'a b c', 'hash' => 'YSMYQTGUwHPTE');
+               $testData[] = array('password' => 'ąśćłóżźćń', 'hash' => 'xIObay0jyQnD2');
+               $testData[] = array('password' => '$$$$', 'hash' => 'JCgedtNc0KHRw');
+               $testData[] = array('password' => '\$$\$$', 'hash' => 'XCFJMFspzHfN6');
+               $testData[] = array('password' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'hash' => 'MD.GrjSxikZ26');
+               $testData[] = array('password' => "\t\n\t\r", 'hash' => 'CQUexWT5q3vHc');
+               $testData[] = array('password' => '\t\n\t\r', 'hash' => 'XHACZ9CpS6KIw');
+               $testData[] = array('password' => '$a=1;print $a;', 'hash' => 'JGr9Nl2UPwz1Y');
+
+               for ($i = 0; $i < count($testData); $i++) {
+                       $result = self::$application->getModule('configuration')->getCryptedPassword($testData[$i]['password']);
+                       $this->assertEquals($testData[$i]['hash'], $result);
+               }
+       }
+
+       public function testGetRandomString() {
+               $testData = array(
+                       'iterations' => 50,
+                       'pattern' => '/^[a-zA-Z0-9]{62}$/',
+                       'characters' => "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+               );
+               for ($i = 0; $i < $testData['iterations']; $i++) {
+                       $str = self::$application->getModule('configuration')->getRandomString();
+                       $result = preg_match($testData['pattern'], $str);
+                       $this->assertEquals(1, $result);
+               }
+
+               $charactersCopy = $testData['characters'];
+               $str = self::$application->getModule('configuration')->getRandomString();
+               for ($i = 0; $i < strlen($testData['characters']); $i++) {
+                       $pos = strpos($str, $charactersCopy[$i]);
+                       $len = strlen($str);
+                       $str_l = substr($str, 0, $pos);
+                       $str_r = ($len > 1) ? substr($str, ($pos+1), $len) : '';
+                       $str = $str_l . $str_r;
+               }
+               $result = empty($str);
+               $this->assertTrue($result);
+       }
 }
 
 ?>
index 69ac8f8f58aef1dd34a03e885c8d9873a7bdc172..d94519f8b259f6d2ebfc01f8bb70ebbc2201ebbe 100644 (file)
@@ -156,5 +156,71 @@ class ConfigurationManagerUsersConfigTest extends PHPUnit_Framework_TestCase {
                $result = self::$application->getModule('configuration')->clearUsersConfig();
                $this->assertTrue($result);
        }
+
+       public function testGetAllUsers() {
+               $testData = array();
+               $testData[] = array(
+                       'user' => 'hmS2Tbx4VispuvjgRcDPIqadG3ylkn9AELeo1FYQCHWKOZw8N6J5MfBtX7rUz',
+                       'password' => 'enEzofZKX2/wM'
+               );
+               $testData[] = array(
+                       'user' => 'hmS2Tbx4VispuvjgRcDPIqadG3ylkn9AELeo1FYQCHWKOZw8N6J5MfBtX7rUz$',
+                       'password' => 'xbe9m5cgdFzc2'
+               );
+               $testData[] = array(
+                       'user' => 'ąśźćłóżźćń',
+                       'password' => 'ąśźćłóżźćń'
+               );
+               $testData[] = array(
+                       'user' => '0',
+                       'password' => 'enEzofZK!X2/wM'
+               );
+               $testData[] = array(
+                       'user' => '-1-',
+                       'password' => '!@#$%^&*()_)O(*&^%$#@@!}{PO|":L?><M~><][\';/.,<'
+               );
+               $testData[] = array(
+                       'user' => '(myUsEr$^)',
+                       'password' => ':::::'
+               );
+               $testData[] = array(
+                       'user' => 'abcd#$@!',
+                       'password' => 'MzfDL89YPyQeM'
+               );
+               $testData[] = array(
+                       'user' => '^$$#@@!!!:-)',
+                       'password' => 'PTwuUMPFz/0PE'
+               );
+
+               // check if config does not exist
+               $result = self::$application->getModule('configuration')->isUsersConfig();
+               $this->assertFalse($result);
+
+               // add users to config
+               for ($i = 0; $i < count($testData); $i++) {
+                       $result = self::$application->getModule('configuration')->setUsersConfig(
+                               $testData[$i]['user'],
+                               $testData[$i]['password']
+                       );
+                       $this->assertTrue($result);
+               }
+
+               // read users from config
+               $result = self::$application->getModule('configuration')->getAllUsers();
+
+               $this->assertEquals(count($testData), count($result));
+
+               /*
+                * Check if users (and passwords) added to config and users (and passwords) read from
+                * config are the same
+                */
+               for ($i = 0; $i < count($result); $i++) {
+                       $user = $testData[$i]['user'];
+                       $plain_pwd = $testData[$i]['password'];
+                       $this->assertTrue(array_key_exists($user, $result));
+                       $enc_pwd = self::$application->getModule('configuration')->getCryptedPassword($plain_pwd);
+                       $this->assertEquals($enc_pwd, $result[$testData[$i]['user']]);
+               }
+       }
 }
 ?>