Пример #1
0
 /**
  * Testing the registerFilter method with a bad filter object.
  *
  * @since 1.0
  */
 public function testRegisterFilterBad()
 {
     try {
         $_SERVER['REQUEST_URI'] = '/';
         $front = new FrontController();
         $front->registerFilter(new FrontController());
         $this->fail('testing the registerFilter method with a bad filter object');
     } catch (IllegalArguementException $e) {
         $this->assertEquals('Supplied filter object is not a valid FilterInterface instance!', $e->getMessage(), 'testing the registerFilter method with a bad filter object');
     }
 }
Пример #2
0
use Alpha\Util\Config\ConfigProvider;
use Alpha\Util\Http\Filter\ClientBlacklistFilter;
use Alpha\Util\Http\Filter\IPBlacklistFilter;
use Alpha\Util\Http\Filter\ClientTempBlacklistFilter;
use Alpha\Util\Http\Request;
use Alpha\Util\Http\Response;
use Alpha\Exception\ResourceNotFoundException;
use Alpha\Exception\ResourceNotAllowedException;
use Alpha\View\View;
try {
    $config = ConfigProvider::getInstance();
    set_exception_handler('Alpha\\Util\\ErrorHandlers::catchException');
    set_error_handler('Alpha\\Util\\ErrorHandlers::catchError', $config->get('php.error.log.level'));
    $front = new FrontController();
    if ($config->get('security.client.blacklist.filter.enabled')) {
        $front->registerFilter(new ClientBlacklistFilter());
    }
    if ($config->get('security.ip.blacklist.filter.enabled')) {
        $front->registerFilter(new IPBlacklistFilter());
    }
    if ($config->get('security.client.temp.blacklist.filter.enabled')) {
        $front->registerFilter(new ClientTempBlacklistFilter());
    }
    $request = new Request();
    $response = $front->process($request);
} catch (ResourceNotFoundException $rnfe) {
    $response = new Response(404, View::renderErrorPage(404, $rnfe->getMessage(), array('Content-Type' => 'text/html')));
} catch (ResourceNotAllowedException $rnae) {
    $response = new Response(403, View::renderErrorPage(403, $rnae->getMessage(), array('Content-Type' => 'text/html')));
}
if ($config->get('security.http.header.x.frame.options') != '' && $response->getHeader('X-Frame-Options') == null) {
Пример #3
0
 /**
  * Testing that a blacklisted IP cannot pass the IPBlacklistFilter filter.
  *
  * @since 1.2.3
  */
 public function testIPBlacklistFilter()
 {
     $_SERVER['REMOTE_ADDR'] = $this->badIP;
     $_SERVER['REQUEST_URI'] = '/';
     $request = new Request(array('method' => 'GET'));
     try {
         $front = new FrontController();
         $front->registerFilter(new IPBlacklistFilter());
         $front->process($request);
         $this->fail('Testing that a blacklisted IP cannot pass the IPBlacklistFilter filter');
     } catch (ResourceNotAllowedException $e) {
         $this->assertEquals('Not allowed!', $e->getMessage(), 'Testing that a blacklisted IP cannot pass the IPBlacklistFilter filter');
     }
 }