diff --git a/src/aleph/sdk/domain.py b/src/aleph/sdk/domain.py index 60cf7408..b014f353 100644 --- a/src/aleph/sdk/domain.py +++ b/src/aleph/sdk/domain.py @@ -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: diff --git a/tests/unit/test_domains.py b/tests/unit/test_domains.py index 221bd517..ffb1f7ae 100644 --- a/tests/unit/test_domains.py +++ b/tests/unit/test_domains.py @@ -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() @@ -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