Skip to content

Commit

Permalink
fix(py): Python 3 incompatibility of relay.auth (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Aug 13, 2020
1 parent 51195b0 commit 7b45bbd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion py/sentry_relay/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import uuid
from sentry_relay._lowlevel import lib
from sentry_relay._compat import text_type, implements_to_string
from sentry_relay._compat import PY2, text_type, implements_to_string
from sentry_relay.utils import (
RustObject,
encode_str,
Expand Down Expand Up @@ -68,6 +68,8 @@ def sign(self, value):

def pack(self, data):
packed = json.dumps(data, separators=(",", ":"))
if not PY2:
packed = packed.encode("utf8")
return packed, self.sign(packed)

def __str__(self):
Expand Down
5 changes: 5 additions & 0 deletions py/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def test_basic_key_functions():
assert pk.verify(b"some secret data", signature)
assert not pk.verify(b"some other data", signature)

packed, signature = sk.pack({"foo": "bar"})
pk.unpack(packed, signature)
with pytest.raises(sentry_relay.UnpackErrorBadSignature):
pk.unpack(b"haha", signature)


def test_challenge_response():
resp = sentry_relay.create_register_challenge(
Expand Down

0 comments on commit 7b45bbd

Please sign in to comment.