parent
faabdb9aee
commit
35221b979e
@ -0,0 +1,71 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
use BradyMcD\TAATP\URI\Otpauth;
|
||||||
|
|
||||||
|
/** @SuppressWarnings(PHPMD.StaticAccess)*/
|
||||||
|
final class URITest extends TestCase
|
||||||
|
{
|
||||||
|
public function testExampleURI(): void
|
||||||
|
{
|
||||||
|
// Sourced from Google's otpauth URI specification
|
||||||
|
// https://github.com/google/google-authenticator/wiki/Key-Uri-Format
|
||||||
|
$string = 'otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=MD5&digits=8&period=60';
|
||||||
|
|
||||||
|
$urlComponents = [ "scheme" => "otpauth",
|
||||||
|
"host" => "totp",
|
||||||
|
"path" => "ACME%20Co:john.doe@email.com/",
|
||||||
|
"query" => "secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30",];
|
||||||
|
$queryComponents = [ "secret" => "HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ",
|
||||||
|
"issuer" => "ACME Co",
|
||||||
|
"algorithm" => "MD5",
|
||||||
|
"digits" => 8,
|
||||||
|
"period" => 60,];
|
||||||
|
|
||||||
|
$provisioningUri = Otpauth::fromString($string);
|
||||||
|
|
||||||
|
$this->assertSame($provisioningUri->secret, $queryComponents['secret']);
|
||||||
|
$this->assertSame($provisioningUri->issuer, $queryComponents['issuer']);
|
||||||
|
$this->assertSame($provisioningUri->digits, $queryComponents['digits']);
|
||||||
|
$this->assertSame($provisioningUri->period, $queryComponents['period']);
|
||||||
|
$this->assertSame($provisioningUri->algorithm, $queryComponents['algorithm']);
|
||||||
|
|
||||||
|
$calculatedUrl = $provisioningUri->emitStr();
|
||||||
|
|
||||||
|
$parsedOtp = \parse_url($calculatedUrl);
|
||||||
|
$parsedTest = \parse_url($string);
|
||||||
|
|
||||||
|
$parsedOtpQuery = [];
|
||||||
|
$parsedTestQuery = [];
|
||||||
|
|
||||||
|
\parse_str($parsedOtp['query'], $parsedOtpQuery);
|
||||||
|
unset($parsedOtp['query']);
|
||||||
|
\parse_str($parsedTest['query'], $parsedTestQuery);
|
||||||
|
unset($parsedTest['query']);
|
||||||
|
|
||||||
|
$this->assertEqualsCanonicalizing($parsedOtp, $parsedTest);
|
||||||
|
$this->assertEqualsCanonicalizing($parsedOtpQuery, $parsedTestQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIncompleteURI(): void
|
||||||
|
{
|
||||||
|
$string = 'otpauth://totp/Example:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=Example';
|
||||||
|
$queryComponents = [ "secret" => "HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ",
|
||||||
|
"issuer" => "Example",
|
||||||
|
"algorithm" => "SHA1",
|
||||||
|
"digits" => 6,
|
||||||
|
"period" => 30,];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$provisioningUri = Otpauth::fromString($string);
|
||||||
|
|
||||||
|
$this->assertSame($provisioningUri->secret, $queryComponents['secret']);
|
||||||
|
$this->assertSame($provisioningUri->algorithm, $queryComponents['algorithm']);
|
||||||
|
$this->assertSame($provisioningUri->digits, $queryComponents['digits']);
|
||||||
|
$this->assertSame($provisioningUri->period, $queryComponents['period']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Loading…
Reference in new issue