Example #1
0
    def test_email_changed(self):
        # Get ref to notification plugin
        self.app.cfg['emailsendchangednotification'] = 'True'
        n = NotificationPlugin(bus=MagicMock(), app=self.app)
        self.assertIsNotNone(n)
        n.send_mail = MagicMock()

        # Set user config
        user = self.app.store.get_user(self.USERNAME)
        user.email = '*****@*****.**'

        # Expect it to be called.
        n.send_mail.assert_called_once_with(ANY, ANY, 'email_changed.html')
Example #2
0
    def test_password_change_notification(self):
        # Set user config
        user = self.app.userdb.get_user(self.USERNAME)
        user.email = '*****@*****.**'

        # Get ref to notification plugin
        self.app.cfg['emailsendchangednotification'] = 'True'
        n = NotificationPlugin(bus=MagicMock(), app=self.app)
        self.assertIsNotNone(n)
        n.send_mail = MagicMock()

        # Change password
        self.app.userdb.set_password(self.USERNAME, 'new_password')

        # Expect it to be called.
        n.send_mail.assert_called_once_with(ANY, ANY, 'password_changed.html')
Example #3
0
    def test_run_with_notification(self):
        """
        Run the notification and check if mails are sent
        """
        # Set user config
        user = self.app.store.get_user(self.USERNAME)
        user.email = '*****@*****.**'
        user.get_repo(self.REPO).maxage = 1

        # Get ref to notification plugin
        n = NotificationPlugin(bus=MagicMock(), app=self.app)
        self.assertIsNotNone(n)
        n.send_mail = MagicMock()

        # Call notification.
        n.send_notifications()

        # Expect it to be called.
        n.send_mail.assert_called_once_with(user, 'Notification', 'email_notification.html', repos=[ANY], user=user)
Example #4
0
    def test_send_mail(self):
        """
        Check email template generation.
        """
        with patch('rdiffweb.core.notification.smtplib') as patcher:
            # Set user config
            user = self.app.store.get_user(self.USERNAME)
            user.email = '*****@*****.**'

            # Set email config
            self.app.cfg['EmailHost'] = 'smtp.gmail.com:587'
            self.app.cfg['EmailUsername'] = '******'
            self.app.cfg['EmailPassword'] = '******'
            self.app.cfg['EmailEncryption'] = 'starttls'

            # Get ref to notification plugin
            bus = MagicMock()
            n = NotificationPlugin(bus, self.app)
            self.assertIsNotNone(n)
            n.send_mail(user, 'subject', 'email_notification.html')
Example #5
0
    def test_run_without_notification(self):
        """
        Run the notification and check if mails are sent
        """
        # Set user config
        user = self.app.store.get_user(self.USERNAME)
        user.email = '*****@*****.**'
        user.get_repo(self.REPO).maxage = -1

        # Get ref to notification plugin
        bus = MagicMock()
        n = NotificationPlugin(bus, self.app)
        self.assertIsNotNone(n)
        n.send_mail = MagicMock()

        # Call notification.
        n.send_notifications()

        # Expect it to be called.
        n.send_mail.assert_not_called()
Example #6
0
def start():
    """Start rdiffweb deamon."""
    # Parse command line options
    args = {}
    opts = getopt.getopt(sys.argv[1:], 'vdrf:', [
        'debug',
        'log-file=',
        'log-access-file=',
        'config=',
    ])[0]
    for option, value in opts:
        if option in ['-d', '--debug']:
            args['debug'] = True
        elif option in ['--log-file']:
            args['log_file'] = value
        elif option in ['--log-access-file']:
            args['log_access_file'] = value
        elif option in ['-f', '--config']:
            args['config'] = value

    # Open config file before opening the apps.
    configfile = args.get('config', '/etc/rdiffweb/rdw.conf')
    cfg = read_config(configfile)
    log_file = args.get('log_file', None) or cfg.get('logfile', False)
    log_access_file = args.get('log_access_file', None) or cfg.get(
        'logaccessfile', None)
    if args.get('debug', False):
        environment = 'development'
        log_level = "DEBUG"
    else:
        environment = cfg.get('environment', 'production')
        log_level = cfg.get('loglevel', 'INFO')

    # Configure logging
    setup_logging(log_file=log_file,
                  log_access_file=log_access_file,
                  level=log_level)

    # Create App.
    app = rdw_app.RdiffwebApp(cfg)

    # Get configuration
    serverHost = nativestr(cfg.get("serverhost", "127.0.0.1"))
    serverPort = int(cfg.get("serverport", "8080"))
    # Get SSL configuration (if any)
    sslCertificate = cfg.get("sslcertificate")
    sslPrivateKey = cfg.get("sslprivatekey")

    global_config = cherrypy._cpconfig.environments.get(environment, {})
    global_config.update({
        'server.socket_host': serverHost,
        'server.socket_port': serverPort,
        'server.log_file': log_file,
        'server.ssl_certificate': sslCertificate,
        'server.ssl_private_key': sslPrivateKey,
        # Set maximum POST size to 2MiB, for security.
        'server.max_request_body_size': 2097152,
        'server.environment': environment,
    })

    cherrypy.config.update(global_config)

    # Add a custom signal handler
    cherrypy.engine.signal_handler.handlers['SIGUSR2'] = debug_dump_mem
    cherrypy.engine.signal_handler.handlers['SIGABRT'] = debug_dump_thread

    # Start deamons
    RemoveOlder(cherrypy.engine, app).subscribe()
    NotificationPlugin(cherrypy.engine, app).subscribe()

    # Start web server
    cherrypy.quickstart(app)

    # Log startup
    logger.info("STOP")