Skip to content

Commit

Permalink
fix hostname_from_url when it's already a hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
aliel committed Oct 5, 2023
1 parent f9fd108 commit 084d4b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/aleph/sdk/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class TargetType(str, Enum):


def hostname_from_url(url: Union[HttpUrl, str]) -> Hostname:
return Hostname(urlparse(url).netloc)
parsed = urlparse(url)
if all([parsed.scheme, parsed.netloc]) is True:
url = parsed.netloc

return Hostname(url)


class DomainValidator:
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

from aleph.sdk.domain import DomainValidator
from aleph.sdk.exceptions import DomainConfigurationError

from src.aleph.sdk.domain import TargetType, hostname_from_url


def test_hostname():
hostname = hostname_from_url("https://aleph.im")
assert hostname == "aleph.im"
hostname = hostname_from_url("aleph.im")
assert hostname == "aleph.im"

@pytest.mark.asyncio
async def test_query():
alephdns = DomainValidator()
Expand Down Expand Up @@ -55,3 +60,4 @@ async def test_not_configured_domain():
hostname = hostname_from_url(url)
with pytest.raises(DomainConfigurationError):
status = await alephdns.check_domain(hostname, TargetType.IPFS, "0xfakeaddress")
assert type(status) is None

0 comments on commit 084d4b6

Please sign in to comment.