-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractProviderUriTest.php
111 lines (99 loc) · 2.42 KB
/
AbstractProviderUriTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace Authwave\Test\ProviderUri;
use Authwave\InitVector;
use Authwave\InsecureProtocolException;
use Authwave\ProviderUri\LoginUri;
use Authwave\Token;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface;
class AbstractProviderUriTest extends TestCase {
public function testAuthUriHttps() {
$baseUri = self::createMock(UriInterface::class);
$baseUri->method("__toString")
->willReturn("https://example.com");
$token = self::createMock(Token::class);
$sut = new LoginUri(
$token,
"",
$baseUri
);
self::assertEquals(
"https",
$sut->getScheme()
);
self::assertNull(
$sut->getPort()
);
}
public function testAuthUriWithNonStandardPort() {
$baseUri = self::createMock(UriInterface::class);
$baseUri->method("__toString")
->willReturn("http://localhost:8081");
$token = self::createMock(Token::class);
$sut = new LoginUri(
$token,
"",
$baseUri
);
self::assertEquals(
"http",
$sut->getScheme()
);
self::assertEquals(
8081,
$sut->getPort()
);
}
// All AuthUris MUST be served over HTTPS, with the one exception of localhost.
// But it should still default to HTTPS on localhost.
public function testGetAuthUriHostnameLocalhostHttpsByDefault() {
$token = self::createMock(Token::class);
$sut = new LoginUri(
$token,
"/",
"localhost"
);
self::assertStringStartsWith(
"https://localhost",
$sut
);
}
// We should be able to set the scheme to HTTP for localhost hostname only.
public function testGetAuthUriHostnameLocalhostHttpAllowed() {
$token = self::createMock(Token::class);
$sut = new LoginUri(
$token,
"/",
"http://localhost"
);
self::assertStringStartsWith(
"http://localhost",
$sut
);
}
// We should NOT be able to set the scheme to HTTP for other hostnames.
public function testGetAuthUriHostnameNotLocalhostHttpNotAllowed() {
$token = self::createMock(Token::class);
self::expectException(InsecureProtocolException::class);
new LoginUri(
$token,
"/",
"http://localhost.com"
);
}
public function testAuthUriHttpsInferred() {
$baseUri = self::createMock(UriInterface::class);
$baseUri->method("__toString")
->willReturn("example.com");
// Note on the line above, no scheme is passed in - we must assume https.
$token = self::createMock(Token::class);
$sut = new LoginUri(
$token,
"/",
$baseUri);
self::assertEquals(
"https",
$sut->getScheme()
);
}
}