diff --git a/README.md b/README.md index a59aa7c8d..732c5169b 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ In general: ``` sudo apt-get install python python-setuptools python-virtualenv \ - python-dev gcc swig dialog libaugeas0 libssl-dev + python-dev gcc swig dialog libaugeas0 libssl-dev openssl ``` #### Mac OSX diff --git a/letsencrypt/client/tests/validator_test.py b/letsencrypt/client/tests/validator_test.py index c6561bdf3..1d3acfc8d 100644 --- a/letsencrypt/client/tests/validator_test.py +++ b/letsencrypt/client/tests/validator_test.py @@ -1,5 +1,48 @@ import unittest +import responses +from requests.exceptions import ConnectionError +from letsencrypt.client.errors import LetsEncryptValidationError + +from letsencrypt.client.validator import Validator + + +def _add(secure=False, **kwargs): + url = "{}://test.com".format("https" if secure else "http") + print(url) + return responses.add(responses.GET, url, **kwargs) + class ValidatorTest(unittest.TestCase): - pass + @responses.activate + def test_succesful_redirect(self): + _add(status=301, adding_headers={"location": "https://test.com"}) + self.assertTrue(Validator().redirect("test.com")) + + @responses.activate + def test_redirect_missing_location(self): + _add(status=301) + self.assertFalse(Validator().redirect("test.com")) + + @responses.activate + def test_redirect_wrong_status_code(self): + _add(status=201, adding_headers={"location": "https://test.com"}) + self.assertFalse(Validator().redirect("test.com")) + + @responses.activate + def test_redirect_wrong_redirect_code(self): + _add(status=303, adding_headers={"location": "https://test.com"}) + self.assertRaises(LetsEncryptValidationError, Validator().redirect, "test.com") + + @responses.activate + def test_https_fail(self): + self.assertRaises(ConnectionError, Validator().https, "test.com") + + @responses.activate + def test_https_success(self): + _add(secure=True, body="blaa") + self.assertTrue(Validator().https("test.com")) + + +if __name__ == '__main__': + unittest.main() diff --git a/requirements.txt b/requirements.txt index a95a0807f..37993ae3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +responses==0.3.0 M2Crypto==0.22.3 python2-pythondialog jsonschema==2.4.0