示例#1
0
 def test_port_changes_port(self):
     cidr = factory.make_ipv4_network()
     port = random.randint(1, 65535)
     config.write_config([cidr], maas_proxy_port=port)
     with self.proxy_path.open() as proxy_file:
         lines = [line.strip() for line in proxy_file.readlines()]
         self.assertIn("http_port %s" % port, lines)
示例#2
0
 def test_without_use_peer_proxy(self):
     cidr = factory.make_ipv4_network()
     config.write_config([cidr])
     with self.proxy_path.open() as proxy_file:
         lines = [line.strip() for line in proxy_file.readlines()]
         self.assertNotIn("never_direct allow all", lines)
         self.assertNotIn("cache_peer", lines)
示例#3
0
 def test_user_not_in_snap(self):
     self.patch(snappy, "running_in_snap").return_value = False
     config.write_config(allowed_cidrs=[])
     with self.proxy_path.open() as proxy_file:
         lines = [line.strip() for line in proxy_file.readlines()]
         self.assertNotIn("cache_effective_user snap_daemon", lines)
         self.assertNotIn("cache_effective_group snap_daemon", lines)
示例#4
0
 def test_adds_cidr(self):
     cidr = factory.make_ipv4_network()
     config.write_config([cidr])
     matcher = Contains("acl localnet src %s" % cidr)
     self.assertThat(
         "%s/%s" % (self.tmpdir, config.MAAS_PROXY_CONF_NAME),
         FileContains(matcher=matcher),
     )
示例#5
0
 def _configure(self, configuration):
     """Update the proxy configuration for the rack."""
     peers = sorted([
         'http://%s:%s' % (upstream, configuration.port)
         for upstream in configuration.upstream_proxies
     ])
     proxy_config.write_config(
         configuration.allowed_cidrs,
         peer_proxies=peers,
         prefer_v4_proxy=configuration.prefer_v4_proxy,
         maas_proxy_port=configuration.port)
示例#6
0
 def test_peer_proxies(self):
     cidr = factory.make_ipv4_network()
     peer_proxies = ["http://example.com:8000/", "http://other.com:8001/"]
     config.write_config([cidr], peer_proxies=peer_proxies)
     cache_peer1_line = (
         "cache_peer example.com parent 8000 0 no-query default")
     cache_peer2_line = (
         "cache_peer other.com parent 8001 0 no-query default")
     with self.proxy_path.open() as proxy_file:
         lines = [line.strip() for line in proxy_file.readlines()]
         self.assertIn("never_direct allow all", lines)
         self.assertIn(cache_peer1_line, lines)
         self.assertIn(cache_peer2_line, lines)
示例#7
0
    def _write_config():
        allowed_subnets = Subnet.objects.filter(allow_proxy=True)
        cidrs = [subnet.cidr for subnet in allowed_subnets]
        config = Config.objects.get_configs([
            "http_proxy",
            "maas_proxy_port",
            "use_peer_proxy",
            "prefer_v4_proxy",
            "enable_http_proxy",
        ])

        kwargs = {
            "prefer_v4_proxy": config["prefer_v4_proxy"],
            "maas_proxy_port": config["maas_proxy_port"],
        }
        if (config["enable_http_proxy"] and config["http_proxy"]
                and config["use_peer_proxy"]):
            kwargs["peer_proxies"] = [config["http_proxy"]]
        write_config(cidrs, **kwargs)
示例#8
0
 def test_with_prefer_v4_proxy_True(self):
     cidr = factory.make_ipv4_network()
     config.write_config([cidr], prefer_v4_proxy=True)
     with self.proxy_path.open() as proxy_file:
         lines = [line.strip() for line in proxy_file.readlines()]
         self.assertIn("dns_v4_first on", lines)