1
0
Fork 0
mirror of synced 2024-07-18 12:56:00 +12:00
appwrite/tests/unit/Utopia/Database/Validator/ProjectIdTest.php
Steven Nguyen 33f5cbeca6
Restrict characters for project ID
Only allow lowercase alphanumeric chars and hyphens
because the project ID is used as part of url
schemes to redirect users back to mobile apps
and certain characters are not allowed.
2023-06-23 16:22:42 -07:00

48 lines
1 KiB
PHP

<?php
namespace Tests\Unit\Utopia\Database\Validator;
use Appwrite\Utopia\Database\Validator\ProjectId;
use PHPUnit\Framework\TestCase;
class ProjectIdTest extends TestCase
{
/**
* @var Key
*/
protected $object = null;
public function setUp(): void
{
$this->object = new ProjectId();
}
public function tearDown(): void
{
}
/**
* @return array
*/
public function provideTest(): array
{
return [
'unique()' => ['unique()', true],
'dashes' => ['as12-df34', true],
'36 chars' => [\str_repeat('a', 36), true],
'uppercase' => ['ABC', false],
'underscore' => ['under_score', false],
'leading dash' => ['-dash', false],
'too long' => [\str_repeat('a', 37), false],
];
}
/**
* @dataProvider provideTest
*/
public function testValues(string $input, bool $expected): void
{
$this->assertEquals($this->object->isValid($input), $expected);
}
}