diff options
author | Bruno Wagner <bwgpro@gmail.com> | 2015-06-08 20:34:29 -0300 |
---|---|---|
committer | Bruno Wagner <bwgpro@gmail.com> | 2015-06-08 20:34:29 -0300 |
commit | 006d753c391d82baa634f112e5d8d06b61eeaaeb (patch) | |
tree | 34976371ea9656edde7a05c1aef3cb7b0b355154 /service/test/unit | |
parent | 3e902a70b94d31458c159c641720d38152bbb267 (diff) |
Heavy rework on certs, removed most of it, simplified the logic
Diffstat (limited to 'service/test/unit')
-rw-r--r-- | service/test/unit/bitmask_libraries/test_certs.py | 30 | ||||
-rw-r--r-- | service/test/unit/bitmask_libraries/test_nicknym.py | 21 | ||||
-rw-r--r-- | service/test/unit/bitmask_libraries/test_provider.py | 18 |
3 files changed, 36 insertions, 33 deletions
diff --git a/service/test/unit/bitmask_libraries/test_certs.py b/service/test/unit/bitmask_libraries/test_certs.py index 814f083f..150a1f14 100644 --- a/service/test/unit/bitmask_libraries/test_certs.py +++ b/service/test/unit/bitmask_libraries/test_certs.py @@ -1,33 +1,27 @@ import unittest from pixelated.bitmask_libraries.certs import LeapCertificate -from pixelated.bitmask_libraries.config import AUTO_DETECT_CA_BUNDLE from mock import MagicMock, patch class CertsTest(unittest.TestCase): - @patch('pixelated.bitmask_libraries.certs.os.path.isfile') - @patch('pixelated.bitmask_libraries.certs.os.path.isdir') - def test_that_which_bootstrap_cert_bundle_returns_string(self, mock_isdir, mock_isfile): - mock_isfile.return_value = True - mock_isdir.return_value = True - config = MagicMock(bootstrap_ca_cert_bundle=AUTO_DETECT_CA_BUNDLE, leap_home='/leap/home') - provider = MagicMock(server_name=u'test.leap.net', config=config) + def test_set_cert_and_fingerprint_sets_cert(self): + LeapCertificate.set_cert_and_fingerprint('some cert', None) - bundle = LeapCertificate(provider).auto_detect_bootstrap_ca_bundle() + self.assertIsNone(LeapCertificate.LEAP_FINGERPRINT) + self.assertEqual('some cert', LeapCertificate.LEAP_CERT) - self.assertEqual('/leap/home/providers/test.leap.net/test.leap.net.ca.crt', bundle) + def test_set_cert_and_fingerprint_sets_fingerprint(self): + LeapCertificate.set_cert_and_fingerprint(None, 'fingerprint') - @patch('pixelated.bitmask_libraries.certs.os.path.isfile') - @patch('pixelated.bitmask_libraries.certs.os.path.isdir') - def test_that_which_bundle_returns_string(self, mock_isdir, mock_isfile): - mock_isfile.return_value = True - mock_isdir.return_value = True + self.assertEqual('fingerprint', LeapCertificate.LEAP_FINGERPRINT) + self.assertFalse(LeapCertificate.LEAP_CERT) - config = MagicMock(bootstrap_ca_cert_bundle=AUTO_DETECT_CA_BUNDLE, ca_cert_bundle=None, leap_home='/some/leap/home') + def test_api_ca_bundle(self): + config = MagicMock(leap_home='/some/leap/home') provider = MagicMock(server_name=u'test.leap.net', config=config) - bundle = LeapCertificate(provider).api_ca_bundle() + cert = LeapCertificate(provider).api_ca_bundle - self.assertEqual('/some/leap/home/providers/test.leap.net/keys/client/api.pem', bundle) + self.assertEqual('/some/leap/home/providers/test.leap.net/keys/client/api.pem', cert) diff --git a/service/test/unit/bitmask_libraries/test_nicknym.py b/service/test/unit/bitmask_libraries/test_nicknym.py index b892c22c..4e683494 100644 --- a/service/test/unit/bitmask_libraries/test_nicknym.py +++ b/service/test/unit/bitmask_libraries/test_nicknym.py @@ -15,16 +15,17 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from mock import patch +from test_abstract_leap import AbstractLeapTest from leap.keymanager import openpgp, KeyNotFound from pixelated.bitmask_libraries.nicknym import NickNym -from test_abstract_leap import AbstractLeapTest +from pixelated.bitmask_libraries.certs import LeapCertificate class NickNymTest(AbstractLeapTest): @patch('pixelated.bitmask_libraries.nicknym.KeyManager.__init__', return_value=None) - def test_that_keymanager_is_created(self, init_mock): + def test_that_keymanager_is_created(self, keymanager_init_mock): # given - + LeapCertificate.api_ca_bundle = '/some/path/to/provider_ca_cert' # when NickNym(self.provider, self.config, @@ -34,10 +35,16 @@ class NickNymTest(AbstractLeapTest): self.auth.uuid) # then - init_mock.assert_called_with('test_user@some-server.test', 'https://nicknym.some-server.test:6425/', - self.soledad, self.auth.token, '/some/path/to/provider_ca_cert', - 'https://api.some-server.test:4430', '1', self.auth.uuid, - '/path/to/gpg') + keymanager_init_mock.assert_called_with( + 'test_user@some-server.test', + 'https://nicknym.some-server.test:6425/', + self.soledad, + self.auth.token, + '/some/path/to/provider_ca_cert', + 'https://api.some-server.test:4430', + '1', + self.auth.uuid, + '/path/to/gpg') @patch('pixelated.bitmask_libraries.nicknym.KeyManager') def test_gen_key(self, keymanager_mock): diff --git a/service/test/unit/bitmask_libraries/test_provider.py b/service/test/unit/bitmask_libraries/test_provider.py index 49627565..320fece2 100644 --- a/service/test/unit/bitmask_libraries/test_provider.py +++ b/service/test/unit/bitmask_libraries/test_provider.py @@ -20,6 +20,7 @@ from httmock import all_requests, HTTMock, urlmatch from requests import HTTPError from pixelated.bitmask_libraries.config import LeapConfig from pixelated.bitmask_libraries.provider import LeapProvider +from pixelated.bitmask_libraries.certs import LeapCertificate from test_abstract_leap import AbstractLeapTest from requests import Session import requests @@ -139,7 +140,8 @@ BOOTSTRAP_CA_CERT = '/tmp/bootstrap-ca.crt' class LeapProviderTest(AbstractLeapTest): def setUp(self): - self.config = LeapConfig(verify_ssl=False, leap_home='/tmp/foobar', bootstrap_ca_cert_bundle=BOOTSTRAP_CA_CERT, ca_cert_bundle=CA_CERT) + self.config = LeapConfig(leap_home='/tmp/foobar') + LeapCertificate.set_cert_and_fingerprint(BOOTSTRAP_CA_CERT, None) def test_provider_fetches_provider_json(self): with HTTMock(provider_json_mock): @@ -195,6 +197,7 @@ class LeapProviderTest(AbstractLeapTest): session = MagicMock(wraps=requests.session()) session_func = MagicMock(return_value=session) get_func = MagicMock(wraps=requests.get) + LeapCertificate.LEAP_CERT = BOOTSTRAP_CA_CERT with patch('pixelated.bitmask_libraries.provider.requests.session', new=session_func): with patch('pixelated.bitmask_libraries.provider.requests.get', new=get_func): @@ -207,24 +210,23 @@ class LeapProviderTest(AbstractLeapTest): def test_that_provider_cert_is_used_to_fetch_soledad_json(self): get_func = MagicMock(wraps=requests.get) + LeapCertificate.api_ca_bundle = CA_CERT with patch('pixelated.bitmask_libraries.provider.requests.get', new=get_func): with HTTMock(provider_json_mock, soledad_json_mock, not_found_mock): provider = LeapProvider('some-provider.test', self.config) provider.fetch_soledad_json() - get_func.assert_called_with('https://api.some-provider.test:4430/1/config/soledad-service.json', verify=CA_CERT, timeout=15) def test_that_leap_fingerprint_is_validated(self): session = MagicMock(wraps=requests.session()) session_func = MagicMock(return_value=session) + LeapCertificate.set_cert_and_fingerprint(None, 'some fingerprint') - with patch('pixelated.bitmask_libraries.certs.LeapCertificate.LEAP_FINGERPRINT', return_value='some fingerprint'): - with patch('pixelated.bitmask_libraries.provider.requests.session', new=session_func): - with patch('pixelated.bitmask_libraries.certs.LeapCertificate.auto_detect_bootstrap_ca_bundle', return_value=False): - with HTTMock(provider_json_mock, ca_cert_mock, not_found_mock): - provider = LeapProvider('some-provider.test', self.config) - provider.fetch_valid_certificate() + with patch('pixelated.bitmask_libraries.provider.requests.session', new=session_func): + with HTTMock(provider_json_mock, ca_cert_mock, not_found_mock): + provider = LeapProvider('some-provider.test', self.config) + provider.fetch_valid_certificate() session.get.assert_any_call('https://some-provider.test/ca.crt', verify=False, timeout=15) session.mount.assert_called_with('https://', ANY) |