diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2016-02-11 09:45:34 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2016-02-11 09:46:43 +0100 |
commit | d8842e7e7ad415045bf230bc52efa90d3e717099 (patch) | |
tree | 5dce965ce605b770d96e3485d829bb393be75e0e /service/test | |
parent | 92fde6a1669f7023dd5c32c1de6edd506633be85 (diff) |
Redownload SMTP certficates if necessary
- Issue #591
- using leaps should_redownload for check
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/unit/bitmask_libraries/test_smtp_client_certificate.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/service/test/unit/bitmask_libraries/test_smtp_client_certificate.py b/service/test/unit/bitmask_libraries/test_smtp_client_certificate.py index 1a57487a..155f46e9 100644 --- a/service/test/unit/bitmask_libraries/test_smtp_client_certificate.py +++ b/service/test/unit/bitmask_libraries/test_smtp_client_certificate.py @@ -18,6 +18,7 @@ import unittest import tempdir from pixelated.bitmask_libraries import session from leap.srp_session import SRPSession +import leap.common.certs as certs from mockito import mock, unstub, when, verify, never, any as ANY from pixelated.bitmask_libraries.session import SmtpClientCertificate @@ -31,29 +32,35 @@ class TestSmtpClientCertificate(unittest.TestCase): self.provider.domain = 'some-provider.tld' self.auth = SRPSession('username', 'token', 'uuid', 'session_id') self.pem_path = os.path.join(self.tmp_dir.name, 'providers', 'some-provider.tld', 'keys', 'client', 'smtp.pem') + self.downloader = mock() + when(session).SmtpCertDownloader(self.provider, self.auth).thenReturn(self.downloader) def tearDown(self): self.tmp_dir.dissolve() unstub() def test_download_certificate(self): - downloader = mock() - when(session).SmtpCertDownloader(self.provider, self.auth).thenReturn(downloader) - cert = SmtpClientCertificate(self.provider, self.auth, self.tmp_dir.name) result = cert.cert_path() self.assertEqual(self.pem_path, result) - verify(downloader).download_to(self.pem_path) - - def test_skip_download_if_already_downloaded(self): + verify(self.downloader).download_to(self.pem_path) - downloader = mock() - when(session).SmtpCertDownloader(self.provider, self.auth).thenReturn(downloader) + def test_download_certificate_if_redownload_necessary(self): when(os.path).exists(self.pem_path).thenReturn(True) + when(certs).should_redownload(self.pem_path).thenReturn(True) + + cert = SmtpClientCertificate(self.provider, self.auth, self.tmp_dir.name) + result = cert.cert_path() + + self.assertEqual(self.pem_path, result) + verify(self.downloader).download_to(self.pem_path) + def test_skip_download_if_already_downloaded_and_still_valid(self): + when(os.path).exists(self.pem_path).thenReturn(True) + when(certs).should_redownload(ANY()).thenReturn(False) cert = SmtpClientCertificate(self.provider, self.auth, self.tmp_dir.name) result = cert.cert_path() self.assertEqual(self.pem_path, result) - verify(downloader, never).download_to(ANY()) + verify(self.downloader, never).download_to(ANY()) |