Example #1
0
 def test_getset_ignore(self):
     p = mock.Mock()
     p.config.check_ignore = HostMatcher()
     fm = flow.FlowMaster(p, flow.State())
     assert not fm.get_ignore_filter()
     fm.set_ignore_filter(["^apple\.com:", ":443$"])
     assert fm.get_ignore_filter()
Example #2
0
    def configure(self, options: moptions.Options,
                  updated: typing.Any) -> None:
        self.check_ignore = DynamicHostMatcher(options.ignore_hosts)
        self.check_tcp = HostMatcher(options.tcp_hosts)

        certstore_path = os.path.expanduser(options.confdir)
        if not os.path.exists(os.path.dirname(certstore_path)):
            raise exceptions.OptionsError(
                "Certificate Authority parent directory does not exist: %s" %
                os.path.dirname(certstore_path))
        self.certstore = certs.CertStore.from_store(certstore_path,
                                                    CONF_BASENAME)

        for c in options.certs:
            parts = c.split("=", 1)
            if len(parts) == 1:
                parts = ["*", parts[0]]

            cert = os.path.expanduser(parts[1])
            if not os.path.exists(cert):
                raise exceptions.OptionsError(
                    "Certificate file does not exist: %s" % cert)
            try:
                self.certstore.add_cert_file(parts[0], cert)
            except crypto.Error:
                raise exceptions.OptionsError(
                    "Invalid certificate format: %s" % cert)
        m = options.mode
        if m.startswith("upstream:") or m.startswith("reverse:"):
            _, spec = server_spec.parse_with_mode(options.mode)
            self.upstream_server = spec
Example #3
0
    def _host_pattern_on(self, attr):
        """
        Updates config.check_tcp or check_ignore, depending on attr.
        """
        assert not hasattr(self, "_ignore_%s_backup" % attr)
        backup = []
        for proxy in self.chain:
            old_matcher = getattr(proxy.tmaster.server.config,
                                  "check_%s" % attr)
            backup.append(old_matcher)
            setattr(
                proxy.tmaster.server.config, "check_%s" % attr,
                HostMatcher([".+:%s" % self.server.port] +
                            old_matcher.patterns))

        setattr(self, "_ignore_%s_backup" % attr, backup)
Example #4
0
    def _host_pattern_on(self, attr):
        """
        Updates config.check_tcp or check_filter, depending on attr.
        """
        assert not hasattr(self, "_ignore_%s_backup" % attr)
        backup = []
        handle = attr
        attr = "filter" if attr in ["allow", "ignore"] else attr
        for proxy in self.chain:
            old_matcher = getattr(proxy.tmaster.server.config,
                                  "check_%s" % attr)
            backup.append(old_matcher)
            setattr(
                proxy.tmaster.server.config, "check_%s" % attr,
                HostMatcher(handle, [".+:%s" % self.server.port] +
                            old_matcher.patterns))

        setattr(self, "_ignore_%s_backup" % attr, backup)
Example #5
0
 def _tcpproxy_on(self):
     assert not hasattr(self, "_tcpproxy_backup")
     self._tcpproxy_backup = self.config.check_tcp
     self.config.check_tcp = HostMatcher(
         [".+:%s" % self.server.port] + self.config.check_tcp.patterns)
Example #6
0
 def _ignore_on(self):
     assert not hasattr(self, "_ignore_backup")
     self._ignore_backup = self.config.check_ignore
     self.config.check_ignore = HostMatcher(
         [".+:%s" % self.server.port] + self.config.check_ignore.patterns)
Example #7
0
 def set_tcp_filter(self, host_patterns):
     self.server.config.check_tcp = HostMatcher(host_patterns)
Example #8
0
 def set_ignore_filter(self, host_patterns):
     self.server.config.check_ignore = HostMatcher(host_patterns)