diff --git a/lam/tests/lib/modules/ppolicyUserTest.php b/lam/tests/lib/modules/ppolicyUserTest.php new file mode 100644 index 00000000..0b69f91d --- /dev/null +++ b/lam/tests/lib/modules/ppolicyUserTest.php @@ -0,0 +1,194 @@ +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 => 365 * 3600 * 24, + PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY => 14 * 3600 * 24, + PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY => 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() { + $this->job->method('findUsers')->willReturn(array()); + + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); + + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } + + public function testAccountDoesNotExpire() { + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=noexpire,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY), + 'pwdchangedtime' => array('20000101112233Z') + ))); + + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); + + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } + + public function testAccountLocked() { + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=locked,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), + 'pwdaccountlockedtime' => array('20010101112233Z'), + 'pwdchangedtime' => array('20000101112233Z') + ))); + + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); + + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } + + public function testAccountExpired() { + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=expired,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), + 'pwdchangedtime' => array('20000101112233Z'), + ))); + + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); + + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } + + public function testWarningNotReached() { + $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'), + ))); + + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); + + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } + + public function testAlreadyWarned() { + $now = new DateTime('now', getTimeZone()); + $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'); + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); + + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } + + public function testWarning() { + $now = new DateTime('now', getTimeZone()); + $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'); + $this->job->expects($this->once())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->once())->method('sendMail'); + + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } + + public function testWarningDryRun() { + $now = new DateTime('now', getTimeZone()); + $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'); + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); + + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true); + } + +} + + +?> \ No newline at end of file