/** * testClientProperties method * * @return void */ public function testClientProperties() { $request = $this->getMock('CakeRequest'); $request->expects($this->once())->method('referer'); $request->expects($this->once())->method('clientIp')->will($this->returnValue(false)); $this->RequestHandler->request = $request; $this->RequestHandler->getReferer(); $this->RequestHandler->getClientIP(false); }
/** * testClientProperties method * * @access public * @return void */ function testClientProperties() { $_SERVER['HTTP_HOST'] = 'localhost:80'; $this->assertEqual($this->RequestHandler->getReferer(), 'localhost'); $_SERVER['HTTP_HOST'] = null; $_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org'; $this->assertEqual($this->RequestHandler->getReferer(), 'cakephp.org'); $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.1.5, 10.0.1.1, proxy.com'; $_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2'; $_SERVER['REMOTE_ADDR'] = '192.168.1.3'; $this->assertEqual($this->RequestHandler->getClientIP(false), '192.168.1.5'); $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2'); unset($_SERVER['HTTP_X_FORWARDED_FOR']); $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2'); unset($_SERVER['HTTP_CLIENT_IP']); $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.3'); $_SERVER['HTTP_CLIENTADDRESS'] = '10.0.1.2, 10.0.1.1'; $this->assertEqual($this->RequestHandler->getClientIP(), '10.0.1.2'); }
/** * logs attempts * @param bool errorsOnly (only if error occured, otherwise always) * @returns null if not logged, true otherwise * 2009-12-18 ms */ private function logAttempt($errorsOnly = true) { if ($errorsOnly === true && empty($this->error) && empty($this->internalError)) { return null; } App::import('Component', 'RequestHandler'); $msg = 'Ip \'' . RequestHandlerComponent::getClientIP() . '\', Agent \'' . env('HTTP_USER_AGENT') . '\', Referer \'' . env('HTTP_REFERER') . '\', Host-Referer \'' . RequestHandlerComponent::getReferer() . '\''; if (!empty($this->error)) { $msg .= ', ' . $this->error; } if (!empty($this->internalError)) { $msg .= ' (' . $this->internalError . ')'; } $this->log($msg, 'captcha'); return true; }