@@ -462,40 +462,124 @@ func TestValidateRuntime(t *testing.T) {
462
462
}
463
463
464
464
func TestValidatePorts (t * testing.T ) {
465
+ isMicrosoftWSL := detect .IsMicrosoftWSL ()
465
466
type portTest struct {
467
+ isTarget bool
466
468
ports []string
467
469
errorMsg string
468
470
}
469
471
var tests = []portTest {
470
472
{
471
- ports : []string {"test:80" },
472
- errorMsg : "Sorry, one of the ports provided with --ports flag is not valid [test:80]" ,
473
+ isTarget : true ,
474
+ ports : []string {"8080:80" },
475
+ errorMsg : "" ,
476
+ },
477
+ {
478
+ isTarget : true ,
479
+ ports : []string {"8080:80/tcp" , "8080:80/udp" },
480
+ errorMsg : "" ,
481
+ },
482
+ {
483
+ isTarget : true ,
484
+ ports : []string {"test:8080" },
485
+ errorMsg : "Sorry, one of the ports provided with --ports flag is not valid [test:8080] (Invalid hostPort: test)" ,
473
486
},
474
487
{
488
+ isTarget : true ,
475
489
ports : []string {"0:80" },
476
490
errorMsg : "Sorry, one of the ports provided with --ports flag is outside range [0:80]" ,
477
491
},
478
492
{
479
- ports : []string {"8080:80" , "6443:443" },
493
+ isTarget : true ,
494
+ ports : []string {"0:80/tcp" },
495
+ errorMsg : "Sorry, one of the ports provided with --ports flag is outside range [0:80/tcp]" ,
496
+ },
497
+ {
498
+ isTarget : true ,
499
+ ports : []string {"65536:80/udp" },
500
+ errorMsg : "Sorry, one of the ports provided with --ports flag is not valid [65536:80/udp] (Invalid hostPort: 65536)" ,
501
+ },
502
+ {
503
+ isTarget : true ,
504
+ ports : []string {"0-1:80-81/tcp" },
505
+ errorMsg : "Sorry, one of the ports provided with --ports flag is outside range [0-1:80-81/tcp]" ,
506
+ },
507
+ {
508
+ isTarget : true ,
509
+ ports : []string {"0-1:80-81/udp" },
510
+ errorMsg : "Sorry, one of the ports provided with --ports flag is outside range [0-1:80-81/udp]" ,
511
+ },
512
+ {
513
+ isTarget : ! isMicrosoftWSL ,
514
+ ports : []string {"80:80" , "1023-1025:8023-8025" , "1023-1025:8023-8025/tcp" , "1023-1025:8023-8025/udp" },
480
515
errorMsg : "" ,
481
516
},
482
517
{
483
- ports : []string {"127.0.0.1:80:80" },
518
+ isTarget : isMicrosoftWSL ,
519
+ ports : []string {"80:80" },
520
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [80:80]" ,
521
+ },
522
+ {
523
+ isTarget : isMicrosoftWSL ,
524
+ ports : []string {"1023-1025:8023-8025" },
525
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [1023-1025:8023-8025]" ,
526
+ },
527
+ {
528
+ isTarget : isMicrosoftWSL ,
529
+ ports : []string {"1023-1025:8023-8025/tcp" },
530
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [1023-1025:8023-8025/tcp]" ,
531
+ },
532
+ {
533
+ isTarget : isMicrosoftWSL ,
534
+ ports : []string {"1023-1025:8023-8025/udp" },
535
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [1023-1025:8023-8025/udp]" ,
536
+ },
537
+ {
538
+ isTarget : true ,
539
+ ports : []string {"127.0.0.1:8080:80" , "127.0.0.1:8081:80/tcp" , "127.0.0.1:8081:80/udp" , "127.0.0.1:8082-8083:8082-8083/tcp" },
484
540
errorMsg : "" ,
485
541
},
486
542
{
543
+ isTarget : true ,
487
544
ports : []string {"1000.0.0.1:80:80" },
488
- errorMsg : "Sorry, the IP address provided with --ports flag is invalid: 1000.0.0.1" ,
545
+ errorMsg : "Sorry, one of the ports provided with --ports flag is not valid [1000.0.0.1:80:80] (Invalid ip address: 1000.0.0.1)" ,
546
+ },
547
+ {
548
+ isTarget : ! isMicrosoftWSL ,
549
+ ports : []string {"127.0.0.1:80:80" , "127.0.0.1:81:81/tcp" , "127.0.0.1:81:81/udp" , "127.0.0.1:82-83:82-83/tcp" , "127.0.0.1:82-83:82-83/udp" },
550
+ errorMsg : "" ,
551
+ },
552
+ {
553
+ isTarget : isMicrosoftWSL ,
554
+ ports : []string {"127.0.0.1:80:80" },
555
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [127.0.0.1:80:80]" ,
556
+ },
557
+ {
558
+ isTarget : isMicrosoftWSL ,
559
+ ports : []string {"127.0.0.1:81:81/tcp" },
560
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [127.0.0.1:81:81/tcp]" ,
561
+ },
562
+ {
563
+ isTarget : isMicrosoftWSL ,
564
+ ports : []string {"127.0.0.1:81:81/udp" },
565
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [127.0.0.1:81:81/udp]" ,
566
+ },
567
+ {
568
+ isTarget : isMicrosoftWSL ,
569
+ ports : []string {"127.0.0.1:80-83:80-83/tcp" },
570
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [127.0.0.1:80-83:80-83/tcp]" ,
571
+ },
572
+ {
573
+ isTarget : isMicrosoftWSL ,
574
+ ports : []string {"127.0.0.1:80-83:80-83/udp" },
575
+ errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [127.0.0.1:80-83:80-83/udp]" ,
489
576
},
490
- }
491
- if detect .IsMicrosoftWSL () {
492
- tests = append (tests , portTest {
493
- ports : []string {"80:80" },
494
- errorMsg : "Sorry, you cannot use privileged ports on the host (below 1024) [80:80]" ,
495
- })
496
577
}
497
578
for _ , test := range tests {
498
579
t .Run (strings .Join (test .ports , "," ), func (t * testing.T ) {
580
+ if ! test .isTarget {
581
+ return
582
+ }
499
583
gotError := ""
500
584
got := validatePorts (test .ports )
501
585
if got != nil {
0 commit comments