| 8 | |
| 9 | |
| 10 | class TestHMACAlgorithm: |
| 11 | def test_non_string_key(self): |
| 12 | with pytest.raises(JOSEError): |
| 13 | HMACKey(object(), ALGORITHMS.HS256) |
| 14 | |
| 15 | def test_RSA_key(self): |
| 16 | key = "-----BEGIN PUBLIC KEY-----" |
| 17 | with pytest.raises(JOSEError): |
| 18 | HMACKey(key, ALGORITHMS.HS256) |
| 19 | |
| 20 | key = "-----BEGIN RSA PUBLIC KEY-----" |
| 21 | with pytest.raises(JOSEError): |
| 22 | HMACKey(key, ALGORITHMS.HS256) |
| 23 | |
| 24 | key = "-----BEGIN CERTIFICATE-----" |
| 25 | with pytest.raises(JOSEError): |
| 26 | HMACKey(key, ALGORITHMS.HS256) |
| 27 | |
| 28 | key = "ssh-rsa" |
| 29 | with pytest.raises(JOSEError): |
| 30 | HMACKey(key, ALGORITHMS.HS256) |
| 31 | |
| 32 | def test_to_dict(self): |
| 33 | passphrase = "The quick brown fox jumps over the lazy dog" |
| 34 | encoded = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw" |
| 35 | key = HMACKey(passphrase, ALGORITHMS.HS256) |
| 36 | |
| 37 | as_dict = key.to_dict() |
| 38 | assert "alg" in as_dict |
| 39 | assert as_dict["alg"] == ALGORITHMS.HS256 |
| 40 | |
| 41 | assert "kty" in as_dict |
| 42 | assert as_dict["kty"] == "oct" |
| 43 | |
| 44 | assert "k" in as_dict |
| 45 | assert as_dict["k"] == encoded |
| 46 | |
| 47 | # as_dict should be serializable to JSON |
| 48 | json.dumps(as_dict) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…