FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_common_auth.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
13 require_once(dirname(__FILE__) . '/../common-auth.php');
14 
19 class test_common_auth extends \PHPUnit\Framework\TestCase
20 {
21  /* initialization */
22  protected function setUp() : void
23  {
24  print "Starting unit test for common-auth.php\n";
25  }
26 
31  {
32  $_SERVER['HTTP_SMUNIVERSALID'] = null;
33  $result = siteminder_check();
34  $this->assertEquals("-1", $result );
35  $_SERVER['HTTP_SMUNIVERSALID'] = "Test Siteminder";
36  $result = siteminder_check();
37  $this->assertEquals("Test Siteminder", $result);
38  }
39 
43  protected function tearDown() : void
44  {
45  print "Ending unit test for common-auth.php\n";
46  }
47 
56  {
57  global $SysConf;
58  $SysConf = [];
59  $SysConf['SYSCONFIG'] = [];
60  $SysConf['SYSCONFIG']['PasswdPolicy'] = 'true';
61  $SysConf['SYSCONFIG']['PasswdPolicyMinChar'] = 8;
62  $SysConf['SYSCONFIG']['PasswdPolicyMaxChar'] = 16;
63  $SysConf['SYSCONFIG']['PasswdPolicyLower'] = 'true';
64  $SysConf['SYSCONFIG']['PasswdPolicyUpper'] = 'true';
65  $SysConf['SYSCONFIG']['PasswdPolicyDigit'] = 'true';
66  $SysConf['SYSCONFIG']['PasswdPolicySpecial'] = '#%@^!*()';
67  $expected = '(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[#%@^!*()])[a-zA-Z\\d#%@^!*()]{8,16}';
68  $actual = generate_password_policy();
69  $this->assertEquals($expected, $actual);
70  }
71 
81  {
82  global $SysConf;
83  $SysConf = [];
84  $SysConf['SYSCONFIG'] = [];
85  $SysConf['SYSCONFIG']['PasswdPolicy'] = 'false';
86  $SysConf['SYSCONFIG']['PasswdPolicyMinChar'] = 8;
87  $SysConf['SYSCONFIG']['PasswdPolicyMaxChar'] = 16;
88  $SysConf['SYSCONFIG']['PasswdPolicyLower'] = 'true';
89  $SysConf['SYSCONFIG']['PasswdPolicyUpper'] = 'true';
90  $SysConf['SYSCONFIG']['PasswdPolicyDigit'] = 'true';
91  $SysConf['SYSCONFIG']['PasswdPolicySpecial'] = '#%@^!*()';
92  $expected = '.*';
93  $actual = generate_password_policy();
94  $this->assertEquals($expected, $actual);
95  }
96 
107  {
108  global $SysConf;
109  $SysConf = [];
110  $SysConf['SYSCONFIG'] = [];
111  $SysConf['SYSCONFIG']['PasswdPolicy'] = 'true';
112  $SysConf['SYSCONFIG']['PasswdPolicyMinChar'] = '';
113  $SysConf['SYSCONFIG']['PasswdPolicyMaxChar'] = 16;
114  $SysConf['SYSCONFIG']['PasswdPolicyLower'] = 'true';
115  $SysConf['SYSCONFIG']['PasswdPolicyUpper'] = 'true';
116  $SysConf['SYSCONFIG']['PasswdPolicyDigit'] = 'true';
117  $SysConf['SYSCONFIG']['PasswdPolicySpecial'] = '#%@^!*()';
118  $expected = '(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[#%@^!*()])[a-zA-Z\\d#%@^!*()]{0,16}';
119  $actual = generate_password_policy();
120  $this->assertEquals($expected, $actual);
121  }
122 
133  {
134  global $SysConf;
135  $SysConf = [];
136  $SysConf['SYSCONFIG'] = [];
137  $SysConf['SYSCONFIG']['PasswdPolicy'] = 'true';
138  $SysConf['SYSCONFIG']['PasswdPolicyMinChar'] = 2;
139  $SysConf['SYSCONFIG']['PasswdPolicyMaxChar'] = '';
140  $SysConf['SYSCONFIG']['PasswdPolicyLower'] = 'true';
141  $SysConf['SYSCONFIG']['PasswdPolicyUpper'] = 'true';
142  $SysConf['SYSCONFIG']['PasswdPolicyDigit'] = 'true';
143  $SysConf['SYSCONFIG']['PasswdPolicySpecial'] = '#%@^!*()';
144  $expected = '(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[#%@^!*()])[a-zA-Z\\d#%@^!*()]{2,}';
145  $actual = generate_password_policy();
146  $this->assertEquals($expected, $actual);
147  }
148 
158  {
159  global $SysConf;
160  $SysConf = [];
161  $SysConf['SYSCONFIG'] = [];
162  $SysConf['SYSCONFIG']['PasswdPolicy'] = 'true';
163  $SysConf['SYSCONFIG']['PasswdPolicyMinChar'] = '';
164  $SysConf['SYSCONFIG']['PasswdPolicyMaxChar'] = '';
165  $SysConf['SYSCONFIG']['PasswdPolicyLower'] = 'true';
166  $SysConf['SYSCONFIG']['PasswdPolicyUpper'] = 'true';
167  $SysConf['SYSCONFIG']['PasswdPolicyDigit'] = 'true';
168  $SysConf['SYSCONFIG']['PasswdPolicySpecial'] = '#%@^!*()';
169  $expected = '(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[#%@^!*()])[a-zA-Z\\d#%@^!*()]*';
170  $actual = generate_password_policy();
171  $this->assertEquals($expected, $actual);
172  }
173 
184  {
185  global $SysConf;
186  $SysConf = [];
187  $SysConf['SYSCONFIG'] = [];
188  $SysConf['SYSCONFIG']['PasswdPolicy'] = 'true';
189  $SysConf['SYSCONFIG']['PasswdPolicyMinChar'] = '8';
190  $SysConf['SYSCONFIG']['PasswdPolicyMaxChar'] = '16';
191  $SysConf['SYSCONFIG']['PasswdPolicyLower'] = 'false';
192  $SysConf['SYSCONFIG']['PasswdPolicyUpper'] = 'true';
193  $SysConf['SYSCONFIG']['PasswdPolicyDigit'] = 'true';
194  $SysConf['SYSCONFIG']['PasswdPolicySpecial'] = '';
195  $expected = '(?=.*[A-Z])(?=.*\\d).{8,16}';
196  $actual = generate_password_policy();
197  $this->assertEquals($expected, $actual);
198  }
199 }
test_siteminder_check()
test for siteminder_check()
tearDown()
clean the env
test_generate_password_policy_no_max()
Test for generate_password_policy() when no max limit is set.
test_generate_password_policy_no_special()
Test for generate_password_policy()
test_generate_password_policy_disable()
Test for generate_password_policy() when policy is disabled.
test_generate_password_policy_no_min()
Test for generate_password_policy() when no minimum limit is set.
test_generate_password_policy_no_limit()
Test for generate_password_policy()
test_generate_password_policy_all()
Test for generate_password_policy()
siteminder_check()
Check if SiteMinder is enabled.
Definition: common-auth.php:22
generate_password_policy()