-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from IanLee1521/test-framework
Test framework
- Loading branch information
Showing
6 changed files
with
247 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -6,3 +6,5 @@ requests_cache | |
pytablewriter | ||
publicsuffix | ||
pyopenssl==17.2.0 | ||
tox | ||
pytest |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import unittest | ||
|
||
from pshtt.models import Domain, Endpoint | ||
from pshtt.pshtt import basic_check, hsts_check | ||
|
||
|
||
def inspect(base_domain): | ||
""" | ||
Mostly copied from pshtt.pshtt.inspect() | ||
""" | ||
domain = Domain(base_domain) | ||
domain.http = Endpoint("http", "root", base_domain) | ||
domain.httpwww = Endpoint("http", "www", base_domain) | ||
domain.https = Endpoint("https", "root", base_domain) | ||
domain.httpswww = Endpoint("https", "www", base_domain) | ||
|
||
return domain | ||
|
||
# Analyze HTTP endpoint responsiveness and behavior. | ||
basic_check(domain.http) | ||
basic_check(domain.httpwww) | ||
basic_check(domain.https) | ||
basic_check(domain.httpswww) | ||
|
||
# Analyze HSTS header, if present, on each HTTPS endpoint. | ||
hsts_check(domain.https) | ||
hsts_check(domain.httpswww) | ||
|
||
return domain | ||
|
||
|
||
@unittest.skip('Disable live tests against badssl for now') | ||
class TestCertificate(unittest.TestCase): | ||
def test_https_expired(self): | ||
domain = inspect('expired.badssl.com') | ||
basic_check(domain.https) | ||
|
||
self.assertTrue(domain.https.https_expired_cert) | ||
|
||
def test_https_bad_hostname(self): | ||
domain = inspect('wrong.host.badssl.com') | ||
basic_check(domain.https) | ||
|
||
self.assertTrue(domain.https.https_bad_hostname) | ||
|
||
def test_https_bad_chain(self): | ||
domain = inspect('untrusted-root.badssl.com') | ||
basic_check(domain.https) | ||
|
||
self.assertTrue(domain.https.https_bad_chain) | ||
|
||
def test_https_self_signed_cert(self): | ||
domain = inspect('self-signed.badssl.com') | ||
basic_check(domain.https) | ||
|
||
self.assertTrue(domain.https.https_self_signed_cert) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import unittest | ||
|
||
from pshtt.models import Domain, Endpoint | ||
from pshtt import pshtt as api | ||
|
||
|
||
class TestUsesHTTPS(unittest.TestCase): | ||
def setUp(self): | ||
base_domain = 'example.com' | ||
self.domain = Domain(base_domain) | ||
|
||
self.domain.http = Endpoint("http", "root", base_domain) | ||
self.domain.httpwww = Endpoint("http", "www", base_domain) | ||
self.domain.https = Endpoint("https", "root", base_domain) | ||
self.domain.httpswww = Endpoint("https", "www", base_domain) | ||
|
||
@unittest.skip('Still working on definition') | ||
def test_definition(self): | ||
self.domain.https.live = True | ||
self.domain.https.https_valid = True | ||
self.domain.https.https_valid = True | ||
|
||
self.assertTrue(api.is_domain_supports_https(self.domain)) | ||
|
||
|
||
class TestBadChain(unittest.TestCase): | ||
def setUp(self): | ||
base_domain = 'example.com' | ||
self.domain = Domain(base_domain) | ||
|
||
self.domain.http = Endpoint("http", "root", base_domain) | ||
self.domain.httpwww = Endpoint("http", "www", base_domain) | ||
self.domain.https = Endpoint("https", "root", base_domain) | ||
self.domain.httpswww = Endpoint("https", "www", base_domain) | ||
|
||
def test_bad_chain_root(self): | ||
self.domain.https.https_bad_chain = True | ||
self.domain.canonical = self.domain.https | ||
|
||
self.assertTrue(api.is_bad_chain(self.domain)) | ||
|
||
def test_bad_chain_www(self): | ||
self.domain.httpswww.https_bad_chain = True | ||
self.domain.canonical = self.domain.httpswww | ||
|
||
self.assertTrue(api.is_bad_chain(self.domain)) | ||
|
||
def test_bad_chain_both(self): | ||
self.domain.https.https_bad_chain = True | ||
self.domain.httpswww.https_bad_chain = True | ||
|
||
self.domain.canonical = self.domain.https | ||
self.assertTrue(api.is_bad_chain(self.domain)) | ||
|
||
self.domain.canonical = self.domain.httpswww | ||
self.assertTrue(api.is_bad_chain(self.domain)) | ||
|
||
|
||
class TestBadHostname(unittest.TestCase): | ||
def setUp(self): | ||
base_domain = 'example.com' | ||
self.domain = Domain(base_domain) | ||
|
||
self.domain.http = Endpoint("http", "root", base_domain) | ||
self.domain.httpwww = Endpoint("http", "www", base_domain) | ||
self.domain.https = Endpoint("https", "root", base_domain) | ||
self.domain.httpswww = Endpoint("https", "www", base_domain) | ||
|
||
def test_bad_hostname_root(self): | ||
self.domain.https.https_bad_hostname = True | ||
self.domain.canonical = self.domain.https | ||
|
||
self.assertTrue(api.is_bad_hostname(self.domain)) | ||
|
||
def test_bad_hostname_www(self): | ||
self.domain.httpswww.https_bad_hostname = True | ||
self.domain.canonical = self.domain.httpswww | ||
|
||
self.assertTrue(api.is_bad_hostname(self.domain)) | ||
|
||
def test_bad_hostname_both(self): | ||
self.domain.https.https_bad_hostname = True | ||
self.domain.httpswww.https_bad_hostname = True | ||
|
||
self.domain.canonical = self.domain.https | ||
self.assertTrue(api.is_bad_hostname(self.domain)) | ||
|
||
self.domain.canonical = self.domain.httpswww | ||
self.assertTrue(api.is_bad_hostname(self.domain)) |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import unittest | ||
|
||
from pshtt.models import Domain, Endpoint | ||
from pshtt.pshtt import is_live | ||
|
||
|
||
class TestLiveliness(unittest.TestCase): | ||
def setUp(self): | ||
base_domain = 'example.com' | ||
self.domain = Domain(base_domain) | ||
|
||
self.domain.http = Endpoint("http", "root", base_domain) | ||
self.domain.httpwww = Endpoint("http", "www", base_domain) | ||
self.domain.https = Endpoint("https", "root", base_domain) | ||
self.domain.httpswww = Endpoint("https", "www", base_domain) | ||
|
||
def test_none(self): | ||
self.assertFalse(is_live(self.domain)) | ||
|
||
def test_http_only(self): | ||
self.domain.http.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
def test_https_only(self): | ||
self.domain.https.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
def test_httpwww_only(self): | ||
self.domain.httpwww.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
def test_httpswww_only(self): | ||
self.domain.httpswww.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
def test_http_both(self): | ||
self.domain.http.live = True | ||
self.domain.httpwww.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
def test_https_both(self): | ||
self.domain.https.live = True | ||
self.domain.httpswww.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
def test_www_neither(self): | ||
self.domain.http.live = True | ||
self.domain.https.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
def test_www_both(self): | ||
self.domain.httpwww.live = True | ||
self.domain.httpswww.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
def test_all(self): | ||
self.domain.http.live = True | ||
self.domain.https.live = True | ||
self.domain.httpwww.live = True | ||
self.domain.httpswww.live = True | ||
|
||
self.assertTrue(is_live(self.domain)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[tox] | ||
envlist = py27,py34,py35,py36,flake8 | ||
skip_missing_interpreters = true | ||
; usedevelop = true | ||
|
||
[testenv] | ||
deps = | ||
pytest-cov | ||
pytest | ||
coveralls | ||
commands = pytest --cov=pshtt | ||
|
||
[testenv:flake8] | ||
deps = flake8 | ||
commands = flake8 |