This event listener lets you control the access to the /stats endpoint by white-/blacklisting ip addresses or subnets (using CIDR notation). If you disable the listener from the configuration it will be open to anyone (and it does not require an access token by default).
Author: Christer Edvartsen (cogo@starzinger.net)
Inheritance: implements Imbo\EventListener\ListenerInterface
Example #1
0
 /**
  * @see https://github.com/imbo/imbo/issues/251
  *
  * This test is best run with "In the Ghetto" blasting on the stereo
  */
 public function testHasHigherPriorityThanTheStatsResource()
 {
     $statsAccess = new StatsAccess();
     $statsResource = new StatsResource();
     $eventManager = new EventManager();
     $eventManager->addEventHandler('statsAccess', $statsAccess);
     $eventManager->addCallbacks('statsAccess', StatsAccess::getSubscribedEvents());
     $eventManager->addEventHandler('statsResource', $statsResource);
     $eventManager->addCallbacks('statsResource', StatsResource::getSubscribedEvents());
     $callbacks = new ReflectionProperty($eventManager, 'callbacks');
     $callbacks->setAccessible(true);
     $handlersForGet = $callbacks->getValue($eventManager)['stats.get'];
     $handlersForHead = $callbacks->getValue($eventManager)['stats.head'];
     $this->assertSame($statsAccess, $eventManager->getHandlerInstance($handlersForGet->extract()['handler']));
     $this->assertSame($statsResource, $eventManager->getHandlerInstance($handlersForGet->extract()['handler']));
     $this->assertSame($statsAccess, $eventManager->getHandlerInstance($handlersForHead->extract()['handler']));
     $this->assertSame($statsResource, $eventManager->getHandlerInstance($handlersForHead->extract()['handler']));
 }