Skip to content

Commit

Permalink
[message] ensure decoding can be done as string->dict too
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Apr 15, 2019
1 parent 8b0bfa3 commit d9634d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion graphenecommon/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ def verify(self, **kwargs):
:returns: True if the message is verified successfully
:raises InvalidMessageSignature if the signature is not ok
"""
assert isinstance(self.message, dict), "Message must be dictionary"
if not isinstance(self.message, dict):
try:
self.message = json.loads(self.message)
except Exception:
raise ValueError("Message must be valid JSON")

payload = self.message.get("payload")
assert payload, "Missing payload"
Expand Down
7 changes: 7 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import json
import unittest
from .fixtures import fixture_data, Message, MessageV1, MessageV2
from pprint import pprint
Expand Down Expand Up @@ -48,6 +49,12 @@ def test_v2_enc(self):
v = MessageV2(c)
v.verify()

def test_v2_enc_string(self):
m = MessageV2("foobar")
c = m.sign(account="init0")
v = MessageV2(json.dumps(c))
v.verify()

def test_v2andv1_enc(self):
m = MessageV2("foobar")
c = m.sign(account="init0")
Expand Down

0 comments on commit d9634d7

Please sign in to comment.