Exemple #1
0
 public function testVoteAccessDenied()
 {
     $user = new UserMock();
     $user->populate("test", "test", [new Role('ROLE_MOCK')], true);
     $voter = new RoleVoter();
     $this->assertSame(RoleVoter::ACCESS_DENIED, $voter->vote($user, [new Role('ROLE_ADMIN')]));
 }
 public function testVoteAccessDenied()
 {
     $user = new UserMock();
     $user->populate("test", "test", [], false);
     $voter = new AuthenticationVoter();
     $this->assertSame(AuthenticationVoter::ACCESS_DENIED, $voter->vote($user, []));
 }
 /**
  * Get the user from user provided for the given instance of Login object.
  *
  * @param Login $login Instance of Login object.
  *
  * @return UserAbstract
  * @throws UserNotFoundException
  */
 public function getUser(Login $login)
 {
     if (self::$returnLoginObject) {
         $user = new UserMock();
         $user->populate($login->getUsername(), $login->getPassword(), ['ROLE_MOCK'], false);
         return $user;
     }
     return false;
 }
 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());
 }
 public function testDecryptUserData()
 {
     \Webiny\Component\Crypt\Crypt::setConfig(__DIR__ . '/CryptDrivers/Crypt/CryptExampleConfig.yaml');
     $user = new UserMock();
     $user->populate('uname', 'pwd', [new Role('ROLE_MOCK')], false);
     $crypt = new TokenCryptMock(new ConfigObject([]));
     $instance = new TokenStorageMock();
     $instance->setCrypt($crypt);
     $result = $instance->encryptUserData($user);
     $tokenData = $instance->decryptUserData($result);
     $this->assertInstanceOf('\\Webiny\\Component\\Security\\Token\\TokenData', $tokenData);
     $this->assertSame('uname', $tokenData->getUsername());
 }