| 26 | jws.verify(token, "secret", ["HS256"]) |
| 27 | |
| 28 | def test_multiple_keys(self): |
| 29 | old_jwk_verify = jwk.HMACKey.verify |
| 30 | try: |
| 31 | token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8" |
| 32 | |
| 33 | def raise_exception(self, msg, sig): |
| 34 | if self.prepared_key == b"incorrect": |
| 35 | raise Exception("Mocked function jose.jwk.HMACKey.verify") |
| 36 | else: |
| 37 | return True |
| 38 | |
| 39 | jwk.HMACKey.verify = raise_exception |
| 40 | jws.verify(token, {"keys": ["incorrect", "secret"]}, ["HS256"]) |
| 41 | finally: |
| 42 | jwk.HMACKey.verify = old_jwk_verify |
| 43 | |
| 44 | def test_invalid_algorithm(self): |
| 45 | token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8" |