You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
<?php declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use BradyMcD\TAATP\URI\Otpauth;
|
|
|
|
// For more information about the specification, refer to google's documentation on github.
|
|
// https://github.com/google/google-authenticator/wiki/Key-Uri-Format
|
|
/** @SuppressWarnings(PHPMD.StaticAccess)*/
|
|
final class URITest extends TestCase
|
|
{
|
|
private static $defaults;
|
|
private static $exampleUri;
|
|
private static $exampleComponents;
|
|
|
|
public static function setUpBeforeClass(): void
|
|
{
|
|
self::$defaults = Otpauth::DEFAULTS;
|
|
self::$exampleUri = 'otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=MD5&digits=8&period=60';
|
|
\parse_str(\parse_url(self::$exampleUri)['query'], self::$exampleComponents);
|
|
|
|
}
|
|
|
|
/** @SuppressWarnings(PHPMD.EmptyCatchBlock)*/
|
|
public function testRejectsInvalidUris(): void
|
|
{
|
|
$invalids = [
|
|
"https://www.example.org",
|
|
"Just a normal string",
|
|
"otpauth://totp/NOSECRETS:john.doe@email.com?issuer=ACME%20Co&algorithm=MD5&digits=8&period=60",
|
|
"otpauth://totp/MISS:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=MATCH&algorithm=MD5&digits=8&period=60",
|
|
"otpauth://totp/vendor:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=vendohr&algorithm=NotAnAlgo&digits=8&period=60",
|
|
"",
|
|
|
|
];
|
|
$pUri;
|
|
|
|
foreach ($invalids as $invalid)
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$pUri = Otpauth::fromString($invalid);
|
|
|
|
$this->assertNull($pUri);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
?>
|