Example #1
0
def test_run_test_fails():
    cfile = create_config(("listen=127.0.0.1:0",))
    with mock.patch(
        "sys.argv", ["blackhole", "-t", "-c", cfile]
    ), pytest.raises(SystemExit) as exc:
        run()
    assert exc.value.code == 64
Example #2
0
def test_run_test():
    cfile = create_config(('', ))
    with mock.patch('sys.argv', ['blackhole', '-t', '-c', cfile]), \
        mock.patch('blackhole.config.Config.test_port', return_value=True), \
            pytest.raises(SystemExit) as err:
        run()
    assert str(err.value) == '0'
def test_run_load_test_fails():
    cfile = create_config(("listen=127.0.0.1:0", ))
    with mock.patch("sys.argv", ["blackhole", "-t", "-c", cfile]), mock.patch(
            "blackhole.config.Config.test",
            side_effect=ConfigException()), pytest.raises(SystemExit) as exc:
        run()
    assert exc.value.code == 64
Example #4
0
def test_run_load_test_fails():
    cfile = create_config(("listen=127.0.0.1:0",))
    with mock.patch("sys.argv", ["blackhole", "-t", "-c", cfile]), mock.patch(
        "blackhole.config.Config.test", side_effect=ConfigException()
    ), pytest.raises(SystemExit) as exc:
        run()
    assert exc.value.code == 64
Example #5
0
def test_run_foreground():
    pidfile = os.path.join(os.getcwd(), "blackhole-test.pid")
    cfile = create_config(
        ("listen=127.0.0.1:9000", "pidfile={}".format(pidfile))
    )
    Config(cfile).load()

    with mock.patch("sys.argv", ["-c {}".format(cfile)]), mock.patch(
        "blackhole.config.Config.test"
    ), mock.patch("blackhole.config.warn_options"), mock.patch(
        "atexit.register"
    ), mock.patch(
        "os.chown"
    ), mock.patch(
        "blackhole.supervisor.Supervisor.generate_servers"
    ), mock.patch(
        "blackhole.control.pid_permissions"
    ), mock.patch(
        "blackhole.control.setgid"
    ), mock.patch(
        "blackhole.control.setuid"
    ), mock.patch(
        "blackhole.supervisor.Supervisor.run"
    ), pytest.raises(
        SystemExit
    ) as exc:
        run()
    assert exc.value.code == 0
Example #6
0
def test_run_daemon_daemonize_error():
    pidfile = os.path.join(os.getcwd(), "blackhole-test.pid")
    cfile = create_config(
        ("listen=127.0.0.1:9000", "pidfile={}".format(pidfile))
    )
    Config(cfile).load()

    with mock.patch("sys.argv", ["-c {}".format(cfile), "-b"]), mock.patch(
        "blackhole.config.Config.test"
    ), mock.patch("blackhole.config.warn_options"), mock.patch(
        "atexit.register"
    ), mock.patch(
        "os.chown"
    ), mock.patch(
        "blackhole.supervisor.Supervisor.generate_servers"
    ), mock.patch(
        "os.fork", side_effect=OSError
    ), mock.patch(
        "blackhole.supervisor.Supervisor." "close_socks"
    ) as mock_close, pytest.raises(
        SystemExit
    ) as exc:
        run()
    assert exc.value.code == 77
    assert mock_close.called is True
def test_run_test_fails():
    cfile = create_config(("listen=127.0.0.1:0", ))
    with mock.patch(
            "sys.argv",
        ["blackhole", "-t", "-c", cfile]), pytest.raises(SystemExit) as exc:
        run()
    assert exc.value.code == 64
Example #8
0
def test_run_load_test_fails():
    cfile = create_config(('listen=127.0.0.1:0', ))
    with mock.patch('sys.argv', ['blackhole', '-t', '-c', cfile]), \
        mock.patch('blackhole.config.Config.test',
                   side_effect=ConfigException()), \
            pytest.raises(SystemExit) as err:
        run()
    assert str(err.value) == '64'
def test_run_test():
    cfile = create_config(("", ))
    with mock.patch("sys.argv", ["blackhole", "-t", "-c", cfile]), mock.patch(
            "blackhole.config.Config.test_port",
            return_value=True), mock.patch(
                "blackhole.config.Config.test_pidfile",
                return_value=True), pytest.raises(SystemExit) as exc:
        run()
    assert exc.value.code == 0
Example #10
0
def test_run_test():
    cfile = create_config(("",))
    with mock.patch("sys.argv", ["blackhole", "-t", "-c", cfile]), mock.patch(
        "blackhole.config.Config.test_port", return_value=True
    ), mock.patch(
        "blackhole.config.Config.test_pidfile", return_value=True
    ), pytest.raises(
        SystemExit
    ) as exc:
        run()
    assert exc.value.code == 0
