예제 #1
0
 def test_functional(self, key="KEY", msg="MSG"):
     assert hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", key, msg)
     assert hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", b"KEY", msg)
     assert not hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", "NKEY", msg)
     assert not hmac.verify(
         hmac.sign("sha512", key, msg), "sha256", "NKEY", msg)
예제 #2
0
파일: test_hmac.py 프로젝트: fcurella/thorn
 def test_functional(self, key="KEY", msg="MSG"):
     assert hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", key, msg)
     assert hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", b"KEY", msg)
     assert not hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", "NKEY", msg)
     assert not hmac.verify(
         hmac.sign("sha512", key, msg), "sha256", "NKEY", msg)
예제 #3
0
파일: test_hmac.py 프로젝트: sambrin/thorn
 def test_functional(self, key="KEY", msg="MSG"):
     self.assertTrue(hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", key, msg,
     ))
     self.assertTrue(hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", b"KEY", msg,
     ))
     self.assertFalse(hmac.verify(
         hmac.sign("sha512", key, msg), "sha512", "NKEY", msg,
     ))
     self.assertFalse(hmac.verify(
         hmac.sign("sha512", key, msg), "sha256", "NKEY", msg,
     ))
예제 #4
0
파일: base.py 프로젝트: sambrin/thorn
 def assert_article_event_received(self, article, event, sub=None,
                                   reverse=None, ref=None, n=1):
     logs = self.wait_for_webhook_received(ref or self.ref, maxlen=n)
     assert len(logs) == n
     if sub is not None:
         hmac_secret = sub['hmac_secret']
         if hmac_secret:
             log = SubscriberLog.objects.filter(ref=ref or self.ref)[0]
             assert hmac.verify(log.hmac, 'sha256', hmac_secret, log.data)
     self.assert_log_matches(
         logs[0],
         event=event,
         ref=reverse or self.reverse_article(article),
         data=article.webhook_payload(),
     )
예제 #5
0
    def assert_article_event_received(self, article, event, sub=None,
                                      reverse=None, ref=None, n=1):
        logs = self.wait_for_webhook_received(ref or self.ref, maxlen=n)
        assert len(logs) == n
        if sub is not None:
            hmac_secret = sub['hmac_secret']
            log = SubscriberLog.objects.filter(ref=ref or self.ref)[0]
            if hmac_secret:
                assert hmac.verify(log.hmac, 'sha256', hmac_secret, log.data)
            assert log.subscription == sub['id']

        self.assert_log_matches(
            logs[0],
            event=event,
            ref=reverse or self.reverse_article(article),
            data=article.webhooks.payload(article),
        )
예제 #6
0
파일: test_hmac.py 프로젝트: sambrin/thorn
 def test_unit(self, compare_digest, sign,
               digest_method="sha256", key="KEY", msg="MSG"):
     ret = hmac.verify("verify", digest_method, key, msg)
     sign.assert_called_with(digest_method, key, msg)
     compare_digest.assert_called_with(sign(), to_bytes("verify"))
     self.assertIs(ret, compare_digest())
예제 #7
0
 def test_unit(self, compare_digest, sign,
               digest_method="sha256", key="KEY", msg="MSG"):
     ret = hmac.verify("verify", digest_method, key, msg)
     sign.assert_called_with(digest_method, key, msg)
     compare_digest.assert_called_with(sign(), want_bytes("verify"))
     assert ret is compare_digest()