diff --git a/tools/serve/serve.py b/tools/serve/serve.py index 3086a231402403..73810ce88ee0f0 100644 --- a/tools/serve/serve.py +++ b/tools/serve/serve.py @@ -702,8 +702,14 @@ def build_config(override_path=None, **kwargs): return rv -def _make_subdomains_product(s, depth=3): - return set(u".".join(x) for x in chain(*(product(s, repeat=i) for i in range(1, depth+1)))) +def _make_subdomains_product(s): + # A "depth" of 2 satisfies the original feature request: the availability + # of "a subdomain of a subdomain (and another subdomain of the same + # subdomain) + # https://github.com/web-platform-tests/wpt/issues/8581 + depth = 2 + + return set(u".".join(x) for x in chain(*(product(s, repeat=i) for i in range(1, depth + 1)))) _subdomains = {u"www", u"www1", @@ -713,10 +719,6 @@ def _make_subdomains_product(s, depth=3): _not_subdomains = {u"nonexistent"} -_subdomains = _make_subdomains_product(_subdomains) - -_not_subdomains = _make_subdomains_product(_not_subdomains) - class ConfigBuilder(config.ConfigBuilder): """serve config @@ -763,8 +765,12 @@ class ConfigBuilder(config.ConfigBuilder): def __init__(self, *args, **kwargs): if "subdomains" not in kwargs: kwargs["subdomains"] = _subdomains + kwargs["subdomains"] = _make_subdomains_product(kwargs["subdomains"]) + if "not_subdomains" not in kwargs: kwargs["not_subdomains"] = _not_subdomains + kwargs["not_subdomains"] = _make_subdomains_product(kwargs["not_subdomains"]) + super(ConfigBuilder, self).__init__( *args, **kwargs diff --git a/tools/serve/test_serve.py b/tools/serve/test_serve.py index e939c3a0ccee4a..f8d2cd69adab49 100644 --- a/tools/serve/test_serve.py +++ b/tools/serve/test_serve.py @@ -23,9 +23,17 @@ def test_make_hosts_file_nix(): "192.168.42.42\tfoo.bar", "192.168.42.42\tfoo2.bar", "192.168.42.42\ta.foo.bar", + "192.168.42.42\ta.a.foo.bar", + "192.168.42.42\ta.b.foo.bar", "192.168.42.42\ta.foo2.bar", + "192.168.42.42\ta.a.foo2.bar", + "192.168.42.42\ta.b.foo2.bar", "192.168.42.42\tb.foo.bar", - "192.168.42.42\tb.foo2.bar"} + "192.168.42.42\tb.a.foo.bar", + "192.168.42.42\tb.b.foo.bar", + "192.168.42.42\tb.foo2.bar", + "192.168.42.42\tb.a.foo2.bar", + "192.168.42.42\tb.b.foo2.bar"} assert lines[-1] == "" @pytest.mark.skipif(platform.uname()[0] != "Windows", @@ -35,20 +43,36 @@ def test_make_hosts_file_windows(): browser_host="foo.bar", alternate_hosts={"alt": "foo2.bar"}, subdomains={"a", "b"}, - not_subdomains={"x, y"}) as c: + not_subdomains={"x", "y"}) as c: hosts = serve.make_hosts_file(c, "192.168.42.42") lines = hosts.split("\n") assert set(lines) == {"", "0.0.0.0\tx.foo.bar", + "0.0.0.0\tx.x.foo.bar", + "0.0.0.0\tx.y.foo.bar", "0.0.0.0\tx.foo2.bar", + "0.0.0.0\tx.x.foo2.bar", + "0.0.0.0\tx.y.foo2.bar", "0.0.0.0\ty.foo.bar", + "0.0.0.0\ty.x.foo.bar", + "0.0.0.0\ty.y.foo.bar", "0.0.0.0\ty.foo2.bar", + "0.0.0.0\ty.x.foo2.bar", + "0.0.0.0\ty.y.foo2.bar", "192.168.42.42\tfoo.bar", "192.168.42.42\tfoo2.bar", "192.168.42.42\ta.foo.bar", + "192.168.42.42\ta.a.foo.bar", + "192.168.42.42\ta.b.foo.bar", "192.168.42.42\ta.foo2.bar", + "192.168.42.42\ta.a.foo2.bar", + "192.168.42.42\ta.b.foo2.bar", "192.168.42.42\tb.foo.bar", - "192.168.42.42\tb.foo2.bar"} + "192.168.42.42\tb.a.foo.bar", + "192.168.42.42\tb.b.foo.bar", + "192.168.42.42\tb.foo2.bar", + "192.168.42.42\tb.a.foo2.bar", + "192.168.42.42\tb.b.foo2.bar"} assert lines[-1] == ""