Inheritance: extends PartKeepr\CoreBundle\Entity\BaseEntity, implements Symfony\Component\Security\Core\User\UserInterface, implements Symfony\Component\Security\Core\User\EquatableInterface
Example #1
0
 public function testSelfChangeUserPassword()
 {
     $builtinProvider = $this->getContainer()->get('partkeepr.userservice')->getBuiltinProvider();
     $user = new User('bernd2');
     $user->setPassword(md5('admin'));
     $user->setLegacy(true);
     $user->setProvider($builtinProvider);
     $this->getContainer()->get('doctrine.orm.default_entity_manager')->persist($user);
     $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($user);
     $client = static::makeClient(false, ['PHP_AUTH_USER' => 'bernd2', 'PHP_AUTH_PW' => 'admin']);
     $iriConverter = $this->getContainer()->get('api.iri_converter');
     $iri = $iriConverter->getIriFromItem($user) . '/changePassword';
     $parameters = ['oldpassword' => 'admin', 'newpassword' => 'foobar'];
     $client->request('PUT', $iri, $parameters);
     $response = json_decode($client->getResponse()->getContent());
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $this->assertFalse($response->{'legacy'});
     $this->assertEmpty($response->{'password'});
     $this->assertEmpty($response->{'newPassword'});
     $client = static::makeClient(false, ['PHP_AUTH_USER' => 'bernd2', 'PHP_AUTH_PW' => 'foobar']);
     $client->request('PUT', $iri, $parameters);
     $response = json_decode($client->getResponse()->getContent());
     $this->assertEquals(500, $client->getResponse()->getStatusCode());
     $this->assertObjectHasAttribute('@type', $response);
     $this->assertEquals('Error', $response->{'@type'});
 }
Example #2
0
 public function testSelfChangeUserPassword()
 {
     $builtinProvider = $this->getContainer()->get("partkeepr.userservice")->getBuiltinProvider();
     $user = new User("bernd2");
     $user->setPassword(md5("admin"));
     $user->setLegacy(true);
     $user->setProvider($builtinProvider);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->persist($user);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush($user);
     $client = static::makeClient(false, array('PHP_AUTH_USER' => "bernd2", 'PHP_AUTH_PW' => "admin"));
     $iriConverter = $this->getContainer()->get("api.iri_converter");
     $iri = $iriConverter->getIriFromItem($user) . "/changePassword";
     $parameters = array("oldpassword" => "admin", "newpassword" => "foobar");
     $client->request("PUT", $iri, $parameters);
     $response = json_decode($client->getResponse()->getContent());
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $this->assertFalse($response->{"legacy"});
     $this->assertEmpty($response->{"password"});
     $this->assertEmpty($response->{"newPassword"});
     $client = static::makeClient(false, array('PHP_AUTH_USER' => "bernd2", 'PHP_AUTH_PW' => "foobar"));
     $client->request("PUT", $iri, $parameters);
     $response = json_decode($client->getResponse()->getContent());
     $this->assertEquals(500, $client->getResponse()->getStatusCode());
     $this->assertObjectHasAttribute("@type", $response);
     $this->assertEquals("Error", $response->{"@type"});
 }
Example #3
0
 public function testLegacyAuth()
 {
     $user = new User("foobar");
     $user->setPassword(md5("admin"));
     $user->setLegacy(true);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->persist($user);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush($user);
     $client = static::makeClient(false, array('PHP_AUTH_USER' => "foobar", 'PHP_AUTH_PW' => "admin"));
     $client->request("GET", "/api/system_status");
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $client = static::makeClient(false, array('PHP_AUTH_USER' => "foobar", 'PHP_AUTH_PW' => "admin2"));
     $client->request("GET", "/api/system_status");
     $this->assertEquals(401, $client->getResponse()->getStatusCode());
 }
Example #4
0
 public function testLegacyAuth()
 {
     $user = new User('foobar');
     $user->setPassword(md5('admin'));
     $user->setLegacy(true);
     $this->getContainer()->get('doctrine.orm.default_entity_manager')->persist($user);
     $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($user);
     $client = static::makeClient(false, ['PHP_AUTH_USER' => 'foobar', 'PHP_AUTH_PW' => 'admin']);
     $client->request('GET', '/api/system_status');
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $client = static::makeClient(false, ['PHP_AUTH_USER' => 'foobar', 'PHP_AUTH_PW' => 'admin2']);
     $client->request('GET', '/api/system_status');
     $this->assertEquals(401, $client->getResponse()->getStatusCode());
 }
Example #5
0
 /**
  * Unprotects a given user against changes.
  *
  * @param User $user
  */
 public function unprotect(User $user)
 {
     $user->setProtected(false);
     $this->entityManager->flush();
 }