Skip to content

Commit 653c6de

Browse files
committed
test: Add a test for container access with 127.0.0.2 specified in -p in rootless mode
When running a rootless container, specifying an address such as 127.0.0.2 for the -p option, we will not be able to access the published container through that address. This behavior is reported in the following issue: - containerd#3539 This behavior is caused by the behavior in rootlesskit, and the following pull request has been made to improve the behavior. - rootless-containers/rootlesskit#477 Therefore, this commit adds a test to ensure that the behavior of the issue has been improved. Signed-off-by: Hayato Kiwata <[email protected]>
1 parent ce61fc4 commit 653c6de

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

cmd/nerdctl/container/container_run_linux_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/containerd/nerdctl/v2/pkg/strutil"
4141
"github.com/containerd/nerdctl/v2/pkg/testutil"
4242
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
43+
"github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil"
4344
"github.com/containerd/nerdctl/v2/pkg/testutil/test"
4445
)
4546

@@ -567,3 +568,45 @@ func TestIssue3568(t *testing.T) {
567568

568569
testCase.Run(t)
569570
}
571+
572+
// TestPortBindingWithCustomHost tests https://github.com/containerd/nerdctl/issues/3539
573+
func TestPortBindingWithCustomHost(t *testing.T) {
574+
testCase := nerdtest.Setup()
575+
576+
const (
577+
host = "127.0.0.2"
578+
hostPort = 8080
579+
)
580+
address := fmt.Sprintf("%s:%d", host, hostPort)
581+
582+
testCase.SubTests = []*test.Case{
583+
{
584+
Description: "Issue #3539 - Access to a container running when 127.0.0.2 is specified in -p in rootless mode.",
585+
Setup: func(data test.Data, helpers test.Helpers) {
586+
helpers.Ensure("run", "-d", "--name", data.Identifier(), "-p", fmt.Sprintf("%s:80", address), testutil.NginxAlpineImage)
587+
nerdtest.EnsureContainerStarted(helpers, data.Identifier())
588+
},
589+
Cleanup: func(data test.Data, helpers test.Helpers) {
590+
helpers.Anyhow("rm", "-f", data.Identifier())
591+
},
592+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
593+
return &test.Expected{
594+
ExitCode: 0,
595+
Errors: []error{},
596+
Output: test.All(
597+
func(stdout string, info string, t *testing.T) {
598+
resp, err := nettestutil.HTTPGet(address, 30, false)
599+
assert.NilError(t, err)
600+
601+
respBody, err := io.ReadAll(resp.Body)
602+
assert.NilError(t, err)
603+
assert.Assert(t, strings.Contains(string(respBody), testutil.NginxAlpineIndexHTMLSnippet))
604+
},
605+
),
606+
}
607+
},
608+
},
609+
}
610+
611+
testCase.Run(t)
612+
}

0 commit comments

Comments
 (0)