Beispiel #1
0
 public function __construct()
 {
     $crudServiceProvider = TestDBSetup::createServiceProvider(false);
     $dataUser = $crudServiceProvider->getData('user');
     $this->userEntity = $dataUser->createEmpty();
     $this->userEntity->set('username', 'username');
     $this->userEntity->set('password', 'password');
     $this->userEntity->set('salt', 'salt');
 }
 public function testResetPassword()
 {
     $passwordReset = new PasswordReset($this->dataUser, $this->dataPasswordReset);
     $app = TestDBSetup::createAppAndDB(false);
     $user = $this->dataUser->createEmpty();
     $user->set('username', 'user2');
     $user->set('password', 'asdasd');
     $user->set('email', '*****@*****.**');
     $this->dataUser->create($user);
     $hash = $user->get('password');
     $salt = $user->get('salt');
     $encoder = new BCryptPasswordEncoder(13);
     $this->assertTrue($encoder->isPasswordValid($hash, 'asdasd', $salt));
     $token = $passwordReset->requestPasswordReset('email', '*****@*****.**');
     $read = $passwordReset->resetPassword('asdasd', 'dsadsa');
     $this->assertFalse($read);
     $read = $passwordReset->resetPassword('', 'dsadsa');
     $this->assertFalse($read);
     $read = $passwordReset->resetPassword(null, 'dsadsa');
     $this->assertFalse($read);
     $read = $passwordReset->resetPassword($token, 'dsadsa');
     $this->assertTrue($read);
     $updatedUser = $this->dataUser->get($user->get('id'));
     $newHash = $updatedUser->get('password');
     $this->assertTrue($encoder->isPasswordValid($newHash, 'dsadsa', $salt));
     // A token can be only used once
     $read = $passwordReset->resetPassword($token, 'dsadsa');
     $this->assertFalse($read);
     // A password reset must be used within 48h
     $token = $passwordReset->requestPasswordReset('email', '*****@*****.**');
     $passwordResets = $this->dataPasswordReset->listEntries(['token' => $token]);
     if (count($passwordResets) !== 1) {
         $this->fail();
     }
     $oldCreatedAt = gmdate('Y-m-d H:i:s', time() - 3 * 24 * 60 * 60);
     $app['db']->executeUpdate('UPDATE password_reset SET created_at = ? WHERE token = ?', [$oldCreatedAt, $token]);
     $read = $passwordReset->resetPassword($token, 'dsadsa');
     $this->assertFalse($read);
 }
 public function testRolesViaManyToMany()
 {
     $crudServiceProvider = TestDBSetup::createServiceProvider(true);
     $this->dataUser = $crudServiceProvider->getData('user');
     $userProvider = new UserProvider($this->dataUser, 'user_role');
     $role = $this->dataRole->createEmpty();
     $role->set('role', 'ROLE_TEST');
     $this->dataRole->create($role);
     $expected = 'user1';
     $user = $this->dataUser->createEmpty();
     $user->set('username', $expected);
     $user->set('password', 'asdasd');
     $user->set('email', '*****@*****.**');
     $user->set('user_role', [['id' => $role->get('id')]]);
     $this->dataUser->create($user);
     $userRead = $userProvider->loadUserByUsername($expected);
     $read = $userRead->getUsername();
     $this->assertSame($read, $expected);
     $read = $userRead->getRoles();
     $expected = ['ROLE_USER', 'ROLE_TEST'];
     $this->assertSame($read, $expected);
 }
Beispiel #4
0
 protected function setUp()
 {
     $crudServiceProvider = TestDBSetup::createServiceProvider(false);
     $this->dataUser = $crudServiceProvider->getData('user');
 }