Trim username and password

This commit is contained in:
Frederic Guillot 2016-12-29 17:53:46 -05:00
parent 56d21dc726
commit 818c501b07
2 changed files with 13 additions and 0 deletions

View File

@ -9,6 +9,8 @@ const TABLE = 'users';
function create_user($username, $password, $is_admin = false)
{
$username = trim($username);
$password = trim($password);
list($fever_token, $fever_api_key) = generate_fever_api_key($username);
return Database::getInstance('db')

View File

@ -61,6 +61,17 @@ class UserModelTest extends BaseTest
$this->assertNotEquals('test', $user['password']);
}
public function testCreateUserWithTrailingSpaces()
{
$this->assertEquals(2, Model\User\create_user('foobar ', ' test'));
$user = Model\User\get_user_by_id(2);
$this->assertEquals(2, $user['id']);
$this->assertEquals('foobar', $user['username']);
$this->assertEquals(0, $user['is_admin']);
$this->assertTrue(password_verify('test', $user['password']));
}
public function testRemoveUser()
{
$this->assertEquals(2, Model\User\create_user('foobar', 'test'));