MCPcopy Create free account
hub / github.com/mpdavis/python-jose / TestHMACAlgorithm

Class TestHMACAlgorithm

tests/algorithms/test_HMAC.py:10–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class 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)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…