Esempio n. 1
0
 def test_error_gpg(self, popen, user_exists):
     user_exists.return_value = False
     err_msg = "Error message 123"
     popen.return_value = MockPopenHandle(1, stderr=err_msg)
     with pytest.raises(GpgErrorException) as e:
         logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
         assert e.message == err_msg
Esempio n. 2
0
 def test_error_gpg(self, popen, user_exists):
     user_exists.return_value = False
     err_msg = "Error message 123"
     popen.return_value = MockPopenHandle(1, stderr=err_msg)
     with pytest.raises(GpgErrorException) as e:
         logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
         assert e.message == err_msg
Esempio n. 3
0
    def test_strange_situation_create(self, popen, user_exists):
        """
        After key generation `user_exists` invoked again, and if it doesn't
        see key it should raise an error
        """

        user_exists.return_value = False
        popen.return_value = MockPopenHandle(0)

        with pytest.raises(GpgErrorException):
            logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
Esempio n. 4
0
    def test_strange_situation_create(self, popen, user_exists):
        """
        After key generation `user_exists` invoked again, and if it doesn't
        see key it should raise an error
        """

        user_exists.return_value = False
        popen.return_value = MockPopenHandle(0)

        with pytest.raises(GpgErrorException):
            logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
Esempio n. 5
0
    def test_tmpfiles_errors(self, popen, user_exists):
        user_exists.return_value = False

        with mock.patch("tempfile.NamedTemporaryFile") as tmpfile:
            tmpfile.side_effect = OSError()
            with pytest.raises(KeygenServiceBaseException) as e:
                logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)

            assert not popen.called

        with mock.patch("tempfile.NamedTemporaryFile") as tmpfile:
            tmpfile.return_value.write.side_effect = OSError()
            with pytest.raises(KeygenServiceBaseException) as e:
                logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)

            assert not popen.called
Esempio n. 6
0
    def test_tmpfiles_errors(self, popen, user_exists):
        user_exists.return_value = False

        with mock.patch("tempfile.NamedTemporaryFile") as tmpfile:
            tmpfile.side_effect = OSError()
            with pytest.raises(KeygenServiceBaseException) as e:
                logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)

            assert not popen.called

        with mock.patch("tempfile.NamedTemporaryFile") as tmpfile:
            tmpfile.return_value.write.side_effect = OSError()
            with pytest.raises(KeygenServiceBaseException) as e:
                logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)

            assert not popen.called
Esempio n. 7
0
    def test_simple_create(self, popen, user_exists):
        """
        Check correct key generation.
        """

        with mock.patch("tempfile.NamedTemporaryFile") as tmpfile:
            def check_gpg_genkey_file_exists(*args, **kwargs):
                assert tmpfile.called
                return MockPopenHandle(0)

            popen.side_effect = check_gpg_genkey_file_exists

            res = logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
            assert res is None
Esempio n. 8
0
    def test_simple_create(self, popen, user_exists):
        """
        Check correct key generation.
        At first user not exist, but after popen call,
        it exists
        """

        with mock.patch("tempfile.NamedTemporaryFile") as tmpfile:
            user_exists_returns = [False, True]
            user_exists.side_effect = \
                lambda *args, **kwargs: user_exists_returns.pop(0)

            def check_gpg_genkey_file_exists(*args, **kwargs):
                assert tmpfile.called
                return MockPopenHandle(0)

            popen.side_effect = check_gpg_genkey_file_exists

            res = logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
            assert res is None
Esempio n. 9
0
    def test_simple_create(self, popen, user_exists):
        """
        Check correct key generation.
        At first user not exist, but after popen call,
        it exists
        """

        with mock.patch("tempfile.NamedTemporaryFile") as tmpfile:
            user_exists_returns = [False, True]
            user_exists.side_effect = \
                lambda *args, **kwargs: user_exists_returns.pop(0)

            def check_gpg_genkey_file_exists(*args, **kwargs):
                assert tmpfile.called
                return MockPopenHandle(0)

            popen.side_effect = check_gpg_genkey_file_exists

            res = logic.create_new_key(app, TEST_NAME, TEST_EMAIL,
                                       TEST_KEYLENGTH)
            assert res is None
Esempio n. 10
0
 def test_error_popen(self, popen, user_exists):
     user_exists.return_value = False
     popen.side_effect = OSError()
     with pytest.raises(GpgErrorException):
         logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
Esempio n. 11
0
    def test_skip_creation_for_existing_user(self, popen, user_exists):
        user_exists.return_value = True
        logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)

        user_exists.assert_called_once()
        assert not popen.called
Esempio n. 12
0
 def test_error_popen(self, popen, user_exists):
     user_exists.return_value = False
     popen.side_effect = OSError()
     with pytest.raises(GpgErrorException):
         logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
Esempio n. 13
0
    def test_skip_creation_for_existing_user(self, popen, user_exists):
        user_exists.return_value = True
        logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)

        user_exists.assert_called_once()
        assert not popen.called