-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for different key types of JOSE::JWK.
- Loading branch information
1 parent
fc8b444
commit 4dde75f
Showing
11 changed files
with
263 additions
and
8 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
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
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,54 @@ | ||
require 'test_helper' | ||
|
||
class JOSE::JWK::KTY_RSATest < Minitest::Test | ||
|
||
SECRET_JWK_JSON = "{\"d\":\"ghUlwEYdrZ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iFqLOU\"}" | ||
|
||
def test_generate_key | ||
jwk1 = JOSE::JWK.generate_key([:rsa, 128]) | ||
jwk2 = JOSE::JWK.generate_key([:rsa, 128, 13]) | ||
jwk3 = JOSE::JWK.generate_key(jwk2) | ||
refute_equal JOSE::JWK.thumbprint(jwk1), JOSE::JWK.thumbprint(jwk2) | ||
refute_equal JOSE::JWK.thumbprint(jwk1), JOSE::JWK.thumbprint(jwk3) | ||
refute_equal JOSE::JWK.thumbprint(jwk2), JOSE::JWK.thumbprint(jwk3) | ||
end | ||
|
||
def test_block_encryptor | ||
RSAGenerator.cache do | ||
plain_jwk = JOSE::JWK.from(SECRET_JWK_JSON) | ||
assert_equal JOSE::Map['alg' => 'RSA-OAEP', 'enc' => 'A128GCM'], JOSE::JWK.block_encryptor(plain_jwk) | ||
extra_jwk = plain_jwk.merge({'alg' => 'RSA-OAEP-256', 'enc' => 'A256GCM', 'use' => 'enc'}) | ||
assert_equal JOSE::Map['alg' => 'RSA-OAEP-256', 'enc' => 'A256GCM'], JOSE::JWK.block_encryptor(extra_jwk) | ||
end | ||
end | ||
|
||
def test_signer | ||
RSAGenerator.cache do | ||
plain_jwk = JOSE::JWK.from(SECRET_JWK_JSON) | ||
assert_equal JOSE::Map['alg' => 'RS256'], JOSE::JWK.signer(plain_jwk) | ||
extra_jwk = plain_jwk.merge({'alg' => 'PS256', 'use' => 'sig'}) | ||
assert_equal JOSE::Map['alg' => 'PS256'], JOSE::JWK.signer(extra_jwk) | ||
public_jwk = JOSE::JWK.from(PUBLIC_JWK_JSON) | ||
assert_raises(ArgumentError) { JOSE::JWK.signer(public_jwk) } | ||
end | ||
end | ||
|
||
def test_verifier | ||
RSAGenerator.cache do | ||
plain_jwk = JOSE::JWK.from(SECRET_JWK_JSON) | ||
assert_equal ['PS256', 'PS384', 'PS512', 'RS256', 'RS384', 'RS512'], JOSE::JWK.verifier(plain_jwk) | ||
extra_jwk = plain_jwk.merge({'alg' => 'PS256', 'use' => 'sig'}) | ||
assert_equal ['PS256'], JOSE::JWK.verifier(extra_jwk) | ||
end | ||
end | ||
|
||
def test_key_encryptor | ||
RSAGenerator.cache do | ||
secret_jwk = JOSE::JWK.from_binary(SECRET_JWK_JSON) | ||
key_encryptor = secret_jwk.kty.key_encryptor(secret_jwk.fields, 'test') | ||
assert_equal 'PBES2-HS256+A128KW', key_encryptor['alg'] | ||
end | ||
end | ||
|
||
end |
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