Skip to content

Commit

Permalink
Exercised the API endpoints with Unicode domains
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismyrobot committed Nov 12, 2017
1 parent af23bd5 commit b9433a8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dnstwister/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def whois(hexdomain):
)
payload = standard_api_values(domain, skip='whois')
try:
payload['whois_text'] = whois_mod.whois(domain).text.strip()
idna_domain = domain.encode('idna')
payload['whois_text'] = whois_mod.whois(idna_domain).text.strip()
if payload['whois_text'] == '':
raise Exception('No whois data retrieved')
except Exception as ex:
Expand Down
5 changes: 3 additions & 2 deletions dnstwister/api/checks/parked.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@

def _domain_redirects(domain, path=''):
"""Returns whether a domain (and optional path) redirects to another."""
idna_domain = domain.encode('idna')
req = requests.get(
'http://{}/{}'.format(domain, path),
'http://{}/{}'.format(idna_domain, path),
**shared.REQ_KWARGS
)
landed_domain = shared.get_domain(req.url)
return landed_domain != domain, landed_domain, req.content[:CONTENT_MAX]
return landed_domain != idna_domain, landed_domain, req.content[:CONTENT_MAX]


def get_text(score):
Expand Down
3 changes: 2 additions & 1 deletion dnstwister/api/checks/safebrowsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def get_report(domain):
Returns a count of matches.
"""
idna_domain = domain.encode('idna')
data = {
'site': domain
'site': idna_domain
}

result = requests.get(API_URL, params=data)
Expand Down
14 changes: 14 additions & 0 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pytest
import webtest.app

from dnstwister import tools


def test_api_root(webapp):
"""Test the API root."""
Expand Down Expand Up @@ -32,3 +34,15 @@ def test_api_domain_validation(webapp):
with pytest.raises(webtest.app.AppError) as err:
webapp.get('/api/{}/{}'.format(endpoint, malformed_domain))
assert '400 BAD REQUEST' in err.value.message


def test_unicode_basics(webapp):
"""Test that Unicode domains work on all endpoints."""
unicode_domain = 'xn--sterreich-z7a.icom.museum'.decode('idna')
endpoints = ('fuzz', 'ip', 'parked', 'safebrowsing', 'whois')
for endpoint in endpoints:
webapp.get('/api/{}/{}'.format(
endpoint,
tools.encode_domain(unicode_domain),
))
webapp.get('/api/to_hex/{}'.format(unicode_domain.encode('idna')))

0 comments on commit b9433a8

Please sign in to comment.