Skip to content

Commit ae3bdee

Browse files
Merge pull request #114 from utopia-php/feat-wildcart-host-validator
Fix: Wildcard host validator
2 parents 6e20469 + c96d011 commit ae3bdee

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Http/Validator/Host.php

100644100755
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ public function isValid($value): bool
5151
return false;
5252
}
5353

54-
if (\in_array(\parse_url($value, PHP_URL_HOST), $this->whitelist)) {
55-
return true;
56-
}
54+
$hostnameValidator = new Hostname($this->whitelist);
5755

58-
return false;
56+
return $hostnameValidator->isValid(\parse_url($value, PHP_URL_HOST));
5957
}
6058

6159
/**

tests/Validator/HostTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class HostTest extends TestCase
1010

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

1616
public function testIsValid()
@@ -21,6 +21,10 @@ public function testIsValid()
2121
$this->assertEquals($this->host->isValid('localhost'), false);
2222
$this->assertEquals($this->host->isValid('http://subdomain.example.test/path'), true);
2323
$this->assertEquals($this->host->isValid('http://test.subdomain.example.test/path'), false);
24+
$this->assertEquals($this->host->isValid('http://appwrite.io/path'), false);
25+
$this->assertEquals($this->host->isValid('http://me.appwrite.io/path'), true);
26+
$this->assertEquals($this->host->isValid('http://you.appwrite.io/path'), true);
27+
$this->assertEquals($this->host->isValid('http://us.together.appwrite.io/path'), true);
2428
$this->assertEquals($this->host->getType(), 'string');
2529
}
2630
}

0 commit comments

Comments
 (0)