def test_run_foreground_pid_error():
    pidfile = os.path.join(os.getcwd(), "blackhole-test.pid")
    cfile = create_config(
        ("listen=127.0.0.1:9000", "pidfile={}".format(pidfile)))
    Config(cfile).load()

    with mock.patch("sys.argv", ["-c {}".format(cfile)]), mock.patch(
            "blackhole.config.Config.test"
    ), mock.patch("blackhole.config.warn_options"), mock.patch(
            "os.getpid", return_value=1234), mock.patch(
                "atexit.register",
                side_effect=DaemonException), pytest.raises(SystemExit) as exc:
        run()
    assert exc.value.code == 64
Example #12
0
def test_run_foreground_pid_error():
    pidfile = os.path.join(os.getcwd(), 'blackhole-test.pid')
    cfile = create_config(('listen=127.0.0.1:9000',
                           'pidfile={}'.format(pidfile)))
    Config(cfile).load()

    with mock.patch('sys.argv', ['-c {}'.format(cfile)]), \
        mock.patch('blackhole.config.Config.test'), \
        mock.patch('blackhole.config.warn_options'), \
        mock.patch('os.getpid', return_value=1234), \
        mock.patch('atexit.register', side_effect=DaemonException), \
            pytest.raises(SystemExit) as err:
        run()
    assert str(err.value) == '64'
Example #13
0
def test_run_foreground_socket_error():
    pidfile = os.path.join(os.getcwd(), 'blackhole-test.pid')
    cfile = create_config(('listen=127.0.0.1:9000',
                           'pidfile={}'.format(pidfile)))
    Config(cfile).load()

    with mock.patch('sys.argv', ['-c {}'.format(cfile)]), \
        mock.patch('blackhole.config.Config.test'), \
        mock.patch('blackhole.config.warn_options'), \
        mock.patch('atexit.register'), \
        mock.patch('blackhole.supervisor.Supervisor.close_socks'), \
        mock.patch('blackhole.supervisor.Supervisor.generate_servers',
                   side_effect=BlackholeRuntimeException), \
            pytest.raises(SystemExit) as err:
        run()
    assert str(err.value) == '77'
def test_run_foreground_socket_error():
    pidfile = os.path.join(os.getcwd(), "blackhole-test.pid")
    cfile = create_config(
        ("listen=127.0.0.1:9000", "pidfile={}".format(pidfile)))
    Config(cfile).load()

    with mock.patch("sys.argv", [
            "-c {}".format(cfile)
    ]), mock.patch("blackhole.config.Config.test"), mock.patch(
            "blackhole.config.warn_options"), mock.patch(
                "atexit.register"), mock.patch(
                    "blackhole.supervisor.Supervisor.close_socks"), mock.patch(
                        "blackhole.supervisor.Supervisor.generate_servers",
                        side_effect=BlackholeRuntimeException,
                    ), pytest.raises(SystemExit) as exc:
        run()
    assert exc.value.code == 77
Example #15
0
def test_run_foreground_pid_error():
    pidfile = os.path.join(os.getcwd(), "blackhole-test.pid")
    cfile = create_config(
        ("listen=127.0.0.1:9000", "pidfile={}".format(pidfile))
    )
    Config(cfile).load()

    with mock.patch("sys.argv", ["-c {}".format(cfile)]), mock.patch(
        "blackhole.config.Config.test"
    ), mock.patch("blackhole.config.warn_options"), mock.patch(
        "os.getpid", return_value=1234
    ), mock.patch(
        "atexit.register", side_effect=DaemonException
    ), pytest.raises(
        SystemExit
    ) as exc:
        run()
    assert exc.value.code == 64
Example #16
0
def test_run_foreground():
    pidfile = os.path.join(os.getcwd(), 'blackhole-test.pid')
    cfile = create_config(('listen=127.0.0.1:9000',
                           'pidfile={}'.format(pidfile)))
    Config(cfile).load()

    with mock.patch('sys.argv', ['-c {}'.format(cfile)]), \
        mock.patch('blackhole.config.Config.test'), \
        mock.patch('blackhole.config.warn_options'), \
        mock.patch('atexit.register'), \
        mock.patch('os.chown'), \
        mock.patch('blackhole.supervisor.Supervisor.generate_servers'), \
        mock.patch('blackhole.control.pid_permissions'), \
        mock.patch('blackhole.control.setgid'), \
        mock.patch('blackhole.control.setuid'), \
        mock.patch('blackhole.supervisor.Supervisor.run'), \
            pytest.raises(SystemExit) as err:
        run()
    assert str(err.value) == '0'
