Skip to content

Commit

Permalink
Wildcard host validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Jan 4, 2024
1 parent ad6f7e6 commit 9cfeb16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Validator/Host.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ public function isValid($value): bool
return false;
}

if (\in_array(\parse_url($value, PHP_URL_HOST), $this->whitelist)) {
return true;
$hostnameValidator = new Hostname($this->whitelist);

if (!$hostnameValidator->isValid(\parse_url($value, PHP_URL_HOST))) {
return false;
}

return false;
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/Validator/HostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HostTest extends TestCase

public function setUp(): void
{
$this->host = new Host(['example.io', 'subdomain.example.test', 'localhost']);
$this->host = new Host(['example.io', 'subdomain.example.test', 'localhost', '*.appwrite.io']);
}

public function testIsValid()
Expand All @@ -32,6 +32,10 @@ public function testIsValid()
$this->assertEquals($this->host->isValid('localhost'), false);
$this->assertEquals($this->host->isValid('http://subdomain.example.test/path'), true);
$this->assertEquals($this->host->isValid('http://test.subdomain.example.test/path'), false);
$this->assertEquals($this->host->isValid('http://appwrite.io/path'), false);
$this->assertEquals($this->host->isValid('http://me.appwrite.io/path'), true);
$this->assertEquals($this->host->isValid('http://you.appwrite.io/path'), true);
$this->assertEquals($this->host->isValid('http://us.together.appwrite.io/path'), true);
$this->assertEquals($this->host->getType(), 'string');
}
}

0 comments on commit 9cfeb16

Please sign in to comment.