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'}); }
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"}); }
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()); }
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()); }
/** * Unprotects a given user against changes. * * @param User $user */ public function unprotect(User $user) { $user->setProtected(false); $this->entityManager->flush(); }