mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-10-22 01:03:21 -04:00
fix validation of invalid username
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user