partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 403439b9a4ad50c74241d0d03db004d87c679a1e
parent b5a1e5716c4341511617dad16a8fbe67972a79d9
Author: Felicitus <felicitus@felicitus.org>
Date:   Sun,  3 May 2015 19:57:36 +0200

Added tests for username and password hash constraints

Diffstat:
Msrc/PartKeepr/AuthBundle/Tests/Controller/DefaultControllerTest.php | 90++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 85 insertions(+), 5 deletions(-)

diff --git a/src/PartKeepr/AuthBundle/Tests/Controller/DefaultControllerTest.php b/src/PartKeepr/AuthBundle/Tests/Controller/DefaultControllerTest.php @@ -6,17 +6,17 @@ use Liip\FunctionalTestBundle\Test\WebTestCase; class DefaultControllerTest extends WebTestCase { - - private $repo; - - public function testLogin() + public function setUp() { $this->loadFixtures( array( - 'PartKeepr\AuthBundle\DataFixtures\LoadUserData' + 'PartKeepr\AuthBundle\DataFixtures\LoadUserData', ) ); + } + public function testLogin() + { $client = static::createClient(); $request = array("username" => "admin", "password" => md5("admin")); @@ -36,4 +36,84 @@ class DefaultControllerTest extends WebTestCase $this->assertObjectHasAttribute("username", $response); } + + public function testMD5Constraint() + { + $client = static::createClient(); + + $request = array("username" => "IDONOTEXIST", "password" => "IAMANINVALIDMD5HASH"); + + $client->request( + 'POST', + '/auth/login', + array(), + array(), + array('CONTENT_TYPE' => 'application/json'), + json_encode($request) + ); + + $this->assertEquals($client->getResponse()->getStatusCode(), 400); + } + + public function testFailedLogin() + { + $client = static::createClient(); + + $request = array("username" => "IDONOTEXIST", "password" => md5("I AM NOT EXISTANT")); + + $client->request( + 'POST', + '/auth/login', + array(), + array(), + array('CONTENT_TYPE' => 'application/json'), + json_encode($request) + ); + + $this->assertEquals($client->getResponse()->getStatusCode(), 401); + } + + public function testUsernameConstraints () { + $this->_testInvalidUsernameConstraint("a"); // Username must be longer than 3 characters + $this->_testInvalidUsernameConstraint(str_repeat("a",51)); // Username must be shorter than 50 characters + $this->_testInvalidUsernameConstraint("BÄH"); // Username must not contain umlauts + + $this->_testValidUsernameConstraint("void_bar\\foo/test.ding-dong"); + } + public function _testInvalidUsernameConstraint($username) + { + $client = static::createClient(); + + $request = array("username" => $username, "password" => md5("I AM NOT EXISTANT")); + + $client->request( + 'POST', + '/auth/login', + array(), + array(), + array('CONTENT_TYPE' => 'application/json'), + json_encode($request) + ); + + $this->assertEquals($client->getResponse()->getStatusCode(), 400); + } + + public function _testValidUsernameConstraint($username) + { + $client = static::createClient(); + + $request = array("username" => $username, "password" => md5("I AM NOT EXISTANT")); + + $client->request( + 'POST', + '/auth/login', + array(), + array(), + array('CONTENT_TYPE' => 'application/json'), + json_encode($request) + ); + + $this->assertNotEquals($client->getResponse()->getStatusCode(), 400); + } + }