Merge pull request #10164 from appwrite/improve-scheme-error

chore: improve invalid scheme error in origin check
This commit is contained in:
Steven Nguyen 2025-07-19 07:16:20 -07:00 committed by GitHub
commit 8b90acd8c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View file

@ -12,6 +12,7 @@ class Origin extends Validator
protected array $schemes = [];
protected ?string $scheme = null;
protected ?string $host = null;
protected string $origin = '';
/**
* Constructor
@ -32,6 +33,7 @@ class Origin extends Validator
*/
public function isValid($origin): bool
{
$this->origin = $origin;
$this->scheme = null;
$this->host = null;
@ -68,13 +70,17 @@ class Origin extends Validator
*/
public function getDescription(): string
{
$platform = $this->scheme ? Platform::getNameByScheme($this->scheme) : null;
$platform = $this->scheme ? Platform::getNameByScheme($this->scheme) : '';
$host = $this->host ? '(' . $this->host . ')' : '';
if (empty($this->host) && empty($this->scheme)) {
return 'Invalid Origin.';
}
if (empty($platform)) {
return 'Invalid Scheme. The scheme used (' . $this->scheme . ') in the Origin (' . $this->origin . ') is not supported. If you are using a custom scheme, please change it to `appwrite-callback-<PROJECT_ID>`';
}
return 'Invalid Origin. Register your new client ' . $host . ' as a new '
. $platform . ' platform on your project console dashboard';
}

View file

@ -106,5 +106,8 @@ class OriginTest extends TestCase
$this->assertEquals(false, $validator->isValid('ms-browser-extension://com.company.appname'));
$this->assertEquals('Invalid Origin. Register your new client (com.company.appname) as a new Web (Edge Extension) platform on your project console dashboard', $validator->getDescription());
$this->assertEquals(false, $validator->isValid('random-scheme://localhost'));
$this->assertEquals('Invalid Scheme. The scheme used (random-scheme) in the Origin (random-scheme://localhost) is not supported. If you are using a custom scheme, please change it to `appwrite-callback-<PROJECT_ID>`', $validator->getDescription());
}
}