Skip to content

Commit 466f7cc

Browse files
author
Greg Bowler
committed
Test AuthURI consists of correct parts
1 parent 4c32d77 commit 466f7cc

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

src/AuthUri.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Authwave;
3+
4+
use Gt\Http\Uri;
5+
use Psr\Http\Message\UriInterface;
6+
7+
class AuthUri extends Uri {
8+
const QUERY_STRING_CIPHER = "cipher";
9+
const QUERY_STRING_INIT_VECTOR = "iv";
10+
const QUERY_STRING_RETURN_PATH = "return";
11+
12+
public function __construct(
13+
UriInterface $baseUri,
14+
Token $token,
15+
string $returnPath
16+
) {
17+
parent::__construct($baseUri);
18+
19+
$this->query = http_build_query([
20+
self::QUERY_STRING_CIPHER => (string)$token->generateCipher(),
21+
self::QUERY_STRING_INIT_VECTOR => (string)$token->getIv(),
22+
self::QUERY_STRING_RETURN_PATH => base64_encode($returnPath),
23+
]);
24+
}
25+
}

test/phpunit/AuthUriTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
namespace Authwave\Test;
3+
4+
use Authwave\AuthUri;
5+
use Authwave\InitVector;
6+
use Authwave\Token;
7+
use PHPUnit\Framework\TestCase;
8+
use Psr\Http\Message\UriInterface;
9+
10+
class AuthUriTest extends TestCase {
11+
public function testAuthUriHttps() {
12+
$baseUri = self::createMock(UriInterface::class);
13+
$baseUri->method("__toString")
14+
->willReturn("https://example.com");
15+
$token = self::createMock(Token::class);
16+
17+
$sut = new AuthUri($baseUri, $token, "");
18+
self::assertEquals(
19+
"https",
20+
$sut->getScheme()
21+
);
22+
}
23+
24+
public function testQueryString() {
25+
$mockCipherValue = str_repeat("f", 16);
26+
$mockIvValue = str_repeat("0", 16);
27+
$iv = self::createMock(InitVector::class);
28+
$iv->method("__toString")
29+
->willReturn($mockIvValue);
30+
31+
$baseUri = self::createMock(UriInterface::class);
32+
$token = self::createMock(Token::class);
33+
$token->method("generateCipher")
34+
->willReturn($mockCipherValue);
35+
$token->method("getIv")
36+
->willReturn($iv);
37+
38+
$returnPath = "/examplePage";
39+
$sut = new AuthUri($baseUri, $token, $returnPath);
40+
parse_str($sut->getQuery(), $queryParts);
41+
42+
self::assertEquals(
43+
$mockCipherValue,
44+
$queryParts[AuthUri::QUERY_STRING_CIPHER],
45+
);
46+
47+
self::assertEquals(
48+
$mockIvValue,
49+
$queryParts[AuthUri::QUERY_STRING_INIT_VECTOR]
50+
);
51+
52+
self::assertEquals(
53+
base64_encode($returnPath),
54+
$queryParts[AuthUri::QUERY_STRING_RETURN_PATH]
55+
);
56+
}
57+
}

0 commit comments

Comments
 (0)