Skip to content

Commit

Permalink
Merge branch 'v4'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	README.rst
#	docs/en/install.rst
#	docs/zh_CN/install.rst
#	stellar_sdk/__version__.py
  • Loading branch information
overcat committed Sep 23, 2021
2 parents 9ce9acd + c8cd7ab commit f71fbd5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release History
==============

### Version 4.2.2
Released on September 23, 2021

#### Update
* fix: SEP-10, fix case where muxed accounts are not enabled. ([#530](https://github.com/StellarCN/py-stellar-base/pull/530))

### Version 5.0.0-beta2
Released on September 21, 2021

Expand Down
11 changes: 10 additions & 1 deletion stellar_sdk/sep/stellar_web_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ..transaction_envelope import TransactionEnvelope
from .ed25519_public_key_signer import Ed25519PublicKeySigner
from .exceptions import InvalidSep10ChallengeError
from ..exceptions import FeatureNotEnabledError

__all__ = [
"build_challenge_transaction",
Expand Down Expand Up @@ -239,6 +240,14 @@ def read_challenge_transaction(
if not client_account:
raise InvalidSep10ChallengeError("Operation should have a source account.")

try:
client_account_address = client_account.account_muxed or client_account.account_id
except FeatureNotEnabledError:
if client_account.account_muxed_id:
raise InvalidSep10ChallengeError("Muxed accounts are not supported")
else:
client_account_address = client_account.account_id

matched_home_domain = None
if isinstance(home_domains, str):
if manage_data_op.data_name == f"{home_domains} auth":
Expand Down Expand Up @@ -311,7 +320,7 @@ def read_challenge_transaction(

return ChallengeTransaction(
transaction=transaction_envelope,
client_account_id=client_account.account_muxed or client_account.account_id,
client_account_id=client_account_address,
matched_home_domain=matched_home_domain,
memo=memo,
)
Expand Down
57 changes: 57 additions & 0 deletions tests/sep/test_stellar_web_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import time
from random import randrange
from unittest.mock import patch, PropertyMock

import pytest

Expand All @@ -22,6 +23,7 @@
)
from stellar_sdk.transaction_builder import TransactionBuilder
from stellar_sdk.transaction_envelope import TransactionEnvelope
from stellar_sdk.exceptions import FeatureNotEnabledError


class TestStellarWebAuthentication:
Expand Down Expand Up @@ -1929,6 +1931,61 @@ def test_read_challenge_transaction_mux_client_id_permitted(self):
)
assert challenge_transaction.client_account_id == client_account_id

def test_read_challenge_transaction_mux_client_id_not_permitted_by_env_var(self):
server_kp = Keypair.random()
client_account_id = (
"MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY"
)
timeout = 600
network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE
home_domain = "example.com"
web_auth_domain = "auth.example.com"

challenge = build_challenge_transaction(
server_secret=server_kp.secret,
client_account_id=client_account_id,
home_domain=home_domain,
web_auth_domain=web_auth_domain,
network_passphrase=network_passphrase,
timeout=timeout,
)
with patch("stellar_sdk.MuxedAccount.account_muxed", new_callable=PropertyMock) as mocked_account_muxed:
mocked_account_muxed.side_effect = FeatureNotEnabledError()
with pytest.raises(InvalidSep10ChallengeError, match="Muxed accounts are not supported"):
read_challenge_transaction(
challenge_transaction=challenge,
server_account_id=server_kp.public_key,
network_passphrase=network_passphrase,
web_auth_domain=web_auth_domain,
home_domains=home_domain,
)

def test_read_challenge_transaction_g_client_id_muxed_not_permitted_by_env_var(self):
server_kp = Keypair.random()
client_account_id = Keypair.random().public_key
timeout = 600
network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE
home_domain = "example.com"
web_auth_domain = "auth.example.com"

challenge = build_challenge_transaction(
server_secret=server_kp.secret,
client_account_id=client_account_id,
home_domain=home_domain,
web_auth_domain=web_auth_domain,
network_passphrase=network_passphrase,
timeout=timeout,
)
with patch("stellar_sdk.MuxedAccount.account_muxed", new_callable=PropertyMock) as mocked_account_muxed:
mocked_account_muxed.side_effect = FeatureNotEnabledError()
read_challenge_transaction(
challenge_transaction=challenge,
server_account_id=server_kp.public_key,
network_passphrase=network_passphrase,
web_auth_domain=web_auth_domain,
home_domains=home_domain,
)

def test_read_challenge_transaction_with_memo_permitted(self):
server_kp = Keypair.random()
client_account_id = Keypair.random()
Expand Down

0 comments on commit f71fbd5

Please sign in to comment.