@@ -40,6 +40,7 @@ import (
40
40
"github.com/containerd/nerdctl/v2/pkg/strutil"
41
41
"github.com/containerd/nerdctl/v2/pkg/testutil"
42
42
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
43
+ "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil"
43
44
"github.com/containerd/nerdctl/v2/pkg/testutil/test"
44
45
)
45
46
@@ -568,3 +569,45 @@ func TestIssue3568(t *testing.T) {
568
569
569
570
testCase .Run (t )
570
571
}
572
+
573
+ // TestPortBindingWithCustomHost tests https://github.com/containerd/nerdctl/issues/3539
574
+ func TestPortBindingWithCustomHost (t * testing.T ) {
575
+ testCase := nerdtest .Setup ()
576
+
577
+ const (
578
+ host = "127.0.0.2"
579
+ hostPort = 8080
580
+ )
581
+ address := fmt .Sprintf ("%s:%d" , host , hostPort )
582
+
583
+ testCase .SubTests = []* test.Case {
584
+ {
585
+ Description : "Issue #3539 - Access to a container running when 127.0.0.2 is specified in -p in rootless mode." ,
586
+ Setup : func (data test.Data , helpers test.Helpers ) {
587
+ helpers .Ensure ("run" , "-d" , "--name" , data .Identifier (), "-p" , fmt .Sprintf ("%s:80" , address ), testutil .NginxAlpineImage )
588
+ nerdtest .EnsureContainerStarted (helpers , data .Identifier ())
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
+ resp , err := nettestutil .HTTPGet (address , 30 , false )
600
+ assert .NilError (t , err )
601
+
602
+ respBody , err := io .ReadAll (resp .Body )
603
+ assert .NilError (t , err )
604
+ assert .Assert (t , strings .Contains (string (respBody ), testutil .NginxAlpineIndexHTMLSnippet ))
605
+ },
606
+ ),
607
+ }
608
+ },
609
+ },
610
+ }
611
+
612
+ testCase .Run (t )
613
+ }
0 commit comments