Skip to content

Commit a61c618

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: - #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 a61c618

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

cmd/nerdctl/container/container_run_linux_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,43 @@ func TestIssue3568(t *testing.T) {
567567

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

0 commit comments

Comments
 (0)