-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test AuthURI consists of correct parts
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace Authwave; | ||
|
||
use Gt\Http\Uri; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
class AuthUri extends Uri { | ||
const QUERY_STRING_CIPHER = "cipher"; | ||
const QUERY_STRING_INIT_VECTOR = "iv"; | ||
const QUERY_STRING_RETURN_PATH = "return"; | ||
|
||
public function __construct( | ||
UriInterface $baseUri, | ||
Token $token, | ||
string $returnPath | ||
) { | ||
parent::__construct($baseUri); | ||
|
||
$this->query = http_build_query([ | ||
self::QUERY_STRING_CIPHER => (string)$token->generateCipher(), | ||
self::QUERY_STRING_INIT_VECTOR => (string)$token->getIv(), | ||
self::QUERY_STRING_RETURN_PATH => base64_encode($returnPath), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace Authwave\Test; | ||
|
||
use Authwave\AuthUri; | ||
use Authwave\InitVector; | ||
use Authwave\Token; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
class AuthUriTest extends TestCase { | ||
public function testAuthUriHttps() { | ||
$baseUri = self::createMock(UriInterface::class); | ||
$baseUri->method("__toString") | ||
->willReturn("https://example.com"); | ||
$token = self::createMock(Token::class); | ||
|
||
$sut = new AuthUri($baseUri, $token, ""); | ||
self::assertEquals( | ||
"https", | ||
$sut->getScheme() | ||
); | ||
} | ||
|
||
public function testQueryString() { | ||
$mockCipherValue = str_repeat("f", 16); | ||
$mockIvValue = str_repeat("0", 16); | ||
$iv = self::createMock(InitVector::class); | ||
$iv->method("__toString") | ||
->willReturn($mockIvValue); | ||
|
||
$baseUri = self::createMock(UriInterface::class); | ||
$token = self::createMock(Token::class); | ||
$token->method("generateCipher") | ||
->willReturn($mockCipherValue); | ||
$token->method("getIv") | ||
->willReturn($iv); | ||
|
||
$returnPath = "/examplePage"; | ||
$sut = new AuthUri($baseUri, $token, $returnPath); | ||
parse_str($sut->getQuery(), $queryParts); | ||
|
||
self::assertEquals( | ||
$mockCipherValue, | ||
$queryParts[AuthUri::QUERY_STRING_CIPHER], | ||
); | ||
|
||
self::assertEquals( | ||
$mockIvValue, | ||
$queryParts[AuthUri::QUERY_STRING_INIT_VECTOR] | ||
); | ||
|
||
self::assertEquals( | ||
base64_encode($returnPath), | ||
$queryParts[AuthUri::QUERY_STRING_RETURN_PATH] | ||
); | ||
} | ||
} |