Merge pull request #78239 from andrew-d/andrew/networking-proxy-tests-python

nixosTests.networkingProxy: port to Python
This commit is contained in:
worldofpeace 2020-01-30 19:14:13 -05:00 committed by GitHub
commit b36f4c81dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 62 additions and 38 deletions

View File

@ -10,7 +10,7 @@ let default-config = {
virtualisation.memorySize = 128; virtualisation.memorySize = 128;
}; };
in import ./make-test.nix ({ pkgs, ...} : { in import ./make-test-python.nix ({ pkgs, ...} : {
name = "networking-proxy"; name = "networking-proxy";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ ]; maintainers = [ ];
@ -66,46 +66,70 @@ in import ./make-test.nix ({ pkgs, ...} : {
testScript = testScript =
'' ''
startAll; from typing import Dict, Optional
# no proxy at all
print $machine->execute("env | grep -i proxy");
print $machine->execute("su - alice -c 'env | grep -i proxy'");
$machine->mustFail("env | grep -i proxy");
$machine->mustFail("su - alice -c 'env | grep -i proxy'");
# Use a default proxy option def get_machine_env(machine: Machine, user: Optional[str] = None) -> Dict[str, str]:
print $machine2->execute("env | grep -i proxy"); """
print $machine2->execute("su - alice -c 'env | grep -i proxy'"); Gets the environment from a given machine, and returns it as a
$machine2->mustSucceed("env | grep -i proxy"); dictionary in the form:
$machine2->mustSucceed("su - alice -c 'env | grep -i proxy'"); {"lowercase_var_name": "value"}
# explicitly set each proxy option Duplicate environment variables with the same name
print $machine3->execute("env | grep -i proxy"); (e.g. "foo" and "FOO") are handled in an undefined manner.
print $machine3->execute("su - alice -c 'env | grep -i proxy'"); """
$machine3->mustSucceed("env | grep -i http_proxy | grep 123"); if user is not None:
$machine3->mustSucceed("env | grep -i https_proxy | grep 456"); env = machine.succeed("su - {} -c 'env -0'".format(user))
$machine3->mustSucceed("env | grep -i rsync_proxy | grep 789"); else:
$machine3->mustSucceed("env | grep -i ftp_proxy | grep 101112"); env = machine.succeed("env -0")
$machine3->mustSucceed("env | grep -i no_proxy | grep 131415"); ret = {}
$machine3->mustSucceed("su - alice -c 'env | grep -i http_proxy | grep 123'"); for line in env.split("\0"):
$machine3->mustSucceed("su - alice -c 'env | grep -i https_proxy | grep 456'"); if "=" not in line:
$machine3->mustSucceed("su - alice -c 'env | grep -i rsync_proxy | grep 789'"); continue
$machine3->mustSucceed("su - alice -c 'env | grep -i ftp_proxy | grep 101112'");
$machine3->mustSucceed("su - alice -c 'env | grep -i no_proxy | grep 131415'");
# set default proxy option + some other specifics key, val = line.split("=", 1)
print $machine4->execute("env | grep -i proxy"); ret[key.lower()] = val
print $machine4->execute("su - alice -c 'env | grep -i proxy'"); return ret
$machine4->mustSucceed("env | grep -i http_proxy | grep 000");
$machine4->mustSucceed("env | grep -i https_proxy | grep 000");
$machine4->mustSucceed("env | grep -i rsync_proxy | grep 123"); start_all()
$machine4->mustSucceed("env | grep -i ftp_proxy | grep 000");
$machine4->mustSucceed("env | grep -i no_proxy | grep 131415"); with subtest("no proxy"):
$machine4->mustSucceed("su - alice -c 'env | grep -i http_proxy | grep 000'"); assert "proxy" not in machine.succeed("env").lower()
$machine4->mustSucceed("su - alice -c 'env | grep -i https_proxy | grep 000'"); assert "proxy" not in machine.succeed("su - alice -c env").lower()
$machine4->mustSucceed("su - alice -c 'env | grep -i rsync_proxy | grep 123'");
$machine4->mustSucceed("su - alice -c 'env | grep -i ftp_proxy | grep 000'"); with subtest("default proxy"):
$machine4->mustSucceed("su - alice -c 'env | grep -i no_proxy | grep 131415'"); assert "proxy" in machine2.succeed("env").lower()
assert "proxy" in machine2.succeed("su - alice -c env").lower()
with subtest("explicitly-set proxy"):
env = get_machine_env(machine3)
assert "123" in env["http_proxy"]
assert "456" in env["https_proxy"]
assert "789" in env["rsync_proxy"]
assert "101112" in env["ftp_proxy"]
assert "131415" in env["no_proxy"]
env = get_machine_env(machine3, "alice")
assert "123" in env["http_proxy"]
assert "456" in env["https_proxy"]
assert "789" in env["rsync_proxy"]
assert "101112" in env["ftp_proxy"]
assert "131415" in env["no_proxy"]
with subtest("default proxy + some other specifics"):
env = get_machine_env(machine4)
assert "000" in env["http_proxy"]
assert "000" in env["https_proxy"]
assert "123" in env["rsync_proxy"]
assert "000" in env["ftp_proxy"]
assert "131415" in env["no_proxy"]
env = get_machine_env(machine4, "alice")
assert "000" in env["http_proxy"]
assert "000" in env["https_proxy"]
assert "123" in env["rsync_proxy"]
assert "000" in env["ftp_proxy"]
assert "131415" in env["no_proxy"]
''; '';
}) })