check if tests can be run
This commit is contained in:
parent
39fdc3e5d2
commit
4417e5aff7
|
@ -21,200 +21,203 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once 'lam/lib/baseModule.inc';
|
if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
|
||||||
include_once 'lam/lib/modules.inc';
|
|
||||||
include_once 'lam/lib/passwordExpirationJob.inc';
|
|
||||||
include_once 'lam/lib/modules/ppolicyUser.inc';
|
|
||||||
|
|
||||||
/**
|
include_once 'lam/lib/baseModule.inc';
|
||||||
* Checks the ppolicy expire job.
|
include_once 'lam/lib/modules.inc';
|
||||||
*
|
include_once 'lam/lib/passwordExpirationJob.inc';
|
||||||
* @author Roland Gruber
|
include_once 'lam/lib/modules/ppolicyUser.inc';
|
||||||
*
|
|
||||||
*/
|
|
||||||
class PPolicyUserPasswordNotifyJobTest extends PHPUnit_Framework_TestCase {
|
|
||||||
|
|
||||||
private $job;
|
/**
|
||||||
|
* Checks the ppolicy expire job.
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class PPolicyUserPasswordNotifyJobTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
const JOB_ID = 'jobID';
|
private $job;
|
||||||
const WARNING = '14';
|
|
||||||
const DEFAULT_POLICY = 'cn=default,dc=test';
|
|
||||||
const NOEXPIRE_POLICY = 'cn=noexpire,dc=test';
|
|
||||||
const ONE_YEAR_POLICY = 'cn=policy1,dc=test';
|
|
||||||
|
|
||||||
private $options = array();
|
const JOB_ID = 'jobID';
|
||||||
|
const WARNING = '14';
|
||||||
|
const DEFAULT_POLICY = 'cn=default,dc=test';
|
||||||
|
const NOEXPIRE_POLICY = 'cn=noexpire,dc=test';
|
||||||
|
const ONE_YEAR_POLICY = 'cn=policy1,dc=test';
|
||||||
|
|
||||||
public function setUp() {
|
private $options = array();
|
||||||
$this->job = $this->getMockBuilder('PPolicyPasswordNotifyJob')
|
|
||||||
->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail',
|
|
||||||
'findUsers', 'getConfigPrefix', 'getPolicyOptions'))
|
|
||||||
->getMock();
|
|
||||||
$this->job->method('getConfigPrefix')->willReturn('test');
|
|
||||||
$this->job->method('sendMail')->willReturn(true);
|
|
||||||
$this->job->method('getPolicyOptions')->willReturn(array(
|
|
||||||
PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY => array('pwdmaxage' => 365 * 3600 * 24),
|
|
||||||
PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY => array('pwdmaxage' => 14 * 3600 * 24),
|
|
||||||
PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY => array('pwdmaxage' => 0),
|
|
||||||
));
|
|
||||||
$this->options['test_mailNotificationPeriod' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::WARNING;
|
|
||||||
$this->options['test_mailDefaultPolicy' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNoAccounts() {
|
public function setUp() {
|
||||||
$this->job->method('findUsers')->willReturn(array());
|
$this->job = $this->getMockBuilder('PPolicyPasswordNotifyJob')
|
||||||
|
->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail',
|
||||||
|
'findUsers', 'getConfigPrefix', 'getPolicyOptions'))
|
||||||
|
->getMock();
|
||||||
|
$this->job->method('getConfigPrefix')->willReturn('test');
|
||||||
|
$this->job->method('sendMail')->willReturn(true);
|
||||||
|
$this->job->method('getPolicyOptions')->willReturn(array(
|
||||||
|
PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY => array('pwdmaxage' => 365 * 3600 * 24),
|
||||||
|
PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY => array('pwdmaxage' => 14 * 3600 * 24),
|
||||||
|
PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY => array('pwdmaxage' => 0),
|
||||||
|
));
|
||||||
|
$this->options['test_mailNotificationPeriod' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::WARNING;
|
||||||
|
$this->options['test_mailDefaultPolicy' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY;
|
||||||
|
}
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testNoAccounts() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$this->job->method('findUsers')->willReturn(array());
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testAccountDoesNotExpire() {
|
$pdo = array();
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
'dn' => 'cn=noexpire,dc=dn',
|
}
|
||||||
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY),
|
|
||||||
'pwdchangedtime' => array('20000101112233Z')
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testAccountDoesNotExpire() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=noexpire,dc=dn',
|
||||||
|
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY),
|
||||||
|
'pwdchangedtime' => array('20000101112233Z')
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testAccountLocked() {
|
$pdo = array();
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
'dn' => 'cn=locked,dc=dn',
|
}
|
||||||
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
|
||||||
'pwdaccountlockedtime' => array('20010101112233Z'),
|
|
||||||
'pwdchangedtime' => array('20000101112233Z')
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testAccountLocked() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=locked,dc=dn',
|
||||||
|
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
||||||
|
'pwdaccountlockedtime' => array('20010101112233Z'),
|
||||||
|
'pwdchangedtime' => array('20000101112233Z')
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testAccountExpired() {
|
$pdo = array();
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
'dn' => 'cn=expired,dc=dn',
|
}
|
||||||
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
|
||||||
'pwdchangedtime' => array('20000101112233Z'),
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testAccountExpired() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=expired,dc=dn',
|
||||||
|
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
||||||
|
'pwdchangedtime' => array('20000101112233Z'),
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testWarningNotReached() {
|
$pdo = array();
|
||||||
$now = new DateTime('now', getTimeZone());
|
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
$lastChangeNow = floor($now->format('U')/3600/24);
|
}
|
||||||
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
|
|
||||||
$date = new DateTime('now', new DateTimeZone('UTC'));
|
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
|
||||||
'dn' => 'cn=notReached,dc=dn',
|
|
||||||
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
|
||||||
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'),
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testWarningNotReached() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$now = new DateTime('now', getTimeZone());
|
||||||
|
$lastChangeNow = floor($now->format('U')/3600/24);
|
||||||
|
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
|
||||||
|
$date = new DateTime('now', new DateTimeZone('UTC'));
|
||||||
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=notReached,dc=dn',
|
||||||
|
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
||||||
|
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'),
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testAlreadyWarned() {
|
$pdo = array();
|
||||||
$now = new DateTime('now', getTimeZone());
|
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
$date = new DateTime('now', new DateTimeZone('UTC'));
|
}
|
||||||
$date->sub(new DateInterval('P360D'));
|
|
||||||
$this->job->method('getDBLastPwdChangeTime')->willReturn($date->format('YmdHis') . 'Z');
|
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
|
||||||
'dn' => 'cn=alreadyWarned,dc=dn',
|
|
||||||
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
|
||||||
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'),
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
public function testAlreadyWarned() {
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
$now = new DateTime('now', getTimeZone());
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$date = new DateTime('now', new DateTimeZone('UTC'));
|
||||||
|
$date->sub(new DateInterval('P360D'));
|
||||||
|
$this->job->method('getDBLastPwdChangeTime')->willReturn($date->format('YmdHis') . 'Z');
|
||||||
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=alreadyWarned,dc=dn',
|
||||||
|
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
||||||
|
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'),
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
||||||
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
}
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
|
|
||||||
public function testWarning() {
|
$pdo = array();
|
||||||
$now = new DateTime('now', getTimeZone());
|
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
$date = new DateTime('now', new DateTimeZone('UTC'));
|
}
|
||||||
$date->sub(new DateInterval('P360D'));
|
|
||||||
$this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z');
|
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
|
||||||
'dn' => 'cn=alreadyWarned,dc=dn',
|
|
||||||
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
|
||||||
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'),
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
public function testWarning() {
|
||||||
$this->job->expects($this->once())->method('setDBLastPwdChangeTime');
|
$now = new DateTime('now', getTimeZone());
|
||||||
$this->job->expects($this->once())->method('sendMail');
|
$date = new DateTime('now', new DateTimeZone('UTC'));
|
||||||
|
$date->sub(new DateInterval('P360D'));
|
||||||
|
$this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z');
|
||||||
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=alreadyWarned,dc=dn',
|
||||||
|
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
||||||
|
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'),
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
||||||
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->once())->method('setDBLastPwdChangeTime');
|
||||||
}
|
$this->job->expects($this->once())->method('sendMail');
|
||||||
|
|
||||||
public function testWarningDryRun() {
|
$pdo = array();
|
||||||
$now = new DateTime('now', getTimeZone());
|
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
$date = new DateTime('now', new DateTimeZone('UTC'));
|
}
|
||||||
$date->sub(new DateInterval('P360D'));
|
|
||||||
$this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z');
|
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
|
||||||
'dn' => 'cn=alreadyWarned,dc=dn',
|
|
||||||
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
|
||||||
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'),
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
public function testWarningDryRun() {
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
$now = new DateTime('now', getTimeZone());
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$date = new DateTime('now', new DateTimeZone('UTC'));
|
||||||
|
$date->sub(new DateInterval('P360D'));
|
||||||
|
$this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z');
|
||||||
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=alreadyWarned,dc=dn',
|
||||||
|
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY),
|
||||||
|
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'),
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
||||||
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true);
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
}
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
|
|
||||||
public function testGetWarningTimeInSeconds() {
|
$pdo = array();
|
||||||
$confDays = 7;
|
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true);
|
||||||
$policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000);
|
}
|
||||||
|
|
||||||
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
|
public function testGetWarningTimeInSeconds() {
|
||||||
|
$confDays = 7;
|
||||||
|
$policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000);
|
||||||
|
|
||||||
$this->assertEquals((7*3600*24 + 10000), $seconds);
|
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
|
||||||
|
|
||||||
|
$this->assertEquals((7*3600*24 + 10000), $seconds);
|
||||||
|
|
||||||
|
|
||||||
$confDays = 0;
|
$confDays = 0;
|
||||||
$policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000);
|
$policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000);
|
||||||
|
|
||||||
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
|
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
|
||||||
|
|
||||||
$this->assertEquals(10000, $seconds);
|
$this->assertEquals(10000, $seconds);
|
||||||
|
|
||||||
|
|
||||||
$confDays = 7;
|
$confDays = 7;
|
||||||
$policy = array('pwdmaxage' => 365 * 3600 * 24);
|
$policy = array('pwdmaxage' => 365 * 3600 * 24);
|
||||||
|
|
||||||
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
|
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
|
||||||
|
|
||||||
$this->assertEquals(7*3600*24, $seconds);
|
$this->assertEquals(7*3600*24, $seconds);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
include_once 'lam/lib/baseModule.inc';
|
include_once 'lam/lib/baseModule.inc';
|
||||||
include_once 'lam/lib/modules.inc';
|
include_once 'lam/lib/modules.inc';
|
||||||
include_once 'lam/lib/passwordExpirationJob.inc';
|
|
||||||
include_once 'lam/lib/modules/sambaSamAccount.inc';
|
include_once 'lam/lib/modules/sambaSamAccount.inc';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,145 +21,148 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once 'lam/lib/baseModule.inc';
|
if (is_readable('lam/lib/passwordExpirationJob.inc')) {
|
||||||
include_once 'lam/lib/modules.inc';
|
|
||||||
include_once 'lam/lib/passwordExpirationJob.inc';
|
|
||||||
include_once 'lam/lib/modules/shadowAccount.inc';
|
|
||||||
|
|
||||||
/**
|
include_once 'lam/lib/baseModule.inc';
|
||||||
* Checks the shadow expire job.
|
include_once 'lam/lib/modules.inc';
|
||||||
*
|
include_once 'lam/lib/passwordExpirationJob.inc';
|
||||||
* @author Roland Gruber
|
include_once 'lam/lib/modules/shadowAccount.inc';
|
||||||
*
|
|
||||||
*/
|
|
||||||
class ShadowAccountPasswordNotifyJobTest extends PHPUnit_Framework_TestCase {
|
|
||||||
|
|
||||||
private $job;
|
/**
|
||||||
|
* Checks the shadow expire job.
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class ShadowAccountPasswordNotifyJobTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
const JOB_ID = 'jobID';
|
private $job;
|
||||||
const WARNING = '14';
|
|
||||||
|
|
||||||
private $options = array();
|
const JOB_ID = 'jobID';
|
||||||
|
const WARNING = '14';
|
||||||
|
|
||||||
public function setUp() {
|
private $options = array();
|
||||||
$this->job = $this->getMockBuilder('ShadowAccountPasswordNotifyJob')
|
|
||||||
->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', 'findUsers', 'getConfigPrefix'))
|
|
||||||
->getMock();
|
|
||||||
$this->job->method('getConfigPrefix')->willReturn('test');
|
|
||||||
$this->job->method('sendMail')->willReturn(true);
|
|
||||||
$this->options['test_mailNotificationPeriod' . ShadowAccountPasswordNotifyJobTest::JOB_ID][0] = ShadowAccountPasswordNotifyJobTest::WARNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNoAccounts() {
|
public function setUp() {
|
||||||
$this->job->method('findUsers')->willReturn(array());
|
$this->job = $this->getMockBuilder('ShadowAccountPasswordNotifyJob')
|
||||||
|
->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', 'findUsers', 'getConfigPrefix'))
|
||||||
|
->getMock();
|
||||||
|
$this->job->method('getConfigPrefix')->willReturn('test');
|
||||||
|
$this->job->method('sendMail')->willReturn(true);
|
||||||
|
$this->options['test_mailNotificationPeriod' . ShadowAccountPasswordNotifyJobTest::JOB_ID][0] = ShadowAccountPasswordNotifyJobTest::WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testNoAccounts() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$this->job->method('findUsers')->willReturn(array());
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testAccountDoesNotExpire() {
|
$pdo = array();
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
'dn' => 'cn=some,dc=dn',
|
}
|
||||||
'shadowmax' => array('0'),
|
|
||||||
'shadowlastchange' => array('1')
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testAccountDoesNotExpire() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=some,dc=dn',
|
||||||
|
'shadowmax' => array('0'),
|
||||||
|
'shadowlastchange' => array('1')
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testAccountExpired() {
|
$pdo = array();
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
'dn' => 'cn=some,dc=dn',
|
}
|
||||||
'shadowmax' => array('10'),
|
|
||||||
'shadowlastchange' => array('1')
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testAccountExpired() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=some,dc=dn',
|
||||||
|
'shadowmax' => array('10'),
|
||||||
|
'shadowlastchange' => array('1')
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testWarningNotReached() {
|
$pdo = array();
|
||||||
$now = new DateTime('now', getTimeZone());
|
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
$lastChangeNow = floor($now->format('U')/3600/24);
|
}
|
||||||
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
|
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
|
||||||
'dn' => 'cn=some,dc=dn',
|
|
||||||
'shadowmax' => array('300'),
|
|
||||||
'shadowlastchange' => array($lastChangeNow)
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
public function testWarningNotReached() {
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$now = new DateTime('now', getTimeZone());
|
||||||
|
$lastChangeNow = floor($now->format('U')/3600/24);
|
||||||
|
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
|
||||||
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=some,dc=dn',
|
||||||
|
'shadowmax' => array('300'),
|
||||||
|
'shadowlastchange' => array($lastChangeNow)
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
}
|
|
||||||
|
|
||||||
public function testAlreadyWarned() {
|
$pdo = array();
|
||||||
$now = new DateTime('now', getTimeZone());
|
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
$lastChangeNow = floor($now->format('U')/3600/24);
|
}
|
||||||
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
|
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
|
||||||
'dn' => 'cn=some,dc=dn',
|
|
||||||
'shadowmax' => array('10'),
|
|
||||||
'shadowlastchange' => array($lastChangeNow)
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
public function testAlreadyWarned() {
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
$now = new DateTime('now', getTimeZone());
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$lastChangeNow = floor($now->format('U')/3600/24);
|
||||||
|
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
|
||||||
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=some,dc=dn',
|
||||||
|
'shadowmax' => array('10'),
|
||||||
|
'shadowlastchange' => array($lastChangeNow)
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
||||||
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
}
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
|
|
||||||
public function testWarning() {
|
$pdo = array();
|
||||||
$now = new DateTime('now', getTimeZone());
|
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
$lastChangeNow = floor($now->format('U')/3600/24);
|
}
|
||||||
$this->job->method('getDBLastPwdChangeTime')->willReturn('1');
|
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
|
||||||
'dn' => 'cn=some,dc=dn',
|
|
||||||
'shadowmax' => array('10'),
|
|
||||||
'shadowlastchange' => array($lastChangeNow)
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
public function testWarning() {
|
||||||
$this->job->expects($this->once())->method('setDBLastPwdChangeTime');
|
$now = new DateTime('now', getTimeZone());
|
||||||
$this->job->expects($this->once())->method('sendMail');
|
$lastChangeNow = floor($now->format('U')/3600/24);
|
||||||
|
$this->job->method('getDBLastPwdChangeTime')->willReturn('1');
|
||||||
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=some,dc=dn',
|
||||||
|
'shadowmax' => array('10'),
|
||||||
|
'shadowlastchange' => array($lastChangeNow)
|
||||||
|
)));
|
||||||
|
|
||||||
$pdo = array();
|
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
||||||
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
$this->job->expects($this->once())->method('setDBLastPwdChangeTime');
|
||||||
}
|
$this->job->expects($this->once())->method('sendMail');
|
||||||
|
|
||||||
public function testWarningDryRun() {
|
$pdo = array();
|
||||||
$now = new DateTime('now', getTimeZone());
|
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false);
|
||||||
$lastChangeNow = floor($now->format('U')/3600/24);
|
}
|
||||||
$this->job->method('getDBLastPwdChangeTime')->willReturn('1');
|
|
||||||
$this->job->method('findUsers')->willReturn(array(array(
|
|
||||||
'dn' => 'cn=some,dc=dn',
|
|
||||||
'shadowmax' => array('10'),
|
|
||||||
'shadowlastchange' => array($lastChangeNow)
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
public function testWarningDryRun() {
|
||||||
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
$now = new DateTime('now', getTimeZone());
|
||||||
$this->job->expects($this->never())->method('sendMail');
|
$lastChangeNow = floor($now->format('U')/3600/24);
|
||||||
|
$this->job->method('getDBLastPwdChangeTime')->willReturn('1');
|
||||||
|
$this->job->method('findUsers')->willReturn(array(array(
|
||||||
|
'dn' => 'cn=some,dc=dn',
|
||||||
|
'shadowmax' => array('10'),
|
||||||
|
'shadowlastchange' => array($lastChangeNow)
|
||||||
|
)));
|
||||||
|
|
||||||
|
$this->job->expects($this->once())->method('getDBLastPwdChangeTime');
|
||||||
|
$this->job->expects($this->never())->method('setDBLastPwdChangeTime');
|
||||||
|
$this->job->expects($this->never())->method('sendMail');
|
||||||
|
|
||||||
|
$pdo = array();
|
||||||
|
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true);
|
||||||
|
}
|
||||||
|
|
||||||
$pdo = array();
|
|
||||||
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -3,7 +3,7 @@
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
Copyright (C) 2014 Roland Gruber
|
Copyright (C) 2014 - 2016 Roland Gruber
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,59 +21,63 @@ $Id$
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once 'lam/lib/baseModule.inc';
|
if (is_readable('lam/lib/modules/sudoRole.inc')) {
|
||||||
include_once 'lam/lib/modules/sudoRole.inc';
|
|
||||||
|
|
||||||
/**
|
include_once 'lam/lib/baseModule.inc';
|
||||||
* Checks sudo role functions.
|
include_once 'lam/lib/modules/sudoRole.inc';
|
||||||
*
|
|
||||||
* @author Roland Gruber
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class SudoRoleTest extends PHPUnit_Framework_TestCase {
|
|
||||||
|
|
||||||
public function testIsValidDate() {
|
/**
|
||||||
$valid = array('22.10.2014', '05.01.2013', '1.3.2014', '10.5.2014', '4.12.2015',
|
* Checks sudo role functions.
|
||||||
'05.01.2013 22:15', '1.3.2014 5:1', '10.5.2014 13:3', '4.12.2015 5:22');
|
*
|
||||||
foreach ($valid as $testDate) {
|
* @author Roland Gruber
|
||||||
$this->assertTrue(sudoRole::isValidDate($testDate));
|
*
|
||||||
}
|
*/
|
||||||
$invalid = array('10.25.2014', 'abc', '2014-10-12', '10.022014', '10:12', '22.10.2014 12');
|
class SudoRoleTest extends PHPUnit_Framework_TestCase {
|
||||||
foreach ($invalid as $testDate) {
|
|
||||||
$this->assertNotTrue(sudoRole::isValidDate($testDate), $testDate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testEncodeDate() {
|
public function testIsValidDate() {
|
||||||
$dates = array(
|
$valid = array('22.10.2014', '05.01.2013', '1.3.2014', '10.5.2014', '4.12.2015',
|
||||||
'1.2.2014' => '20140201000000Z',
|
'05.01.2013 22:15', '1.3.2014 5:1', '10.5.2014 13:3', '4.12.2015 5:22');
|
||||||
'10.2.2014' => '20140210000000Z',
|
foreach ($valid as $testDate) {
|
||||||
'1.11.2014' => '20141101000000Z',
|
$this->assertTrue(sudoRole::isValidDate($testDate));
|
||||||
'20.12.2014' => '20141220000000Z',
|
}
|
||||||
'1.2.2014 1:2' => '20140201010200Z',
|
$invalid = array('10.25.2014', 'abc', '2014-10-12', '10.022014', '10:12', '22.10.2014 12');
|
||||||
'10.2.2014 1:10' => '20140210011000Z',
|
foreach ($invalid as $testDate) {
|
||||||
'1.11.2014 10:2' => '20141101100200Z',
|
$this->assertNotTrue(sudoRole::isValidDate($testDate), $testDate);
|
||||||
'20.12.2014 10:12' => '20141220101200Z',
|
}
|
||||||
);
|
|
||||||
foreach ($dates as $input => $output) {
|
|
||||||
$this->assertEquals($output, sudoRole::encodeDate($input), $input . ' ' . $output);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function testDecodeDate() {
|
public function testEncodeDate() {
|
||||||
$dates = array(
|
$dates = array(
|
||||||
'01.02.2014 00:00' => '20140201000000Z',
|
'1.2.2014' => '20140201000000Z',
|
||||||
'10.02.2014 00:00' => '20140210000000Z',
|
'10.2.2014' => '20140210000000Z',
|
||||||
'01.11.2014 00:00' => '20141101000000Z',
|
'1.11.2014' => '20141101000000Z',
|
||||||
'20.12.2014 00:00' => '20141220000000Z',
|
'20.12.2014' => '20141220000000Z',
|
||||||
'01.02.2014 01:02' => '20140201010200Z',
|
'1.2.2014 1:2' => '20140201010200Z',
|
||||||
'10.02.2014 01:10' => '20140210011000Z',
|
'10.2.2014 1:10' => '20140210011000Z',
|
||||||
'01.11.2014 10:02' => '20141101100200Z',
|
'1.11.2014 10:2' => '20141101100200Z',
|
||||||
'20.12.2014 10:12' => '20141220101200Z',
|
'20.12.2014 10:12' => '20141220101200Z',
|
||||||
);
|
);
|
||||||
foreach ($dates as $output => $input) {
|
foreach ($dates as $input => $output) {
|
||||||
$this->assertEquals($output, sudoRole::decodeDate($input), $input . ' ' . $output);
|
$this->assertEquals($output, sudoRole::encodeDate($input), $input . ' ' . $output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDecodeDate() {
|
||||||
|
$dates = array(
|
||||||
|
'01.02.2014 00:00' => '20140201000000Z',
|
||||||
|
'10.02.2014 00:00' => '20140210000000Z',
|
||||||
|
'01.11.2014 00:00' => '20141101000000Z',
|
||||||
|
'20.12.2014 00:00' => '20141220000000Z',
|
||||||
|
'01.02.2014 01:02' => '20140201010200Z',
|
||||||
|
'10.02.2014 01:10' => '20140210011000Z',
|
||||||
|
'01.11.2014 10:02' => '20141101100200Z',
|
||||||
|
'20.12.2014 10:12' => '20141220101200Z',
|
||||||
|
);
|
||||||
|
foreach ($dates as $output => $input) {
|
||||||
|
$this->assertEquals($output, sudoRole::decodeDate($input), $input . ' ' . $output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue