diff options
author | NavaL <ayoyo@thoughtworks.com> | 2016-11-21 14:23:20 +0100 |
---|---|---|
committer | Thais Siqueira <thais.siqueira@gmail.com> | 2017-01-02 14:29:45 -0200 |
commit | 56a0db46f2e53c453b8c5e67202601f7dac6c0b5 (patch) | |
tree | 2c9c785f4be54efac139bb45cd25e98bf64a9bbd /service/test/unit | |
parent | 7f7cb59a38a3be3d486bafc810133b584d7fd7a7 (diff) |
[#815] regenerating new keys when the current one expires
Diffstat (limited to 'service/test/unit')
-rw-r--r-- | service/test/unit/bitmask_libraries/test_keymanager.py | 22 | ||||
-rw-r--r-- | service/test/unit/config/test_leap.py | 2 |
2 files changed, 11 insertions, 13 deletions
diff --git a/service/test/unit/bitmask_libraries/test_keymanager.py b/service/test/unit/bitmask_libraries/test_keymanager.py index 6b7c114e..c788697c 100644 --- a/service/test/unit/bitmask_libraries/test_keymanager.py +++ b/service/test/unit/bitmask_libraries/test_keymanager.py @@ -28,7 +28,8 @@ class KeymanagerTest(TestCase): self.provider = MagicMock() self.soledad = MagicMock() self.auth = MagicMock(token='token', auth='auth') - with patch('pixelated.bitmask_libraries.keymanager.KeyManager'): + self.leap_keymanager = MagicMock() + with patch('pixelated.bitmask_libraries.keymanager.KeyManager', return_value=self.leap_keymanager): self.keymanager = Keymanager(self.provider, self.soledad, 'test_user@some-server.test', @@ -108,33 +109,30 @@ class KeymanagerTest(TestCase): with self.assertRaises(UploadKeyError): yield self.keymanager.generate_openpgp_key() - self.keymanager.delete_key_pair.assert_called_once_with('test_user@some-server.test') + self.keymanager.delete_key_pair.assert_called_once() + @defer.inlineCallbacks def test_keymanager_regenerate_key_pair_if_current_key_expired(self): mock_open_pgp_key = MagicMock() mock_open_pgp_key.has_expired = MagicMock(return_value=True) when(self.keymanager)._key_exists('test_user@some-server.test').thenReturn(mock_open_pgp_key) - self.keymanager._regenerate_key = MagicMock() - self.keymanager._send_key_to_leap = MagicMock() - - self.keymanager.generate_openpgp_key() + yield self.keymanager.generate_openpgp_key() - self.keymanager._regenerate_key.assert_called_once() - self.keymanager._send_key_to_leap.assert_called_once() + self.leap_keymanager.regenerate_key.assert_called_once() + self.leap_keymanager.send_key.assert_called_once() @defer.inlineCallbacks def test_key_regeneration_does_not_delete_key_when_upload_fails(self): mock_open_pgp_key = MagicMock() mock_open_pgp_key.has_expired = MagicMock(return_value=True) - when(self.keymanager)._key_exists('test_user@some-server.test').thenReturn(mock_open_pgp_key) + self.leap_keymanager.get_key = MagicMock(return_value=defer.succeed(mock_open_pgp_key)) + self.leap_keymanager.send_key = MagicMock(side_effect=UploadKeyError('Could not upload key')) - self.keymanager._regenerate_key = MagicMock() self.keymanager.delete_key_pair = MagicMock() - when(self.keymanager)._send_key_to_leap().thenRaise(UploadKeyError('Could not upload key')) with self.assertRaises(UploadKeyError): yield self.keymanager.generate_openpgp_key() - self.keymanager._regenerate_key.assert_called_once() + self.leap_keymanager.regenerate_key.assert_called_once() self.keymanager.delete_key_pair.assert_not_called() diff --git a/service/test/unit/config/test_leap.py b/service/test/unit/config/test_leap.py index a6893194..7e073d26 100644 --- a/service/test/unit/config/test_leap.py +++ b/service/test/unit/config/test_leap.py @@ -18,7 +18,7 @@ class TestLeapInit(unittest.TestCase): with patch.object(LeapSessionFactory, '_create_new_session', return_value=session): yield create_leap_session(provider_mock, 'username', 'password', auth=auth_mock) - session.first_required_sync.assert_called_with() + session.first_required_sync.assert_called_once() self.assertEqual({'mocked key': session}, SessionCache.sessions) @patch('pixelated.config.sessions.SessionCache.lookup_session') |