Inheritance: use trait Webiny\Component\StdLib\SingletonTrait, use trait Webiny\Component\StdLib\StdLibTrait
Exemple #1
0
 /**
  * Get application web path.
  *
  * @return string
  */
 public function getWebPath()
 {
     $webPath = $this->environment->getCurrentEnvironmentConfig()->get('Domain', false);
     if (!$webPath) {
         $webPath = Request::getInstance()->getCurrentUrl(true)->getDomain() . '/';
     }
     return $webPath;
 }
 public function testGetInstance()
 {
     TwitterOAuth::setConfig(realpath(__DIR__ . '/ExampleConfig.yaml'));
     Request::getInstance()->setCurrentUrl('http://admin.w3.com/batman-is-better-than-superman/?batman=one&superman=two');
     // other tests might change the library, which can cause this test to fail
     Bridge::setLibrary('\\Webiny\\Component\\TwitterOAuth\\Bridge\\League\\TwitterOAuth');
     $instance = TwitterOAuthLoader::getInstance('MyTwitterApp');
     $this->assertInstanceOf('\\Webiny\\Component\\TwitterOAuth\\TwitterOAuth', $instance);
 }
 public function testIsUserAllowedAccessDecisionStrategyAffirmative()
 {
     // lets mock the address to one that doesn't match any rules
     Request::getInstance()->setCurrentUrl('http://admin.w3.com/about/');
     $user = new UserMock();
     $user->populate('test', 'test', [new Role('ROLE_MOCK')], true);
     $config = new ConfigObject(['DecisionStrategy' => 'affirmative', 'Rules' => [['Path' => '/^\\/about/', 'Roles' => 'ROLE_GOD']]]);
     $instance = new AccessControl($user, $config);
     $this->assertTrue($instance->isUserAllowedAccess());
 }
Exemple #4
0
 public function testGetLoginObjectValidState()
 {
     Request::deleteInstance();
     Session::getInstance()->save('oauth_token', '123');
     Session::getInstance()->save('oauth_state', 'state-id');
     $_GET['code'] = 'some code';
     $_GET['state'] = 'state-id';
     $oauth2 = new OAuth2('Facebook', ['ROLE_ADMIN']);
     $oauth2->setExitTrigger(OAuth2::EXIT_TRIGGER_EXCEPTION);
     $result = $oauth2->getLoginObject(new ConfigObject([]));
     $this->assertInstanceOf('\\Webiny\\Component\\Security\\Authentication\\Providers\\Login', $result);
 }
Exemple #5
0
 /**
  * @runInSeparateProcess
  */
 public function testTriggerLogin()
 {
     Request::deleteInstance();
     // mock server vars
     $_SERVER = ['PHP_AUTH_USER' => 'name', 'PHP_AUTH_PW' => 'pass'];
     Request::getInstance()->setCurrentUrl('http://admin.w3.com/login');
     $http = new Http();
     $http->setExitTrigger('exception');
     $c = new ConfigObject([]);
     $http->triggerLogin($c);
     $this->assertSame('name', Session::getInstance()->get('username'));
     $this->assertSame('pass', Session::getInstance()->get('password'));
 }
Exemple #6
0
 public function testGetLoginObject()
 {
     Request::deleteInstance();
     // mock POST
     $_POST = ['username' => 'un', 'password' => 'pw', 'rememberme' => 'yes'];
     $form = new Form();
     $c = new ConfigObject([]);
     $login = $form->getLoginObject($c);
     $this->assertInstanceOf('\\Webiny\\Component\\Security\\Authentication\\Providers\\Login', $login);
     $this->assertSame('un', $login->getUsername());
     $this->assertSame('pw', $login->getPassword());
     $this->assertSame('yes', $login->getRememberMe());
 }
Exemple #7
0
 public function setUp()
 {
     Request::getInstance()->setCurrentUrl('http://www.myapp.com/');
 }
Exemple #8
0
 public function setUp()
 {
     Router::getInstance()->prependRoutes(Config::getInstance()->yaml(__DIR__ . '/ExampleConfig.yaml')->get('Router.Routes'));
     Request::getInstance()->setCurrentUrl('http://www.webiny.com/');
 }
Exemple #9
0
 /**
  * @param Firewall $firewall
  *
  * @dataProvider firewallProvider
  */
 public function testIsUserDeniedAccessOnAddressThatIsInsideAccessRules($firewall)
 {
     $firewall->processLogin('MockProvider');
     // let's authenticate the user
     Request::getInstance()->setCurrentUrl('http://admin.w3.com/about/');
     $result = $firewall->isUserAllowedAccess();
     $this->assertFalse($result);
 }
Exemple #10
0
 /**
  * Return all query filters
  *
  * @return mixed
  */
 protected static function restGetFilters()
 {
     return Request::getInstance()->query();
 }
Exemple #11
0
 /**
  * Get Request component instance.
  *
  * @return Request
  */
 protected static function httpRequest()
 {
     return Request::getInstance();
 }
<?php

require_once 'vendor/autoload.php';
$_SERVER['SERVER_NAME'] = 'www.webiny.com';
$geoProvider = new \Webiny\GeoIp\Provider\MaxMindGeoLite2\MaxMindGeoLite2(__DIR__ . '/test-config.yaml');
$geoIp = new \Webiny\GeoIp\GeoIp($geoProvider);
$mongo = new \Webiny\Component\Mongo\Mongo('127.0.0.1:27017', 'LoginFoo');
$a = new \Webiny\AnalyticsDb\AnalyticsDb($mongo);
$wa = new \Webiny\WebsiteAnalytics\WebsiteAnalytics($a, $geoIp);
$userAgents = ['Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7', 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0', 'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/45.0.2454.101 Chrome/45.0.2454.101 Safari/537.36', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3', 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1'];
$ipList = ['23.92.128.123', '46.188.128.31', '82.112.64.231', '62.85.64.131', '196.200.48.121', '5.77.64.21', '14.139.0.12', '46.23.160.21', '101.98.0.213', '5.10.144.101'];
for ($i = 0; $i <= 100000; $i++) {
    $page = '/page-' . rand(100, 1000) . '/';
    $_SERVER['REQUEST_URI'] = $page;
    \Webiny\Component\Http\Request::getInstance()->setCurrentUrl('http://www.webiny.com' . $page);
    $ua = $userAgents[array_rand($userAgents)];
    $ip = $ipList[array_rand($ipList)];
    $wa->setUserAgent($ua);
    $wa->setIp($ip);
    $time = time() - rand(0, 365) * 86400;
    $wa->setTimestamp($time);
    $wa->saveStats();
    if (rand(1, 10) == 5) {
        $wa->deleteSession();
    }
}
Exemple #13
0
 public function testGetTrustedHeaders()
 {
     $thAssert = ['client_ip' => 'X_FORWARDED_FOR', 'client_host' => 'X_FORWARDED_HOST', 'client_proto' => 'X_FORWARDED_PROTO', 'client_port' => 'X_FORWARDED_PORT'];
     $trustedHeaders = Request::getInstance()->getTrustedHeaders();
     $this->assertSame($thAssert, $trustedHeaders);
 }
 public function dataProvider()
 {
     OAuth2::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
     Request::getInstance()->setCurrentUrl('http://admin.w3.com/batman-is-better-than-superman/?batman=one&superman=two');
     $oauth2Instance = OAuth2Loader::getInstance('Facebook');
     $oauth2Request = new OAuth2Request($oauth2Instance);
     return [[$oauth2Request]];
 }