-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: signatures * fix: signature Wordpress is a bit annoying and needs cnames with at least one alpha character. Need to revisit * fix: cnames always have an alpha
- Loading branch information
1 parent
0770f96
commit 0bfa004
Showing
7 changed files
with
145 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from .templates.cname_found_but_status_code import cname_found_but_status_code | ||
|
||
test = cname_found_but_status_code( | ||
cname="cname.launchrock.com", | ||
code=500, | ||
service="Launchrock", | ||
https=True, | ||
) | ||
from .templates.cname_found_but_status_code import cname_found_but_status_code | ||
|
||
test = cname_found_but_status_code( | ||
cname="host.launchrock.com", | ||
code=0, | ||
service="Launchrock", | ||
https=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
from .templates.cname_or_ip_found_but_string_in_body import ( | ||
cname_or_ip_found_but_string_in_body, | ||
) | ||
|
||
ipv4 = ["23.227.38.65"] | ||
ipv6 = [] | ||
|
||
cname = "shops.myshopify.com" | ||
|
||
test = cname_or_ip_found_but_string_in_body( | ||
cname=cname, | ||
ips=ipv4 + ipv6, | ||
domain_not_configured_message="Only one step left!", | ||
service="Shopify", | ||
) | ||
|
||
# https://help.shopify.com/en/manual/domains/add-a-domain/connecting-domains/connect-domain-manual#step-1-change-your-dns-records-in-your-third-party-domain-provider-account | ||
from .templates.cname_or_ip_found_but_string_in_body import ( | ||
cname_or_ip_found_but_string_in_body, | ||
) | ||
|
||
ipv4 = ["23.227.38.65"] | ||
ipv6 = [] | ||
|
||
cname = "shops.myshopify.com" | ||
|
||
test = cname_or_ip_found_but_string_in_body( | ||
cname=cname, | ||
ips=ipv4 + ipv6, | ||
domain_not_configured_message="Create an Ecommerce Website and Sell Online! Ecommerce Software by Shopify", | ||
service="Shopify", | ||
) | ||
|
||
# https://help.shopify.com/en/manual/domains/add-a-domain/connecting-domains/connect-domain-manual#step-1-change-your-dns-records-in-your-third-party-domain-provider-account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from .templates.cname_found_but_string_in_body import cname_found_but_string_in_body | ||
|
||
test = cname_found_but_string_in_body( | ||
cname="cname.smartjobboard.com", | ||
domain_not_configured_message="404 Not Found", | ||
service="smartjobboard.com", | ||
https=True, | ||
) | ||
from .templates.ip_found_but_string_in_body import ip_found_but_string_in_body | ||
|
||
test = ip_found_but_string_in_body( | ||
ips=["52.16.160.97"], | ||
domain_not_configured_message="job board website is either expired or its domain name is invalid.", | ||
service="smartjobboard.com", | ||
https=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from .templates.cname_found_but_string_in_body import cname_found_but_string_in_body | ||
|
||
test = cname_found_but_string_in_body( | ||
cname="cname.wishpond.com", | ||
domain_not_configured_message="https://www.wishpond.com/404?campaign=true", | ||
service="wishpond.com", | ||
) | ||
from .templates.cname_found_but_string_in_body import cname_found_but_string_in_body | ||
|
||
test = cname_found_but_string_in_body( | ||
cname="cname.wishpond.com", | ||
domain_not_configured_message="https://www.wishpond.com/404?campaign=true", | ||
service="wishpond.com", | ||
https=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from .templates.cname_found_but_string_in_body import cname_found_but_string_in_body | ||
|
||
test = cname_found_but_string_in_body( | ||
cname=".wordpress.com", | ||
domain_not_configured_message="Do you want to register", | ||
service="wordpress.com", | ||
) | ||
from .templates.cname_found_but_string_in_body import cname_found_but_string_in_body | ||
|
||
test = cname_found_but_string_in_body( | ||
cname=".wordpress.com", | ||
domain_not_configured_message="Do you want to register", | ||
service="wordpress.com", | ||
https=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,94 @@ | ||
from collections import namedtuple | ||
from domain import Domain | ||
import requests | ||
import dns.resolver | ||
import ipaddress | ||
from uuid import uuid4 | ||
|
||
|
||
def random_string(): | ||
return uuid4().hex[:8] | ||
|
||
|
||
def mock_web_response_with_static_value( | ||
domain: Domain, body: str = "", status_code: int = 0 | ||
) -> Domain: | ||
def mock_fetch_web(**kwargs): | ||
return namedtuple("web_response", ["body", "status_code"])(body, status_code) | ||
|
||
domain.fetch_web = mock_fetch_web | ||
|
||
|
||
def mock_web_request_by_providing_static_host_resolution( | ||
domain: Domain, hostname: str | ||
) -> Domain: | ||
requests_adapter = HostHeaderAdapter() | ||
requests_adapter.set_static_host_resolution(hostname) | ||
patched_requests = requests.session() | ||
patched_requests.mount("https://", requests_adapter) | ||
patched_requests.mount("http://", requests_adapter) | ||
domain.requests = patched_requests | ||
|
||
|
||
def mock_web_request_by_providing_custom_ns(domain: Domain, ns: str) -> Domain: | ||
requests_adapter = HostHeaderAdapter() | ||
requests_adapter.set_ns_for_resolution(ns) | ||
patched_requests = requests.session() | ||
patched_requests.mount("https://", requests_adapter) | ||
patched_requests.mount("http://", requests_adapter) | ||
domain.requests = patched_requests | ||
|
||
|
||
class HostHeaderAdapter(requests.adapters.HTTPAdapter): | ||
def set_static_host_resolution(self, host): | ||
self.host = self.resolve_to_ip(host) | ||
|
||
def set_ns_for_resolution(self, ns): | ||
self.ns = self.resolve_to_ip(ns) | ||
|
||
def resolve_via_ns(self, domain): | ||
resolver = dns.resolver.Resolver() | ||
resolver.nameservers = [self.ns] | ||
response = resolver.resolve(domain) | ||
return [record.to_text() for record in response][0] | ||
|
||
def resolve_to_ip(self, name): | ||
try: | ||
# return the name if its already an ip | ||
ipaddress.ip_address(name) | ||
return name | ||
except: | ||
response = dns.resolver.resolve(name) | ||
ip = [record.to_text() for record in response][0] | ||
return self.resolve_to_ip(ip) | ||
|
||
def wrap_if_ipv6(self, ip): | ||
if ip.count(":") > 1: | ||
return f"[{ip}]" | ||
return ip | ||
|
||
def send(self, request, **kwargs): | ||
from urllib.parse import urlparse | ||
|
||
connection_pool_kwargs = self.poolmanager.connection_pool_kw | ||
result = urlparse(request.url) | ||
try: | ||
# Try use a static ip | ||
resolved_ip = self.host | ||
except: | ||
# If that fails, try and resolve | ||
resolved_ip = self.resolve_to_ip(result.hostname) | ||
|
||
resolved_ip = self.wrap_if_ipv6(resolved_ip) | ||
|
||
request.url = request.url.replace( | ||
"//" + result.hostname, | ||
"//" + resolved_ip, | ||
) | ||
if "https" in request.url: | ||
connection_pool_kwargs["server_hostname"] = result.hostname # SNI | ||
connection_pool_kwargs["assert_hostname"] = result.hostname | ||
|
||
# overwrite the host header | ||
request.headers["Host"] = result.hostname | ||
return super(HostHeaderAdapter, self).send(request, **kwargs) | ||
from collections import namedtuple | ||
from domain import Domain | ||
import requests | ||
import dns.resolver | ||
import ipaddress | ||
from uuid import uuid4 | ||
|
||
|
||
def random_string(): | ||
return f"a{uuid4().hex[:8]}" | ||
|
||
|
||
def mock_web_response_with_static_value( | ||
domain: Domain, body: str = "", status_code: int = 0 | ||
) -> Domain: | ||
def mock_fetch_web(**kwargs): | ||
return namedtuple("web_response", ["body", "status_code"])(body, status_code) | ||
|
||
domain.fetch_web = mock_fetch_web | ||
|
||
|
||
def mock_web_request_by_providing_static_host_resolution( | ||
domain: Domain, hostname: str | ||
) -> Domain: | ||
requests_adapter = HostHeaderAdapter() | ||
requests_adapter.set_static_host_resolution(hostname) | ||
patched_requests = requests.session() | ||
patched_requests.mount("https://", requests_adapter) | ||
patched_requests.mount("http://", requests_adapter) | ||
domain.requests = patched_requests | ||
|
||
|
||
def mock_web_request_by_providing_custom_ns(domain: Domain, ns: str) -> Domain: | ||
requests_adapter = HostHeaderAdapter() | ||
requests_adapter.set_ns_for_resolution(ns) | ||
patched_requests = requests.session() | ||
patched_requests.mount("https://", requests_adapter) | ||
patched_requests.mount("http://", requests_adapter) | ||
domain.requests = patched_requests | ||
|
||
|
||
class HostHeaderAdapter(requests.adapters.HTTPAdapter): | ||
def set_static_host_resolution(self, host): | ||
self.host = self.resolve_to_ip(host) | ||
|
||
def set_ns_for_resolution(self, ns): | ||
self.ns = self.resolve_to_ip(ns) | ||
|
||
def resolve_via_ns(self, domain): | ||
resolver = dns.resolver.Resolver() | ||
resolver.nameservers = [self.ns] | ||
response = resolver.resolve(domain) | ||
return [record.to_text() for record in response][0] | ||
|
||
def resolve_to_ip(self, name): | ||
try: | ||
# return the name if its already an ip | ||
ipaddress.ip_address(name) | ||
return name | ||
except: | ||
response = dns.resolver.resolve(name) | ||
ip = [record.to_text() for record in response][0] | ||
return self.resolve_to_ip(ip) | ||
|
||
def wrap_if_ipv6(self, ip): | ||
if ip.count(":") > 1: | ||
return f"[{ip}]" | ||
return ip | ||
|
||
def send(self, request, **kwargs): | ||
from urllib.parse import urlparse | ||
|
||
connection_pool_kwargs = self.poolmanager.connection_pool_kw | ||
result = urlparse(request.url) | ||
try: | ||
# Try use a static ip | ||
resolved_ip = self.host | ||
except: | ||
# If that fails, try and resolve | ||
resolved_ip = self.resolve_to_ip(result.hostname) | ||
|
||
resolved_ip = self.wrap_if_ipv6(resolved_ip) | ||
|
||
request.url = request.url.replace( | ||
"//" + result.hostname, | ||
"//" + resolved_ip, | ||
) | ||
if "https" in request.url: | ||
connection_pool_kwargs["server_hostname"] = result.hostname # SNI | ||
connection_pool_kwargs["assert_hostname"] = result.hostname | ||
|
||
# overwrite the host header | ||
request.headers["Host"] = result.hostname | ||
return super(HostHeaderAdapter, self).send(request, **kwargs) |