Skip to content

Commit

Permalink
chore: add test for parseKey (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Aug 7, 2024
1 parent 500501c commit d4495ba
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/JWKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,39 @@ public function testDecodeByMultiJwkKeySet()

$this->assertSame('bar', $result->sub);
}

public function testParseKey()
{
// Use a known module and exponent, and ensure it parses as expected
$jwk = [
'alg' => 'RS256',
'kty' => 'RSA',
'n' => 'hsYvCPtkUV7SIxwkOkJsJfhwV_CMdXU5i0UmY2QEs-Pa7v0-0y-s4EjEDtsQ8Yow6hc670JhkGBcMzhU4DtrqNGROXebyOse5FX0m0UvWo1qXqNTf28uBKB990mY42Icr8sGjtOw8ajyT9kufbmXi3eZKagKpG0TDGK90oBEfoGzCxoFT87F95liNth_GoyU5S8-G3OqIqLlQCwxkI5s-g2qvg_aooALfh1rhvx2wt4EJVMSrdnxtPQSPAtZBiw5SwCnVglc6OnalVNvAB2JArbqC9GAzzz9pApAk28SYg5a4hPiPyqwRv-4X1CXEK8bO5VesIeRX0oDf7UoM-pVAw',
'use' => 'sig',
'e' => 'AQAB',
'kid' => '838c06c62046c2d948affe137dd5310129f4d5d1'
];

$key = JWK::parseKey($jwk);
$this->assertNotNull($key);

$openSslKey = $key->getKeyMaterial();
$pubKey = openssl_pkey_get_public($openSslKey);
$keyData = openssl_pkey_get_details($pubKey);

$expectedPublicKey = <<<EOF
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhsYvCPtkUV7SIxwkOkJs
JfhwV/CMdXU5i0UmY2QEs+Pa7v0+0y+s4EjEDtsQ8Yow6hc670JhkGBcMzhU4Dtr
qNGROXebyOse5FX0m0UvWo1qXqNTf28uBKB990mY42Icr8sGjtOw8ajyT9kufbmX
i3eZKagKpG0TDGK90oBEfoGzCxoFT87F95liNth/GoyU5S8+G3OqIqLlQCwxkI5s
+g2qvg/aooALfh1rhvx2wt4EJVMSrdnxtPQSPAtZBiw5SwCnVglc6OnalVNvAB2J
ArbqC9GAzzz9pApAk28SYg5a4hPiPyqwRv+4X1CXEK8bO5VesIeRX0oDf7UoM+pV
AwIDAQAB
-----END PUBLIC KEY-----
EOF;

$this->assertEquals($expectedPublicKey, $keyData['key']);
}
}

0 comments on commit d4495ba

Please sign in to comment.