()
| 143 | |
| 144 | |
| 145 | def test_function_key(): |
| 146 | protected = {"alg": "HS256"} |
| 147 | header = [ |
| 148 | {"protected": protected, "header": {"kid": "a"}}, |
| 149 | {"protected": protected, "header": {"kid": "b"}}, |
| 150 | ] |
| 151 | |
| 152 | def load_key(header, payload): |
| 153 | assert payload == b"hello" |
| 154 | kid = header.get("kid") |
| 155 | if kid == "a": |
| 156 | return "secret-a" |
| 157 | return "secret-b" |
| 158 | |
| 159 | jws = JsonWebSignature() |
| 160 | s = jws.serialize(header, b"hello", load_key) |
| 161 | assert isinstance(s, dict) |
| 162 | assert "signatures" in s |
| 163 | |
| 164 | data = jws.deserialize(json.dumps(s), load_key) |
| 165 | header, payload = data["header"], data["payload"] |
| 166 | assert payload == b"hello" |
| 167 | assert header[0]["alg"] == "HS256" |
| 168 | assert "signature" not in data |
| 169 | |
| 170 | |
| 171 | def test_serialize_json_empty_payload(): |
nothing calls this directly
no test coverage detected