at 18.03-beta 4.3 kB view raw
1# Test whether `networking.proxy' work as expected. 2 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 5 6let default-config = { 7 imports = [ ./common/user-account.nix ]; 8 9 services.xserver.enable = false; 10 11 virtualisation.memorySize = 128; 12 }; 13in import ./make-test.nix ({ pkgs, ...} : { 14 name = "networking-proxy"; 15 meta = with pkgs.stdenv.lib.maintainers; { 16 maintainers = [ ]; 17 }; 18 19 nodes = { 20 # no proxy 21 machine = 22 { config, pkgs, ... }: 23 24 default-config; 25 26 # proxy default 27 machine2 = 28 { config, pkgs, ... }: 29 30 default-config // { 31 networking.proxy.default = "http://user:pass@host:port"; 32 }; 33 34 # specific proxy options 35 machine3 = 36 { config, pkgs, ... }: 37 38 default-config // 39 { 40 networking.proxy = { 41 # useless because overriden by the next options 42 default = "http://user:pass@host:port"; 43 # advanced proxy setup 44 httpProxy = "123-http://user:pass@http-host:port"; 45 httpsProxy = "456-http://user:pass@https-host:port"; 46 rsyncProxy = "789-http://user:pass@rsync-host:port"; 47 ftpProxy = "101112-http://user:pass@ftp-host:port"; 48 noProxy = "131415-127.0.0.1,localhost,.localdomain"; 49 }; 50 }; 51 52 # mix default + proxy options 53 machine4 = 54 { config, pkgs, ... }: 55 56 default-config // { 57 networking.proxy = { 58 # open for all *_proxy env var 59 default = "000-http://user:pass@default-host:port"; 60 # except for those 2 61 rsyncProxy = "123-http://user:pass@http-host:port"; 62 noProxy = "131415-127.0.0.1,localhost,.localdomain"; 63 }; 64 }; 65 }; 66 67 testScript = 68 '' 69 startAll; 70 71 # no proxy at all 72 print $machine->execute("env | grep -i proxy"); 73 print $machine->execute("su - alice -c 'env | grep -i proxy'"); 74 $machine->mustFail("env | grep -i proxy"); 75 $machine->mustFail("su - alice -c 'env | grep -i proxy'"); 76 77 # Use a default proxy option 78 print $machine2->execute("env | grep -i proxy"); 79 print $machine2->execute("su - alice -c 'env | grep -i proxy'"); 80 $machine2->mustSucceed("env | grep -i proxy"); 81 $machine2->mustSucceed("su - alice -c 'env | grep -i proxy'"); 82 83 # explicitly set each proxy option 84 print $machine3->execute("env | grep -i proxy"); 85 print $machine3->execute("su - alice -c 'env | grep -i proxy'"); 86 $machine3->mustSucceed("env | grep -i http_proxy | grep 123"); 87 $machine3->mustSucceed("env | grep -i https_proxy | grep 456"); 88 $machine3->mustSucceed("env | grep -i rsync_proxy | grep 789"); 89 $machine3->mustSucceed("env | grep -i ftp_proxy | grep 101112"); 90 $machine3->mustSucceed("env | grep -i no_proxy | grep 131415"); 91 $machine3->mustSucceed("su - alice -c 'env | grep -i http_proxy | grep 123'"); 92 $machine3->mustSucceed("su - alice -c 'env | grep -i https_proxy | grep 456'"); 93 $machine3->mustSucceed("su - alice -c 'env | grep -i rsync_proxy | grep 789'"); 94 $machine3->mustSucceed("su - alice -c 'env | grep -i ftp_proxy | grep 101112'"); 95 $machine3->mustSucceed("su - alice -c 'env | grep -i no_proxy | grep 131415'"); 96 97 # set default proxy option + some other specifics 98 print $machine4->execute("env | grep -i proxy"); 99 print $machine4->execute("su - alice -c 'env | grep -i proxy'"); 100 $machine4->mustSucceed("env | grep -i http_proxy | grep 000"); 101 $machine4->mustSucceed("env | grep -i https_proxy | grep 000"); 102 $machine4->mustSucceed("env | grep -i rsync_proxy | grep 123"); 103 $machine4->mustSucceed("env | grep -i ftp_proxy | grep 000"); 104 $machine4->mustSucceed("env | grep -i no_proxy | grep 131415"); 105 $machine4->mustSucceed("su - alice -c 'env | grep -i http_proxy | grep 000'"); 106 $machine4->mustSucceed("su - alice -c 'env | grep -i https_proxy | grep 000'"); 107 $machine4->mustSucceed("su - alice -c 'env | grep -i rsync_proxy | grep 123'"); 108 $machine4->mustSucceed("su - alice -c 'env | grep -i ftp_proxy | grep 000'"); 109 $machine4->mustSucceed("su - alice -c 'env | grep -i no_proxy | grep 131415'"); 110 ''; 111})