← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-webhook-client into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-webhook-client into launchpad:master.

Commit message:
Fix use of hmac in webhook client

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/388910

hmac.new takes its secret key and message arguments as bytes, not text.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-webhook-client into launchpad:master.
diff --git a/lib/lp/services/webhooks/client.py b/lib/lp/services/webhooks/client.py
index 256c1ff..8254cca 100644
--- a/lib/lp/services/webhooks/client.py
+++ b/lib/lp/services/webhooks/client.py
@@ -45,7 +45,9 @@ def create_request(user_agent, secret, delivery_id, event_type, payload):
         'X-Launchpad-Delivery': delivery_id,
         }
     if secret is not None:
-        hexdigest = hmac.new(secret, body, digestmod=hashlib.sha1).hexdigest()
+        hexdigest = hmac.new(
+            secret.encode('UTF-8'), body.encode('UTF-8'),
+            digestmod=hashlib.sha1).hexdigest()
         headers['X-Hub-Signature'] = 'sha1=%s' % hexdigest
     return (body, headers)
 
diff --git a/lib/lp/services/webhooks/tests/test_job.py b/lib/lp/services/webhooks/tests/test_job.py
index 90f3b93..a395b53 100644
--- a/lib/lp/services/webhooks/tests/test_job.py
+++ b/lib/lp/services/webhooks/tests/test_job.py
@@ -190,7 +190,7 @@ class TestWebhookClient(TestCase):
                 'response': MatchesDict({
                     'status_code': Equals(200),
                     'headers': Equals({'Content-Type': 'text/plain'}),
-                    'body': Equals('Content'),
+                    'body': Equals(b'Content'),
                     }),
                 }))
 
@@ -203,7 +203,7 @@ class TestWebhookClient(TestCase):
                 'response': MatchesDict({
                     'status_code': Equals(404),
                     'headers': Equals({'Content-Type': 'text/plain'}),
-                    'body': Equals('Content'),
+                    'body': Equals(b'Content'),
                     }),
                 }))