/**
  * @expectedException MWException
  * @covers WebRequest::getIP
  */
 public function testGetIpLackOfRemoteAddrThrowAnException()
 {
     // ensure that local install state doesn't interfere with test
     $this->setMwGlobals(array('wgSquidServersNoPurge' => array(), 'wgSquidServers' => array(), 'wgUsePrivateIPs' => false, 'wgHooks' => array()));
     $request = new WebRequest();
     # Next call throw an exception about lacking an IP
     $request->getIP();
 }
Exemple #2
0
 /**
  * Roughly increments the cache misses in the last hour by unique visitors
  * @param WebRequest $request
  * @return void
  */
 public function incrMissesRecent(WebRequest $request)
 {
     if (mt_rand(0, self::MISS_FACTOR - 1) == 0) {
         $cache = ObjectCache::getLocalClusterInstance();
         # Get a large IP range that should include the user  even if that
         # person's IP address changes
         $ip = $request->getIP();
         if (!IP::isValid($ip)) {
             return;
         }
         $ip = IP::isIPv6($ip) ? IP::sanitizeRange("{$ip}/32") : IP::sanitizeRange("{$ip}/16");
         # Bail out if a request already came from this range...
         $key = wfMemcKey(get_class($this), 'attempt', $this->mType, $this->mKey, $ip);
         if ($cache->get($key)) {
             return;
             // possibly the same user
         }
         $cache->set($key, 1, self::MISS_TTL_SEC);
         # Increment the number of cache misses...
         $key = $this->cacheMissKey();
         if ($cache->get($key) === false) {
             $cache->set($key, 1, self::MISS_TTL_SEC);
         } else {
             $cache->incr($key);
         }
     }
 }
 /**
  * Test against the passed WebRequest
  * @param WebRequest $request
  * @return Status
  */
 public function check(WebRequest $request)
 {
     $ok = ['ip' => $this->checkIP($request->getIP())];
     $status = Status::newGood();
     $status->setResult($ok === array_filter($ok), $ok);
     return $status;
 }
 /**
  * @expectedException MWException
  */
 function testGetIpLackOfRemoteAddrThrowAnException()
 {
     $request = new WebRequest();
     # Next call throw an exception about lacking an IP
     $request->getIP();
 }