diff --git a/tests/Ltb/PpolicyTest.php b/tests/Ltb/PpolicyTest.php index 61cd775..09de6a1 100644 --- a/tests/Ltb/PpolicyTest.php +++ b/tests/Ltb/PpolicyTest.php @@ -253,5 +253,180 @@ public function testCheckEntropyJSON() } + public function test_smarty_assign_variable() + { + + # Password policy array + $pwd_policy_config = array( + "pwd_show_policy" => "always", + "pwd_min_length" => 12, + "pwd_max_length" => 32, + "pwd_min_lower" => 1, + "pwd_min_upper" => 1, + "pwd_min_digit" => 0, + "pwd_min_special" => 0, + "pwd_special_chars" => "^a-zA-Z0-9", + "pwd_forbidden_chars" => null, + "pwd_no_reuse" => true, + "pwd_diff_last_min_chars" => 0, + "pwd_diff_login" => true, + "pwd_complexity" => 3, + "use_pwnedpasswords" => true, + "pwd_no_special_at_ends" => false, + "pwd_forbidden_words" => array("secret","password"), + "pwd_forbidden_ldap_fields" => array(), + "pwd_display_entropy" => true, + "pwd_check_entropy" => true, + "pwd_min_entropy" => 3 + ); + + $smarty = Mockery::mock('Smarty'); + + foreach ($pwd_policy_config as $param => $value) { + if( isset($value) ) + { + // only send password policy parameters + // of type string to smarty template + if( !is_array($value) ) + { + $smarty->shouldreceive('assign') + ->once() + ->with($param, $value); + } + } + } + + \Ltb\Ppolicy::smarty_assign_variable($smarty, $pwd_policy_config); + + $this->assertNotNull($smarty, "smarty variable is null while testing smarty_assign_variable" ); + + } + + public function test_smarty_assign_ppolicy() + { + + # Password policy array + $pwd_policy_config = array( + "pwd_show_policy" => "always", + "pwd_min_length" => 12, + "pwd_max_length" => 32, + "pwd_min_lower" => 1, + "pwd_min_upper" => 1, + "pwd_min_digit" => 0, + "pwd_min_special" => 0, + "pwd_special_chars" => "^a-zA-Z0-9", + "pwd_forbidden_chars" => null, + "pwd_no_reuse" => true, + "pwd_diff_last_min_chars" => 0, + "pwd_diff_login" => true, + "pwd_complexity" => 3, + "use_pwnedpasswords" => true, + "pwd_no_special_at_ends" => false, + "pwd_forbidden_words" => array("secret","password"), + "pwd_forbidden_ldap_fields" => array(), + "pwd_display_entropy" => true, + "pwd_check_entropy" => true, + "pwd_min_entropy" => 3 + ); + + $smarty = Mockery::mock('Smarty'); + $pwd_show_policy_pos = "above"; + $pwd_show_policy = "always"; + $result = ""; + + $smarty->shouldreceive('assign') + ->once() + ->with("pwd_show_policy_pos", $pwd_show_policy_pos ); + $smarty->shouldreceive('assign') + ->once() + ->with("pwd_show_policy", $pwd_show_policy ); + $smarty->shouldreceive('assign') + ->once() + ->with("pwd_show_policy_onerror", true ); + + foreach ($pwd_policy_config as $param => $value) { + if( isset($value) ) + { + // only send password policy parameters + // of type string to smarty template + if( !is_array($value) ) + { + $smarty->shouldreceive('assign') + ->once() + ->with($param, $value); + } + } + } + + $smarty->shouldreceive('assign') + ->once() + ->with("json_policy", base64_encode(json_encode( $pwd_policy_config )) ); + + \Ltb\Ppolicy::smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_policy, $result, $pwd_policy_config); + + $this->assertNotNull($smarty, "smarty variable is null while testing smarty_assign_ppolicy" ); + + } + + public function test_smarty_assign_ppolicy_show_policy_onerror() + { + + $pwd_policy_config = array(); + + $smarty = Mockery::mock('Smarty'); + $pwd_show_policy_pos = "above"; + $pwd_show_policy = "onerror"; + $result = "forbiddenchars"; + + $smarty->shouldreceive('assign') + ->once() + ->with("pwd_show_policy_pos", $pwd_show_policy_pos ); + $smarty->shouldreceive('assign') + ->once() + ->with("pwd_show_policy", $pwd_show_policy ); + $smarty->shouldreceive('assign') + ->twice() + ->with("pwd_show_policy_onerror", true ); + + $smarty->shouldreceive('assign') + ->once() + ->with("json_policy", base64_encode(json_encode( $pwd_policy_config )) ); + + \Ltb\Ppolicy::smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_policy, $result, $pwd_policy_config); + + $this->assertNotNull($smarty, "smarty variable is null while testing smarty_assign_ppolicy" ); + + } + + public function test_smarty_assign_ppolicy_show_policy_onerror_dummy() + { + + $pwd_policy_config = array(); + + $smarty = Mockery::mock('Smarty'); + $pwd_show_policy_pos = "above"; + $pwd_show_policy = "onerror"; + $result = "dummy"; + + $smarty->shouldreceive('assign') + ->once() + ->with("pwd_show_policy_pos", $pwd_show_policy_pos ); + $smarty->shouldreceive('assign') + ->once() + ->with("pwd_show_policy", $pwd_show_policy ); + $smarty->shouldreceive('assign') + ->with("pwd_show_policy_onerror", true ); + $smarty->shouldreceive('assign') + ->with("pwd_show_policy_onerror", false ); + + $smarty->shouldreceive('assign') + ->once() + ->with("json_policy", base64_encode(json_encode( $pwd_policy_config )) ); + + \Ltb\Ppolicy::smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_policy, $result, $pwd_policy_config); + + $this->assertNotNull($smarty, "smarty variable is null while testing smarty_assign_ppolicy" ); + + } }