Skip to content

Commit e0eb64e

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 e0eb64e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

cmd/nerdctl/container/container_run_linux_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,42 @@ 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+
},
587+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
588+
return helpers.Custom("curl", "-s", address)
589+
},
590+
Cleanup: func(data test.Data, helpers test.Helpers) {
591+
helpers.Anyhow("rm", "-f", data.Identifier())
592+
},
593+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
594+
return &test.Expected{
595+
ExitCode: 0,
596+
Errors: []error{},
597+
Output: test.All(
598+
func(stdout string, info string, t *testing.T) {
599+
assert.Assert(t, strings.Contains(string(stdout), testutil.NginxAlpineIndexHTMLSnippet))
600+
},
601+
),
602+
}
603+
},
604+
},
605+
}
606+
607+
testCase.Run(t)
608+
}

0 commit comments

Comments
 (0)