commit
282ecd233d
@ -3,7 +3,7 @@
|
|||||||
# client on the inside network, a server on the outside network, and a
|
# client on the inside network, a server on the outside network, and a
|
||||||
# router connected to both that performs Network Address Translation
|
# router connected to both that performs Network Address Translation
|
||||||
# for the client.
|
# for the client.
|
||||||
import ./make-test.nix ({ pkgs, lib, withFirewall, withConntrackHelpers ? false, ... }:
|
import ./make-test-python.nix ({ pkgs, lib, withFirewall, withConntrackHelpers ? false, ... }:
|
||||||
let
|
let
|
||||||
unit = if withFirewall then "firewall" else "nat";
|
unit = if withFirewall then "firewall" else "nat";
|
||||||
|
|
||||||
@ -69,49 +69,52 @@ import ./make-test.nix ({ pkgs, lib, withFirewall, withConntrackHelpers ? false,
|
|||||||
routerDummyNoNatClosure = nodes.routerDummyNoNat.config.system.build.toplevel;
|
routerDummyNoNatClosure = nodes.routerDummyNoNat.config.system.build.toplevel;
|
||||||
routerClosure = nodes.router.config.system.build.toplevel;
|
routerClosure = nodes.router.config.system.build.toplevel;
|
||||||
in ''
|
in ''
|
||||||
$client->start;
|
client.start()
|
||||||
$router->start;
|
router.start()
|
||||||
$server->start;
|
server.start()
|
||||||
|
|
||||||
# The router should have access to the server.
|
# The router should have access to the server.
|
||||||
$server->waitForUnit("network.target");
|
server.wait_for_unit("network.target")
|
||||||
$server->waitForUnit("httpd");
|
server.wait_for_unit("httpd")
|
||||||
$router->waitForUnit("network.target");
|
router.wait_for_unit("network.target")
|
||||||
$router->succeed("curl --fail http://server/ >&2");
|
router.succeed("curl --fail http://server/ >&2")
|
||||||
|
|
||||||
# The client should be also able to connect via the NAT router.
|
# The client should be also able to connect via the NAT router.
|
||||||
$router->waitForUnit("${unit}");
|
router.wait_for_unit("${unit}")
|
||||||
$client->waitForUnit("network.target");
|
client.wait_for_unit("network.target")
|
||||||
$client->succeed("curl --fail http://server/ >&2");
|
client.succeed("curl --fail http://server/ >&2")
|
||||||
$client->succeed("ping -c 1 server >&2");
|
client.succeed("ping -c 1 server >&2")
|
||||||
|
|
||||||
# Test whether passive FTP works.
|
# Test whether passive FTP works.
|
||||||
$server->waitForUnit("vsftpd");
|
server.wait_for_unit("vsftpd")
|
||||||
$server->succeed("echo Hello World > /home/ftp/foo.txt");
|
server.succeed("echo Hello World > /home/ftp/foo.txt")
|
||||||
$client->succeed("curl -v ftp://server/foo.txt >&2");
|
client.succeed("curl -v ftp://server/foo.txt >&2")
|
||||||
|
|
||||||
# Test whether active FTP works.
|
# Test whether active FTP works.
|
||||||
$client->${if withConntrackHelpers then "succeed" else "fail"}(
|
client.${if withConntrackHelpers then "succeed" else "fail"}("curl -v -P - ftp://server/foo.txt >&2")
|
||||||
"curl -v -P - ftp://server/foo.txt >&2");
|
|
||||||
|
|
||||||
# Test ICMP.
|
# Test ICMP.
|
||||||
$client->succeed("ping -c 1 router >&2");
|
client.succeed("ping -c 1 router >&2")
|
||||||
$router->succeed("ping -c 1 client >&2");
|
router.succeed("ping -c 1 client >&2")
|
||||||
|
|
||||||
# If we turn off NAT, the client shouldn't be able to reach the server.
|
# If we turn off NAT, the client shouldn't be able to reach the server.
|
||||||
$router->succeed("${routerDummyNoNatClosure}/bin/switch-to-configuration test 2>&1");
|
router.succeed(
|
||||||
$client->fail("curl --fail --connect-timeout 5 http://server/ >&2");
|
"${routerDummyNoNatClosure}/bin/switch-to-configuration test 2>&1"
|
||||||
$client->fail("ping -c 1 server >&2");
|
)
|
||||||
|
client.fail("curl --fail --connect-timeout 5 http://server/ >&2")
|
||||||
|
client.fail("ping -c 1 server >&2")
|
||||||
|
|
||||||
# And make sure that reloading the NAT job works.
|
# And make sure that reloading the NAT job works.
|
||||||
$router->succeed("${routerClosure}/bin/switch-to-configuration test 2>&1");
|
router.succeed(
|
||||||
|
"${routerClosure}/bin/switch-to-configuration test 2>&1"
|
||||||
|
)
|
||||||
# FIXME: this should not be necessary, but nat.service is not started because
|
# FIXME: this should not be necessary, but nat.service is not started because
|
||||||
# network.target is not triggered
|
# network.target is not triggered
|
||||||
# (https://github.com/NixOS/nixpkgs/issues/16230#issuecomment-226408359)
|
# (https://github.com/NixOS/nixpkgs/issues/16230#issuecomment-226408359)
|
||||||
${lib.optionalString (!withFirewall) ''
|
${lib.optionalString (!withFirewall) ''
|
||||||
$router->succeed("systemctl start nat.service");
|
router.succeed("systemctl start nat.service")
|
||||||
''}
|
''}
|
||||||
$client->succeed("curl --fail http://server/ >&2");
|
client.succeed("curl --fail http://server/ >&2")
|
||||||
$client->succeed("ping -c 1 server >&2");
|
client.succeed("ping -c 1 server >&2")
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user