-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Strobotti/test-coverage
Increase test-coverage
- Loading branch information
Showing
8 changed files
with
171 additions
and
51 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
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Strobotti\JWK\Key\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Strobotti\JWK\Key\AbstractKey; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AbstractKeyTest extends TestCase | ||
{ | ||
public function testCreateFromJSON(): void | ||
{ | ||
$json = <<<'EOT' | ||
{ | ||
"kty": "RSA", | ||
"use": "sig", | ||
"alg": "RS256", | ||
"kid": "86D88Kf" | ||
} | ||
EOT; | ||
|
||
$key = AbstractKeyTest__AbstractKey__Mock::createFromJSON($json); | ||
|
||
static::assertSame($json, "{$key}"); | ||
} | ||
} | ||
|
||
final class AbstractKeyTest__AbstractKey__Mock extends AbstractKey | ||
{ | ||
} |
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
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
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
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
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,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Strobotti\JWK\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Strobotti\JWK\Key\Rsa; | ||
use Strobotti\JWK\KeySet; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class KeySetTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideCreateFromJSON | ||
*/ | ||
public function testToString(string $expected, KeySet $keySet): void | ||
{ | ||
static::assertSame($expected, "{$keySet}"); | ||
} | ||
|
||
public function provideCreateFromJSON(): \Generator | ||
{ | ||
$keyJson = <<<'EOT' | ||
{ | ||
"kty": "RSA", | ||
"use": "sig", | ||
"alg": "RS256", | ||
"kid": "86D88Kf", | ||
"n": "iGaLqP6y-SJCCBq5Hv6pGDbG_SQ11MNjH7rWHcCFYz4hGwHC4lcSurTlV8u3avoVNM8jXevG1Iu1SY11qInqUvjJur--hghr1b56OPJu6H1iKulSxGjEIyDP6c5BdE1uwprYyr4IO9th8fOwCPygjLFrh44XEGbDIFeImwvBAGOhmMB2AD1n1KviyNsH0bEB7phQtiLk-ILjv1bORSRl8AK677-1T8isGfHKXGZ_ZGtStDe7Lu0Ihp8zoUt59kx2o9uWpROkzF56ypresiIl4WprClRCjz8x6cPZXU2qNWhu71TQvUFwvIvbkE1oYaJMb0jcOTmBRZA2QuYw-zHLwQ", | ||
"e": "AQAB" | ||
} | ||
EOT; | ||
|
||
yield [ | ||
'expected' => <<<'EOT' | ||
{ | ||
"keys": [ | ||
{ | ||
"kty": "RSA", | ||
"use": "sig", | ||
"alg": "RS256", | ||
"kid": "86D88Kf", | ||
"n": "iGaLqP6y-SJCCBq5Hv6pGDbG_SQ11MNjH7rWHcCFYz4hGwHC4lcSurTlV8u3avoVNM8jXevG1Iu1SY11qInqUvjJur--hghr1b56OPJu6H1iKulSxGjEIyDP6c5BdE1uwprYyr4IO9th8fOwCPygjLFrh44XEGbDIFeImwvBAGOhmMB2AD1n1KviyNsH0bEB7phQtiLk-ILjv1bORSRl8AK677-1T8isGfHKXGZ_ZGtStDe7Lu0Ihp8zoUt59kx2o9uWpROkzF56ypresiIl4WprClRCjz8x6cPZXU2qNWhu71TQvUFwvIvbkE1oYaJMb0jcOTmBRZA2QuYw-zHLwQ", | ||
"e": "AQAB" | ||
} | ||
] | ||
} | ||
EOT | ||
, | ||
'keySet' => (new KeySet()) | ||
->addKey(Rsa::createFromJSON($keyJson)), | ||
]; | ||
} | ||
|
||
public function testAddKeyThrowsErrorOnDuplicateKid(): void | ||
{ | ||
$this->expectException(\InvalidArgumentException::class); | ||
|
||
$keyJson = <<<'EOT' | ||
{ | ||
"kty": "RSA", | ||
"use": "sig", | ||
"alg": "RS256", | ||
"kid": "86D88Kf", | ||
"n": "iGaLqP6y-SJCCBq5Hv6pGDbG_SQ11MNjH7rWHcCFYz4hGwHC4lcSurTlV8u3avoVNM8jXevG1Iu1SY11qInqUvjJur--hghr1b56OPJu6H1iKulSxGjEIyDP6c5BdE1uwprYyr4IO9th8fOwCPygjLFrh44XEGbDIFeImwvBAGOhmMB2AD1n1KviyNsH0bEB7phQtiLk-ILjv1bORSRl8AK677-1T8isGfHKXGZ_ZGtStDe7Lu0Ihp8zoUt59kx2o9uWpROkzF56ypresiIl4WprClRCjz8x6cPZXU2qNWhu71TQvUFwvIvbkE1oYaJMb0jcOTmBRZA2QuYw-zHLwQ", | ||
"e": "AQAB" | ||
} | ||
EOT; | ||
$keySet = new KeySet(); | ||
$keySet->addKey(Rsa::createFromJSON($keyJson)) | ||
->addKey(Rsa::createFromJSON($keyJson)) | ||
; | ||
} | ||
|
||
public function testGetKeyById(): void | ||
{ | ||
$keyJson = <<<'EOT' | ||
{ | ||
"kty": "RSA", | ||
"use": "sig", | ||
"alg": "RS256", | ||
"kid": "86D88Kf", | ||
"n": "iGaLqP6y-SJCCBq5Hv6pGDbG_SQ11MNjH7rWHcCFYz4hGwHC4lcSurTlV8u3avoVNM8jXevG1Iu1SY11qInqUvjJur--hghr1b56OPJu6H1iKulSxGjEIyDP6c5BdE1uwprYyr4IO9th8fOwCPygjLFrh44XEGbDIFeImwvBAGOhmMB2AD1n1KviyNsH0bEB7phQtiLk-ILjv1bORSRl8AK677-1T8isGfHKXGZ_ZGtStDe7Lu0Ihp8zoUt59kx2o9uWpROkzF56ypresiIl4WprClRCjz8x6cPZXU2qNWhu71TQvUFwvIvbkE1oYaJMb0jcOTmBRZA2QuYw-zHLwQ", | ||
"e": "AQAB" | ||
} | ||
EOT; | ||
|
||
$key = Rsa::createFromJSON($keyJson); | ||
|
||
$keySet = new KeySet(); | ||
$keySet->addKey($key); | ||
|
||
static::assertSame($key, $keySet->getKeyById('86D88Kf')); | ||
|
||
static::assertNull($keySet->getKeyById('asdf')); | ||
} | ||
} |
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