コード例 #1
0
 public function testPassword()
 {
     $hash = new BasicHashService();
     $password = '******';
     $doc = new PasswordTraitDoc();
     $doc->setPassword($password);
     $this->documentManager->persist($doc);
     $this->documentManager->flush();
     $this->assertNotEquals($password, $doc->getPassword());
     $this->assertEquals($doc->getPassword(), $hash->hashValue($password, $doc->getSalt()));
     $this->assertNotEquals($doc->getPassword(), $hash->hashValue('not password', $doc->getSalt()));
     $newPassword = '******';
     $doc->setPassword($newPassword);
     $this->documentManager->flush();
     $this->assertNotEquals($newPassword, $doc->getPassword());
     $this->assertEquals($doc->getPassword(), $hash->hashValue($newPassword, $doc->getSalt()));
     $this->assertNotEquals($doc->getPassword(), $hash->hashValue($password, $doc->getSalt()));
 }
コード例 #2
0
 public function testChangePasswordWithUsername()
 {
     //first create the token
     $accept = new Accept();
     $accept->addMediaType('application/json');
     $this->getRequest()->setMethod(Request::METHOD_POST)->setContent('{"username": "******"}')->getHeaders()->addHeaders([$accept, ContentType::fromString('Content-type: application/json')]);
     $this->dispatch('/rest/recoverpasswordtoken');
     $response = $this->getResponse();
     $result = json_decode($response->getContent(), true);
     $this->assertFalse(isset($result));
     $this->assertResponseStatusCode(201);
     $this->assertFalse($response->getHeaders()->has('Location'));
     //check the email
     $this->assertTrue(file_exists(__DIR__ . '/../../../../email/test_mail.tmp'));
     //second, use the code in the email to change the password
     $text = file_get_contents(__DIR__ . '/../../../../email/test_mail.tmp');
     preg_match('/\\/rest\\/recoverpasswordtoken\\/[a-zA-Z0-9]+/', $text, $match);
     $accept = new Accept();
     $accept->addMediaType('application/json');
     $this->getRequest()->setMethod(Request::METHOD_PUT)->setContent('{"password": "******"}')->getHeaders()->addHeaders([$accept, ContentType::fromString('Content-type: application/json')]);
     $this->dispatch($match[0]);
     $response = $this->getResponse();
     $result = json_decode($response->getContent(), true);
     $this->assertFalse(isset($result));
     $this->assertResponseStatusCode(204);
     //add sys user
     $sysUser = new User();
     $sysUser->addRole('sys::authenticate');
     $this->shardServiceLocator->setAllowOverride(true);
     $this->shardServiceLocator->setService('user', $sysUser);
     $user = $this->documentManager->getRepository('Zoop\\GomiModule\\DataModel\\User')->findOneBy(['username' => 'toby']);
     $basicHashService = new BasicHashService();
     $this->assertTrue($basicHashService->hashValue('newPassword2', $user->getSalt()) == $user->getPassword());
 }