mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 08:28:42 +00:00
Merge pull request #10164 from appwrite/improve-scheme-error
chore: improve invalid scheme error in origin check
This commit is contained in:
commit
8b90acd8c6
2 changed files with 10 additions and 1 deletions
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue