fix validation of invalid username

This commit is contained in:
Spine
2024-01-01 13:17:14 +01:00
parent 6d2a288b85
commit 412c41fbe4
2 changed files with 47 additions and 4 deletions
+44 -1
View File
@@ -8,7 +8,9 @@ class UserCreateTest extends TestCase {
protected Gazelle\User $user;
public function tearDown(): void {
$this->user->remove();
if (isset($this->user)) {
$this->user->remove();
}
}
public function testCreate(): void {
@@ -64,4 +66,45 @@ class UserCreateTest extends TestCase {
$this->assertEquals(0, $watch->nrAttempts(), 'user-create-two-login-cleared');
$this->assertEquals(0, $watch->nrBans(), 'user-create-two-login-banned');
}
public function testZeroFailure(): void {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
$creator = (new \Gazelle\UserCreator)
->setUsername('0')
->setEmail("[email protected]")
->setPassword(randomString(20))
->setIpaddr('127.0.0.100')
->setAdminComment('Created by tests/phpunit/UserCreateTest.php');
$this->expectException(Gazelle\Exception\UserCreatorException::class);
$creator->create();
}
public function testNameFailure(): void {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
$creator = (new \Gazelle\UserCreator)
->setUsername(randomString(21))
->setEmail("[email protected]")
->setPassword(randomString(20))
->setIpaddr('127.0.0.100')
->setAdminComment('Created by tests/phpunit/UserCreateTest.php');
$this->expectException(Gazelle\Exception\UserCreatorException::class);
$creator->create();
}
public function testNameTrim(): void {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
$this->user = (new \Gazelle\UserCreator)
->setUsername(' ' . randomString(6))
->setEmail("[email protected]")
->setPassword(randomString(20))
->setIpaddr('127.0.0.100')
->setAdminComment('Created by tests/phpunit/UserCreateTest.php')
->create();
$this->assertInstanceOf(Gazelle\User::class, $this->user, 'user-create-trim');
}
}