Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,5 @@ composer test
```

The test script runs PHPUnit, PHPStan, PHP_CodeSniffer and PHPMD. To run the unit tests alone, use `composer phpunit`.

For a local test provider, HTTP is supported for hosts ending in `.test`, such as `http://login.realtest.authwave.test:9090`. Configure local DNS or a hosts-file entry for the provider. This exception applies only to HTTP and the complete `.test` hostname suffix; `.authwave-test` and names such as `example.test.com` do not qualify. Other remote providers require HTTPS. Use test accounts on a trusted development network; the suffix does not encrypt traffic or guarantee that it stays on your machine.
3 changes: 3 additions & 0 deletions src/ProviderUri/BaseProviderUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ protected function normaliseBaseUri(string $baseUri):Uri {
->withHost($host)
->withPort($port);

$isTestHttp = $uri->getScheme() === "http"
&& str_ends_with(strtolower(rtrim($uri->getHost(), ".")), ".test");
if($uri->getHost() !== "localhost"
&& $uri->getHost() !== "127.0.0.127"
&& !$isTestHttp
&& $uri->getScheme() !== "https") {
throw new InsecureProtocolException($uri->getScheme());
}
Expand Down
42 changes: 42 additions & 0 deletions test/phpunit/ProviderUri/TestDomainTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace Authwave\Test\ProviderUri;

use Authwave\InsecureProtocolException;
use Authwave\ProviderUri\AdminUri;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class TestDomainTest extends TestCase {
public static function providerHosts():array {
return [
["http://login.realtest.authwave.test:9090", true],
["http://app.test", true],
["http://LOGIN.EXAMPLE.TEST:9090", true],
["http://login.example.test.:9090", true],
["http://localhost:9090", true],
["http://127.0.0.127:9090", true],
["https://login.authwave.com", true],
["http://login.realtest.authwave-test:9090", false],
["http://example.test.attacker.com", false],
["http://exampletest", false],
["http://test", false],
["http://login.authwave.com", false],
["ftp://example.test", false],
];
}

#[DataProvider("providerHosts")]
public function testProviderProtocolPolicy(string $host, bool $allowed):void {
if(!$allowed) {
self::expectException(InsecureProtocolException::class);
}
$uri = new AdminUri($host);
self::assertSame("/admin/", $uri->getPath());
if($allowed && str_starts_with($host, "http://")) {
self::assertSame("http", $uri->getScheme());
}
if(str_contains($host, ":9090")) {
self::assertSame(9090, $uri->getPort());
}
}
}
Loading