Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test framework #122

Merged
merged 21 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
468742a
Beginning of work to develop a tox configuration for testing
IanLee1521 Sep 20, 2017
c4215d5
Added tox dependency to requirements.txt
IanLee1521 Sep 20, 2017
3a1c323
Added Python 3.6 classifier
IanLee1521 Sep 20, 2017
425c436
Updated tox.ini to include testing py3.4, py3.5 and running flake8
IanLee1521 Sep 20, 2017
a089f85
Dont fail on missing interpreters
IanLee1521 Sep 20, 2017
11b2766
Use pytest as test runner
IanLee1521 Sep 20, 2017
83181cd
Created first set of tests
IanLee1521 Sep 20, 2017
e91bcc9
Fixed test cases to properly assert state
IanLee1521 Sep 21, 2017
25e659f
Enable running pytest tests in travis build
IanLee1521 Sep 28, 2017
f887558
Converted to use pytest-cov package for test coverage
IanLee1521 Sep 28, 2017
17fbe24
Apparently, need to explicitly install pshtt to get pytest to work right
IanLee1521 Sep 28, 2017
049ea38
Updated tox.ini to use pytest-cov
IanLee1521 Sep 29, 2017
d60362d
Run coveralls command in Travis
IanLee1521 Sep 30, 2017
a047a0d
Merge remote-tracking branch 'upstream/master' into test-framework
IanLee1521 Sep 30, 2017
2043167
Added Travis CI build status badge
IanLee1521 Sep 30, 2017
654805d
Added test cases for `is_live()`
IanLee1521 Oct 1, 2017
0bdcd52
Skip the live tests against badssl for now
IanLee1521 Oct 2, 2017
5c25c05
Merge remote-tracking branch 'upstream/master' into test-framework
IanLee1521 Oct 2, 2017
2108ff0
Added a new set of tests for definitions
IanLee1521 Oct 7, 2017
fd8f851
Merge remote-tracking branch 'upstream/master' into test-framework
IanLee1521 Oct 19, 2017
c098879
Only run coveralls on testing success
IanLee1521 Oct 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ python:
- '3.6'

install:
- pip install flake8
- pip install -r requirements.txt
- pip install flake8
- pip install pytest-cov pytest coveralls
- pip install -e .

script:
- pytest --cov=pshtt
- flake8 .

after_success:
- coveralls
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ requests_cache
pytablewriter
publicsuffix
pyopenssl==17.2.0
tox
pytest
60 changes: 60 additions & 0 deletions tests/test_badssl.py
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()
89 changes: 89 additions & 0 deletions tests/test_definitions.py
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))
74 changes: 74 additions & 0 deletions tests/test_pshtt.py
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()
15 changes: 15 additions & 0 deletions tox.ini
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