$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);
+ }
}
?>
$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']]);
+ }
+ }
}
?>