2021-09-30 16:31:19 -04:00
|
|
|
""" Tests to validate checkcert"""
|
|
|
|
from click.testing import CliRunner
|
2021-09-28 16:44:52 -04:00
|
|
|
from checkcert.checkcert import main as cert_main
|
|
|
|
from checkcert.checkcert import __version__ as cert_version
|
|
|
|
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
|
|
|
|
|
|
def test_main():
|
2021-09-30 16:31:19 -04:00
|
|
|
"""validate the core function returns correctly for:
|
|
|
|
a domain
|
|
|
|
a domain and a port
|
|
|
|
no names specified
|
|
|
|
a list of domains
|
|
|
|
a list of domains with a port specified on one
|
|
|
|
"""
|
|
|
|
response = runner.invoke(cert_main, ["www.franklin.edu"])
|
|
|
|
assert response.exit_code == 0
|
|
|
|
response = runner.invoke(cert_main, ["www.franklin.edu:443"])
|
|
|
|
assert response.exit_code == 0
|
|
|
|
response = runner.invoke(cert_main, ["www.franklin.edu", "--no-color"])
|
|
|
|
assert response.exit_code == 0
|
|
|
|
response = runner.invoke(cert_main, ["www.franklin.edu", "library.franklin.edu"])
|
|
|
|
assert response.exit_code == 0
|
2021-10-04 14:47:45 -04:00
|
|
|
response = runner.invoke(cert_main, ["www.franklin.edu", "--valid"])
|
|
|
|
assert response.exit_code == 0
|
2021-09-30 16:31:19 -04:00
|
|
|
response = runner.invoke(
|
|
|
|
cert_main, ["www.franklin.edu:443", "library.franklin.edu"]
|
|
|
|
)
|
|
|
|
assert response.exit_code == 0
|
2021-09-28 16:44:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_version():
|
2021-09-30 16:31:19 -04:00
|
|
|
"""get the version output and ensure it matches the version var"""
|
2021-09-28 16:44:52 -04:00
|
|
|
response = runner.invoke(cert_main, ["--version"])
|
|
|
|
assert response.exit_code == 0
|
|
|
|
assert cert_version in response.output
|
2021-09-28 16:52:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_dump():
|
2021-09-30 16:31:19 -04:00
|
|
|
"""verify that --dump outputs data"""
|
2021-09-28 16:52:14 -04:00
|
|
|
response = runner.invoke(cert_main, ["www.franklin.edu", "--dump"])
|
|
|
|
assert response.exit_code == 0
|
2021-09-30 16:31:19 -04:00
|
|
|
assert "www.franklin.edu" in response.output
|
2021-09-28 16:52:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_san():
|
2021-09-30 16:31:19 -04:00
|
|
|
"""verify --san outputs correctly"""
|
2021-09-28 16:52:14 -04:00
|
|
|
response = runner.invoke(cert_main, ["www.franklin.edu", "--san"])
|
|
|
|
assert response.exit_code == 0
|
2021-09-30 16:23:00 -04:00
|
|
|
|
|
|
|
|
2021-10-04 09:58:43 -04:00
|
|
|
def test_san_only():
|
|
|
|
"""verify --san outputs correctly"""
|
2021-10-04 14:47:45 -04:00
|
|
|
check_domain = "example.com"
|
2021-10-04 12:09:35 -04:00
|
|
|
response = runner.invoke(cert_main, ["--san-only", check_domain])
|
|
|
|
assert response.exit_code == 0
|
|
|
|
sep_string = ","
|
|
|
|
response = runner.invoke(
|
2021-10-04 14:47:45 -04:00
|
|
|
cert_main, ["--san-only", "--sep", sep_string, check_domain]
|
2021-10-04 12:09:35 -04:00
|
|
|
)
|
|
|
|
assert response.exit_code == 0
|
|
|
|
assert sep_string in response.output
|
|
|
|
response = runner.invoke(
|
2021-10-04 14:47:45 -04:00
|
|
|
cert_main, ["--san-only", "--sep", sep_string, "--pre", check_domain]
|
|
|
|
)
|
|
|
|
assert response.exit_code == 0
|
|
|
|
assert response.output.startswith(sep_string)
|
|
|
|
response = runner.invoke(
|
|
|
|
cert_main, ["--san-only", "--sep", sep_string, "--pre", "cs.franklin.edu"]
|
2021-10-04 12:09:35 -04:00
|
|
|
)
|
2021-10-04 09:58:43 -04:00
|
|
|
assert response.exit_code == 0
|
2021-10-04 14:47:45 -04:00
|
|
|
assert response.output.startswith(sep_string)
|
2021-10-04 09:58:43 -04:00
|
|
|
|
|
|
|
|
2021-09-30 16:23:00 -04:00
|
|
|
def test_bad_cert():
|
2021-09-30 16:31:19 -04:00
|
|
|
"""verify an expired certificate works"""
|
2021-09-30 16:23:00 -04:00
|
|
|
response = runner.invoke(cert_main, ["support.bluequill.com", "--san"])
|
|
|
|
assert response.exit_code == 0
|
2021-10-01 12:19:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_from_file():
|
|
|
|
"""Verify loading domains from file"""
|
|
|
|
response = runner.invoke(cert_main, ["--filename", "ci/test_domains.txt"])
|
|
|
|
assert response.exit_code == 0
|