1 # Test whether `networking.proxy' work as expected.
3 # TODO: use a real proxy node and put this test into networking.nix
4 # TODO: test whether nix tools work as expected behind a proxy
7 imports = [ ./common/user-account.nix ];
9 services.xserver.enable = false;
12 in import ./make-test-python.nix ({ pkgs, ...} : {
13 name = "networking-proxy";
14 meta = with pkgs.lib.maintainers; {
30 networking.proxy.default = "http://user:pass@host:port";
33 # specific proxy options
40 # useless because overridden by the next options
41 default = "http://user:pass@host:port";
42 # advanced proxy setup
43 httpProxy = "123-http://user:pass@http-host:port";
44 httpsProxy = "456-http://user:pass@https-host:port";
45 rsyncProxy = "789-http://user:pass@rsync-host:port";
46 ftpProxy = "101112-http://user:pass@ftp-host:port";
47 noProxy = "131415-127.0.0.1,localhost,.localdomain";
51 # mix default + proxy options
57 # open for all *_proxy env var
58 default = "000-http://user:pass@default-host:port";
60 rsyncProxy = "123-http://user:pass@http-host:port";
61 noProxy = "131415-127.0.0.1,localhost,.localdomain";
68 from typing import Dict, Optional
71 def get_machine_env(machine: Machine, user: Optional[str] = None) -> Dict[str, str]:
73 Gets the environment from a given machine, and returns it as a
74 dictionary in the form:
75 {"lowercase_var_name": "value"}
77 Duplicate environment variables with the same name
78 (e.g. "foo" and "FOO") are handled in an undefined manner.
81 env = machine.succeed("su - {} -c 'env -0'".format(user))
83 env = machine.succeed("env -0")
85 for line in env.split("\0"):
89 key, val = line.split("=", 1)
90 ret[key.lower()] = val
96 with subtest("no proxy"):
97 assert "proxy" not in machine.succeed("env").lower()
98 assert "proxy" not in machine.succeed("su - alice -c env").lower()
100 with subtest("default proxy"):
101 assert "proxy" in machine2.succeed("env").lower()
102 assert "proxy" in machine2.succeed("su - alice -c env").lower()
104 with subtest("explicitly-set proxy"):
105 env = get_machine_env(machine3)
106 assert "123" in env["http_proxy"]
107 assert "456" in env["https_proxy"]
108 assert "789" in env["rsync_proxy"]
109 assert "101112" in env["ftp_proxy"]
110 assert "131415" in env["no_proxy"]
112 env = get_machine_env(machine3, "alice")
113 assert "123" in env["http_proxy"]
114 assert "456" in env["https_proxy"]
115 assert "789" in env["rsync_proxy"]
116 assert "101112" in env["ftp_proxy"]
117 assert "131415" in env["no_proxy"]
119 with subtest("default proxy + some other specifics"):
120 env = get_machine_env(machine4)
121 assert "000" in env["http_proxy"]
122 assert "000" in env["https_proxy"]
123 assert "123" in env["rsync_proxy"]
124 assert "000" in env["ftp_proxy"]
125 assert "131415" in env["no_proxy"]
127 env = get_machine_env(machine4, "alice")
128 assert "000" in env["http_proxy"]
129 assert "000" in env["https_proxy"]
130 assert "123" in env["rsync_proxy"]
131 assert "000" in env["ftp_proxy"]
132 assert "131415" in env["no_proxy"]