diff --git a/src/cmd/initContainer.go b/src/cmd/initContainer.go index ca7f3caad..71bda7bf2 100644 --- a/src/cmd/initContainer.go +++ b/src/cmd/initContainer.go @@ -200,7 +200,8 @@ func initContainer(cmd *cobra.Command, args []string) error { return err } - if _, err := os.Readlink("/etc/resolv.conf"); err != nil { + if resolvConfTarget, err := os.Readlink("/etc/resolv.conf"); err != nil || + resolvConfTarget != "/run/host/etc/resolv.conf" { if err := redirectPath("/etc/resolv.conf", "/run/host/etc/resolv.conf", false); err != nil { diff --git a/test/system/203-network.bats b/test/system/203-network.bats index 4b0b8e5ef..db1ba561f 100644 --- a/test/system/203-network.bats +++ b/test/system/203-network.bats @@ -62,6 +62,132 @@ teardown() { assert [ ${#stderr_lines[@]} -eq 0 ] } +@test "network: /etc/resolv.conf inside the default container" { + create_default_container + + run --keep-empty-lines --separate-stderr "$TOOLBOX" run readlink /etc/resolv.conf + + assert_success + assert_line --index 0 "/run/host/etc/resolv.conf" + + if check_bats_version 1.10.0; then + assert [ ${#lines[@]} -eq 1 ] + else + assert [ ${#lines[@]} -eq 2 ] + fi + + # shellcheck disable=SC2154 + assert [ ${#stderr_lines[@]} -eq 0 ] +} + +@test "network: /etc/resolv.conf inside Arch Linux" { + create_distro_container arch latest arch-toolbox-latest + + run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro arch readlink /etc/resolv.conf + + assert_success + assert_line --index 0 "/run/host/etc/resolv.conf" + + if check_bats_version 1.10.0; then + assert [ ${#lines[@]} -eq 1 ] + else + assert [ ${#lines[@]} -eq 2 ] + fi + + # shellcheck disable=SC2154 + assert [ ${#stderr_lines[@]} -eq 0 ] +} + +@test "network: /etc/resolv.conf inside Fedora 34" { + create_distro_container fedora 34 fedora-toolbox-34 + + run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro fedora --release 34 readlink /etc/resolv.conf + + assert_success + assert_line --index 0 "/run/host/etc/resolv.conf" + + if check_bats_version 1.10.0; then + assert [ ${#lines[@]} -eq 1 ] + else + assert [ ${#lines[@]} -eq 2 ] + fi + + # shellcheck disable=SC2154 + assert [ ${#stderr_lines[@]} -eq 0 ] +} + +@test "network: /etc/resolv.conf inside RHEL 8.7" { + create_distro_container rhel 8.7 rhel-toolbox-8.7 + + run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro rhel --release 8.7 readlink /etc/resolv.conf + + assert_success + assert_line --index 0 "/run/host/etc/resolv.conf" + + if check_bats_version 1.10.0; then + assert [ ${#lines[@]} -eq 1 ] + else + assert [ ${#lines[@]} -eq 2 ] + fi + + # shellcheck disable=SC2154 + assert [ ${#stderr_lines[@]} -eq 0 ] +} + +@test "network: /etc/resolv.conf inside Ubuntu 16.04" { + create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04 + + run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 16.04 readlink /etc/resolv.conf + + assert_success + assert_line --index 0 "/run/host/etc/resolv.conf" + + if check_bats_version 1.10.0; then + assert [ ${#lines[@]} -eq 1 ] + else + assert [ ${#lines[@]} -eq 2 ] + fi + + # shellcheck disable=SC2154 + assert [ ${#stderr_lines[@]} -eq 0 ] +} + +@test "network: /etc/resolv.conf inside Ubuntu 18.04" { + create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04 + + run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 18.04 readlink /etc/resolv.conf + + assert_success + assert_line --index 0 "/run/host/etc/resolv.conf" + + if check_bats_version 1.10.0; then + assert [ ${#lines[@]} -eq 1 ] + else + assert [ ${#lines[@]} -eq 2 ] + fi + + # shellcheck disable=SC2154 + assert [ ${#stderr_lines[@]} -eq 0 ] +} + +@test "network: /etc/resolv.conf inside Ubuntu 20.04" { + create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04 + + run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 20.04 readlink /etc/resolv.conf + + assert_success + assert_line --index 0 "/run/host/etc/resolv.conf" + + if check_bats_version 1.10.0; then + assert [ ${#lines[@]} -eq 1 ] + else + assert [ ${#lines[@]} -eq 2 ] + fi + + # shellcheck disable=SC2154 + assert [ ${#stderr_lines[@]} -eq 0 ] +} + @test "network: DNS inside the default container" { local ipv4_skip=false local ipv4_addr