public function getAuth($attempts)
 {
     $auth = new Auth();
     $lim = new CookieLoginLimitPlugin($attempts);
     $success = new SuccessPlugin();
     $auth->addPlugin($success);
     $auth->addPlugin($lim);
     return $auth;
 }
 protected function getAuth($attempts)
 {
     $auth = new Auth();
     $fakemc = new FakeMemcache();
     $fakemc->flush();
     $mclim = new MemcacheLoginLimitPlugin($fakemc, $attempts);
     $mclim->setRemoteAddr('localhost');
     $success = new SuccessPlugin();
     $auth->addPlugin($success);
     $auth->addPlugin($mclim);
     return $auth;
 }
Exemplo n.º 3
0
 public function testEdgeCases()
 {
     $test = new TestPlugin();
     $this->auth->addPlugin($test);
     $test->setResult(new SplFixedArray());
     // This isn't a valid result.
     try {
         $this->auth->login('u', 'p');
         $this->fail("An invalid result should have triggered an AuthException");
     } catch (AuthException $e) {
         // Expected
     }
     $this->setUp();
     $this->assertTrue($this->auth->addPlugin('Vectorface\\Auth\\Plugin\\SuccessPlugin'));
     $this->auth->addPlugin($test);
     $test->setResult(new Exception("Exception added on purpose by test case."));
     // Causes a log entry and failure.
     $this->assertFalse($this->auth->verify());
     $test->setResult(new AuthException());
     try {
         $this->auth->verify();
         $this->fail("Expected AuthException to be passed up.");
     } catch (AuthException $e) {
         // Expected
     }
     /* Loading by class name should work. */
     $this->assertTrue($this->auth->addPlugin('Vectorface\\Auth\\Plugin\\SuccessPlugin'));
     $this->assertFalse($this->auth->addPlugin(new SplFixedArray()));
     // Fails for obvious reasons.
 }
Exemplo n.º 4
0
 public function testLogging()
 {
     $logfile = sys_get_temp_dir() . '/LoggerTest';
     $test = new TestPlugin();
     $auth = new Auth();
     $auth->addPlugin($test);
     $globalLogger = new Logger('GlobalLogger');
     $globalLogger->pushHandler(new StreamHandler($logfile, Logger::WARNING));
     $internalLogger = new Logger('InternalLogger');
     $internalLogger->pushHandler(new StreamHandler($logfile, Logger::WARNING));
     $auth->setLogger($globalLogger);
     $this->assertEquals($globalLogger, $auth->getLogger());
     /* It can use the global logger... */
     $this->assertFalse(@file_get_contents($logfile));
     $auth->testWarning("Logger Test!");
     $this->assertTrue(strpos(@file_get_contents($logfile), "Logger Test!") !== false);
     $this->assertTrue(strpos(@file_get_contents($logfile), "GlobalLogger") !== false);
     @unlink($logfile);
     /* ... Or its own logger! */
     $this->assertFalse(@file_get_contents($logfile));
     $test->setLogger($internalLogger);
     $auth->testWarning("Logger Test!");
     $this->assertTrue(strpos(@file_get_contents($logfile), "Logger Test!") !== false);
     $this->assertTrue(strpos(@file_get_contents($logfile), "InternalLogger") !== false);
     @unlink($logfile);
 }