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->resultLog = new \LAM\JOB\JobResultLog(); $this->assertFalse($this->resultLog->hasError()); } 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, $this->resultLog); $this->assertFalse($this->resultLog->hasError()); } 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, $this->resultLog); $this->assertFalse($this->resultLog->hasError()); } 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, $this->resultLog); $this->assertFalse($this->resultLog->hasError()); } 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, $this->resultLog); $this->assertFalse($this->resultLog->hasError()); } 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, $this->resultLog); $this->assertFalse($this->resultLog->hasError()); } 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, $this->resultLog); $this->assertFalse($this->resultLog->hasError()); } 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, $this->resultLog); $this->assertFalse($this->resultLog->hasError()); } 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, $this->resultLog); $this->assertFalse($this->resultLog->hasError()); } public function testGetWarningTimeInSeconds() { $confDays = 7; $policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); $this->assertEquals((7*3600*24 + 10000), $seconds); $confDays = 0; $policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); $this->assertEquals(10000, $seconds); $confDays = 7; $policy = array('pwdmaxage' => 365 * 3600 * 24); $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); $this->assertEquals(7*3600*24, $seconds); } } } ?>