Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(py): Python 3 incompatibility of relay.auth #712

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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