/** * @covers ::setApiKeyEnabled * @covers ::generateKeysOnNeed */ public function testSetApiKeyEnabled() { $this->assertNull($this->mockUser->getApiKeyPrivate()); $this->assertNull($this->mockUser->getApiKeyPublic()); $this->mockUser->setApiKeyEnabled(true); $privateKey = $this->mockUser->getApiKeyPrivate(); $publicKey = $this->mockUser->getApiKeyPublic(); $this->assertNotNull($privateKey); $this->assertNotNull($publicKey); $this->mockUser->setApiKeyEnabled(false); $this->assertEquals($privateKey, $this->mockUser->getApiKeyPrivate()); $this->assertEquals($publicKey, $this->mockUser->getApiKeyPublic()); }
protected function setUp() { $this->initAutoload(); $this->bbapp = $this->getBBApp(); $this->initDb($this->bbapp); $this->bbapp->start(); // valid user $user = new User(); $user->setLogin('user123'); $user->setEmail('*****@*****.**'); $user->setPassword(md5('password123')); $user->setActivated(true); $this->getEntityManager()->persist($user); $this->getEntityManager()->flush(); $this->controller = $this->getController(); }
/** * Creates a user for the specified group, and authenticates a BBUserToken. * * @param string $groupId * * @return \BackBee\Security\Token\BBUserToken */ protected function createAuthUser($groupId, $roles = array('ROLE_API_USER')) { $token = new BBUserToken($roles); $user = new User(); $user->setEmail('*****@*****.**')->setLogin('admin')->setPassword('pass')->setApiKeyPrivate(uniqid("PRIVATE", true))->setApiKeyPublic(uniqid("PUBLIC", true))->setApiKeyEnabled(true); $group = $this->getBBApp()->getEntityManager()->getRepository('BackBee\\Security\\Group')->findOneBy(array('_name' => $groupId)); if (!$group) { $group = new Group(); $group->setName($groupId); $this->getBBApp()->getEntityManager()->persist($group); $this->getBBApp()->getEntityManager()->flush($group); } $user->addGroup($group); $token->setAuthenticated(true); $token->setUser($user)->setCreated(new \DateTime())->setLifetime(300); $this->getSecurityContext()->setToken($token); return $user; }
/** * @covers ::postAction * @expectedException \Symfony\Component\HttpKernel\Exception\ConflictHttpException * @expectedExceptionMessage User with that login already exists: usernameDuplicate */ public function testPostActionDuplicateLogin() { // set up permissions $aclManager = $this->getBBApp()->getContainer()->get('security.acl_manager'); $aclManager->insertOrUpdateClassAce(new ObjectIdentity('all', get_class($this->user)), UserSecurityIdentity::fromAccount($this->user), MaskBuilder::MASK_CREATE); $controller = $this->getController(); // create user $user = new User(); $user->setLogin('usernameDuplicate')->setEmail('*****@*****.**')->setPassword('password123')->setApiKeyEnabled(false)->setApiKeyPrivate('PRIVATE_KEY')->setApiKeyPublic('PUBLIC_KEY')->setFirstname('FirstName')->setLastname('LastName')->setActivated(true); $this->getBBApp()->getEntityManager()->persist($user); $this->getBBApp()->getEntityManager()->flush(); $response = $controller->postAction(new Request([], ['login' => 'usernameDuplicate', 'email' => '*****@*****.**', 'api_key_enabled' => true, 'api_key_public' => 'api_key_public', 'api_key_private' => 'api_key_private', 'firstname' => 'first_name', 'lastname' => 'last_name', 'activated' => false, 'password' => 'password'])); }
/** * Checks that the user is activated * * @param User $user The user * * @return User * * @throws DisabledException if the user is not activated */ private function checkActivatedStatus(User $user) { if (!$user->isActivated()) { throw new DisabledException(sprintf('Account `%s`is disabled.', $user->getUsername())); } return $user; }