Example #17
0
def test_run_daemon_daemonize_error():
    pidfile = os.path.join(os.getcwd(), 'blackhole-test.pid')
    cfile = create_config(('listen=127.0.0.1:9000',
                           'pidfile={}'.format(pidfile)))
    Config(cfile).load()

    with mock.patch('sys.argv', ['-c {}'.format(cfile), '-b']), \
        mock.patch('blackhole.config.Config.test'), \
        mock.patch('blackhole.config.warn_options'), \
        mock.patch('atexit.register'), \
        mock.patch('os.chown'), \
        mock.patch('blackhole.supervisor.Supervisor.generate_servers'), \
        mock.patch('os.fork', side_effect=OSError), \
        mock.patch('blackhole.supervisor.Supervisor.'
                   'close_socks') as mock_close, \
            pytest.raises(SystemExit) as err:
        run()
    assert str(err.value) == '77'
    assert mock_close.called is True
def test_run_daemon_daemonize_error():
    pidfile = os.path.join(os.getcwd(), "blackhole-test.pid")
    cfile = create_config(
        ("listen=127.0.0.1:9000", "pidfile={}".format(pidfile)))
    Config(cfile).load()

    with mock.patch(
            "sys.argv",
        ["-c {}".format(cfile), "-b"
         ]), mock.patch("blackhole.config.Config.test"), mock.patch(
             "blackhole.config.warn_options"
         ), mock.patch("atexit.register"), mock.patch("os.chown"), mock.patch(
             "blackhole.supervisor.Supervisor.generate_servers"), mock.patch(
                 "os.fork", side_effect=OSError), mock.patch(
                     "blackhole.supervisor.Supervisor."
                     "close_socks") as mock_close, pytest.raises(
                         SystemExit) as exc:
        run()
    assert exc.value.code == 77
    assert mock_close.called is True
def test_run_foreground():
    pidfile = os.path.join(os.getcwd(), "blackhole-test.pid")
    cfile = create_config(
        ("listen=127.0.0.1:9000", "pidfile={}".format(pidfile)))
    Config(cfile).load()

    with mock.patch(
            "sys.argv",
        ["-c {}".format(cfile)
         ]), mock.patch("blackhole.config.Config.test"), mock.patch(
             "blackhole.config.warn_options"
         ), mock.patch("atexit.register"), mock.patch("os.chown"), mock.patch(
             "blackhole.supervisor.Supervisor.generate_servers"
         ), mock.patch("blackhole.control.pid_permissions"), mock.patch(
             "blackhole.control.setgid"), mock.patch(
                 "blackhole.control.setuid"), mock.patch(
                     "blackhole.supervisor.Supervisor.run"), pytest.raises(
                         SystemExit) as exc:
        run()
    assert exc.value.code == 0
Example #20
0
def test_run_foreground_socket_error():
    pidfile = os.path.join(os.getcwd(), "blackhole-test.pid")
    cfile = create_config(
        ("listen=127.0.0.1:9000", "pidfile={}".format(pidfile))
    )
    Config(cfile).load()

    with mock.patch("sys.argv", ["-c {}".format(cfile)]), mock.patch(
        "blackhole.config.Config.test"
    ), mock.patch("blackhole.config.warn_options"), mock.patch(
        "atexit.register"
    ), mock.patch(
        "blackhole.supervisor.Supervisor.close_socks"
    ), mock.patch(
        "blackhole.supervisor.Supervisor.generate_servers",
        side_effect=BlackholeRuntimeException,
    ), pytest.raises(
        SystemExit
    ) as exc:
        run()
    assert exc.value.code == 77
Example #21
0
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""
Blackhole is an email MTA that pipes all mail to /dev/null.

Blackhole is built on top of asyncio and utilises `async` and `await`
statements on available in Python 3.5 and above.

While Blackhole is an MTA (mail transport agent), none of the actions
performed of SMTP or SMTPS are actually processed and no email or sent or
delivered.
"""

from blackhole.application import run


if __name__ == '__main__':  # pragma: no cover
    run()
Example #22
0
def test_run_test_fails():
    cfile = create_config(('listen=127.0.0.1:0', ))
    with mock.patch('sys.argv', ['blackhole', '-t', '-c', cfile]), \
            pytest.raises(SystemExit) as err:
        run()
    assert str(err.value) == '64'
Example #23
0
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""
Blackhole is an email MTA that pipes all mail to /dev/null.

Blackhole is built on top of asyncio and utilises `async` and `await`
statements on available in Python 3.5 and above.

While Blackhole is an MTA (mail transport agent), none of the actions
performed of SMTP or SMTPS are actually processed and no email or sent or
delivered.
"""

from blackhole.application import run

if __name__ == '__main__':  # pragma: no cover
    run()