25
25
26
26
import com .google .common .collect .ImmutableList ;
27
27
import com .google .common .collect .ImmutableMap ;
28
+ import com .google .common .net .InetAddresses ;
28
29
import com .google .common .util .concurrent .SettableFuture ;
29
30
import io .grpc .ServerInterceptor ;
30
31
import io .grpc .internal .TestUtils .NoopChannelLogger ;
58
59
import io .netty .handler .codec .http2 .Http2Settings ;
59
60
import java .net .InetSocketAddress ;
60
61
import java .net .SocketAddress ;
61
- import java .net .UnknownHostException ;
62
62
import java .util .ArrayList ;
63
63
import java .util .Collections ;
64
64
import java .util .HashMap ;
@@ -318,7 +318,8 @@ public void destPrefixRangeMatch() throws Exception {
318
318
EnvoyServerProtoData .FilterChainMatch filterChainMatchWithMatch =
319
319
EnvoyServerProtoData .FilterChainMatch .create (
320
320
0 ,
321
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.1.2.0" , 24 )),
321
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
322
+ InetAddresses .forString ("10.1.2.0" ), 24 )),
322
323
ImmutableList .of (),
323
324
ImmutableList .of (),
324
325
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -360,7 +361,8 @@ public void destPrefixRangeMismatch_returnDefaultFilterChain()
360
361
EnvoyServerProtoData .FilterChainMatch filterChainMatchWithMismatch =
361
362
EnvoyServerProtoData .FilterChainMatch .create (
362
363
0 ,
363
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.2.2.0" , 24 )),
364
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
365
+ InetAddresses .forString ("10.2.2.0" ), 24 )),
364
366
ImmutableList .of (),
365
367
ImmutableList .of (),
366
368
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -403,7 +405,8 @@ public void dest0LengthPrefixRange()
403
405
EnvoyServerProtoData .FilterChainMatch filterChainMatch0Length =
404
406
EnvoyServerProtoData .FilterChainMatch .create (
405
407
0 ,
406
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.2.2.0" , 0 )),
408
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
409
+ InetAddresses .forString ("10.2.2.0" ), 0 )),
407
410
ImmutableList .of (),
408
411
ImmutableList .of (),
409
412
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -444,7 +447,8 @@ public void destPrefixRange_moreSpecificWins()
444
447
EnvoyServerProtoData .FilterChainMatch filterChainMatchLessSpecific =
445
448
EnvoyServerProtoData .FilterChainMatch .create (
446
449
0 ,
447
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.1.2.0" , 24 )),
450
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
451
+ InetAddresses .forString ("10.1.2.0" ), 24 )),
448
452
ImmutableList .of (),
449
453
ImmutableList .of (),
450
454
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -461,7 +465,8 @@ public void destPrefixRange_moreSpecificWins()
461
465
EnvoyServerProtoData .FilterChainMatch filterChainMatchMoreSpecific =
462
466
EnvoyServerProtoData .FilterChainMatch .create (
463
467
0 ,
464
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.1.2.2" , 31 )),
468
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
469
+ InetAddresses .forString ("10.1.2.2" ), 31 )),
465
470
ImmutableList .of (),
466
471
ImmutableList .of (),
467
472
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -519,7 +524,8 @@ public void destPrefixRange_emptyListLessSpecific()
519
524
EnvoyServerProtoData .FilterChainMatch filterChainMatchMoreSpecific =
520
525
EnvoyServerProtoData .FilterChainMatch .create (
521
526
0 ,
522
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("8.0.0.0" , 5 )),
527
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
528
+ InetAddresses .forString ("8.0.0.0" ), 5 )),
523
529
ImmutableList .of (),
524
530
ImmutableList .of (),
525
531
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -559,7 +565,8 @@ public void destPrefixRangeIpv6_moreSpecificWins()
559
565
EnvoyServerProtoData .FilterChainMatch filterChainMatchLessSpecific =
560
566
EnvoyServerProtoData .FilterChainMatch .create (
561
567
0 ,
562
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("FE80:0:0:0:0:0:0:0" , 60 )),
568
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
569
+ InetAddresses .forString ("FE80:0:0:0:0:0:0:0" ), 60 )),
563
570
ImmutableList .of (),
564
571
ImmutableList .of (),
565
572
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -577,7 +584,8 @@ public void destPrefixRangeIpv6_moreSpecificWins()
577
584
EnvoyServerProtoData .FilterChainMatch .create (
578
585
0 ,
579
586
ImmutableList .of (
580
- EnvoyServerProtoData .CidrRange .create ("FE80:0000:0000:0000:0202:0:0:0" , 80 )),
587
+ EnvoyServerProtoData .CidrRange .create (
588
+ InetAddresses .forString ("FE80:0000:0000:0000:0202:0:0:0" ), 80 )),
581
589
ImmutableList .of (),
582
590
ImmutableList .of (),
583
591
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -620,8 +628,10 @@ public void destPrefixRange_moreSpecificWith2Wins()
620
628
EnvoyServerProtoData .FilterChainMatch .create (
621
629
0 ,
622
630
ImmutableList .of (
623
- EnvoyServerProtoData .CidrRange .create ("10.1.2.0" , 24 ),
624
- EnvoyServerProtoData .CidrRange .create (LOCAL_IP , 32 )),
631
+ EnvoyServerProtoData .CidrRange .create (
632
+ InetAddresses .forString ("10.1.2.0" ), 24 ),
633
+ EnvoyServerProtoData .CidrRange .create (
634
+ InetAddresses .forString (LOCAL_IP ), 32 )),
625
635
ImmutableList .of (),
626
636
ImmutableList .of (),
627
637
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -638,7 +648,8 @@ public void destPrefixRange_moreSpecificWith2Wins()
638
648
EnvoyServerProtoData .FilterChainMatch filterChainMatchLessSpecific =
639
649
EnvoyServerProtoData .FilterChainMatch .create (
640
650
0 ,
641
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.1.2.2" , 31 )),
651
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
652
+ InetAddresses .forString ("10.1.2.2" ), 31 )),
642
653
ImmutableList .of (),
643
654
ImmutableList .of (),
644
655
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -763,8 +774,10 @@ public void sourcePrefixRange_moreSpecificWith2Wins()
763
774
ImmutableList .of (),
764
775
ImmutableList .of (),
765
776
ImmutableList .of (
766
- EnvoyServerProtoData .CidrRange .create ("10.4.2.0" , 24 ),
767
- EnvoyServerProtoData .CidrRange .create (REMOTE_IP , 32 )),
777
+ EnvoyServerProtoData .CidrRange .create (
778
+ InetAddresses .forString ("10.4.2.0" ), 24 ),
779
+ EnvoyServerProtoData .CidrRange .create (
780
+ InetAddresses .forString (REMOTE_IP ), 32 )),
768
781
EnvoyServerProtoData .ConnectionSourceType .ANY ,
769
782
ImmutableList .of (),
770
783
ImmutableList .of (),
@@ -781,7 +794,8 @@ public void sourcePrefixRange_moreSpecificWith2Wins()
781
794
0 ,
782
795
ImmutableList .of (),
783
796
ImmutableList .of (),
784
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.4.2.2" , 31 )),
797
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
798
+ InetAddresses .forString ("10.4.2.2" ), 31 )),
785
799
EnvoyServerProtoData .ConnectionSourceType .ANY ,
786
800
ImmutableList .of (),
787
801
ImmutableList .of (),
@@ -811,8 +825,7 @@ filterChainLessSpecific, randomConfig("no-match")),
811
825
}
812
826
813
827
@ Test
814
- public void sourcePrefixRange_2Matchers_expectException ()
815
- throws UnknownHostException {
828
+ public void sourcePrefixRange_2Matchers_expectException () {
816
829
ChannelHandler next = new ChannelInboundHandlerAdapter () {
817
830
@ Override
818
831
public void userEventTriggered (ChannelHandlerContext ctx , Object evt ) {
@@ -831,8 +844,10 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
831
844
ImmutableList .of (),
832
845
ImmutableList .of (),
833
846
ImmutableList .of (
834
- EnvoyServerProtoData .CidrRange .create ("10.4.2.0" , 24 ),
835
- EnvoyServerProtoData .CidrRange .create ("192.168.10.2" , 32 )),
847
+ EnvoyServerProtoData .CidrRange .create (
848
+ InetAddresses .forString ("10.4.2.0" ), 24 ),
849
+ EnvoyServerProtoData .CidrRange .create (
850
+ InetAddresses .forString ("192.168.10.2" ), 32 )),
836
851
EnvoyServerProtoData .ConnectionSourceType .ANY ,
837
852
ImmutableList .of (),
838
853
ImmutableList .of (),
@@ -848,7 +863,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
848
863
0 ,
849
864
ImmutableList .of (),
850
865
ImmutableList .of (),
851
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.4.2.0" , 24 )),
866
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
867
+ InetAddresses .forString ("10.4.2.0" ), 24 )),
852
868
EnvoyServerProtoData .ConnectionSourceType .ANY ,
853
869
ImmutableList .of (),
854
870
ImmutableList .of (),
@@ -890,8 +906,10 @@ public void sourcePortMatch_exactMatchWinsOverEmptyList() throws Exception {
890
906
ImmutableList .of (),
891
907
ImmutableList .of (),
892
908
ImmutableList .of (
893
- EnvoyServerProtoData .CidrRange .create ("10.4.2.0" , 24 ),
894
- EnvoyServerProtoData .CidrRange .create ("10.4.2.2" , 31 )),
909
+ EnvoyServerProtoData .CidrRange .create (
910
+ InetAddresses .forString ("10.4.2.0" ), 24 ),
911
+ EnvoyServerProtoData .CidrRange .create (
912
+ InetAddresses .forString ("10.4.2.2" ), 31 )),
895
913
EnvoyServerProtoData .ConnectionSourceType .ANY ,
896
914
ImmutableList .of (),
897
915
ImmutableList .of (),
@@ -908,7 +926,8 @@ public void sourcePortMatch_exactMatchWinsOverEmptyList() throws Exception {
908
926
0 ,
909
927
ImmutableList .of (),
910
928
ImmutableList .of (),
911
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.4.2.2" , 31 )),
929
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
930
+ InetAddresses .forString ("10.4.2.2" ), 31 )),
912
931
EnvoyServerProtoData .ConnectionSourceType .ANY ,
913
932
ImmutableList .of (7000 , 15000 ),
914
933
ImmutableList .of (),
@@ -966,7 +985,8 @@ public void filterChain_5stepMatch() throws Exception {
966
985
PORT ,
967
986
ImmutableList .of (),
968
987
ImmutableList .of (),
969
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create (REMOTE_IP , 32 )),
988
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
989
+ InetAddresses .forString (REMOTE_IP ), 32 )),
970
990
EnvoyServerProtoData .ConnectionSourceType .ANY ,
971
991
ImmutableList .of (),
972
992
ImmutableList .of (),
@@ -981,9 +1001,11 @@ public void filterChain_5stepMatch() throws Exception {
981
1001
EnvoyServerProtoData .FilterChainMatch filterChainMatch2 =
982
1002
EnvoyServerProtoData .FilterChainMatch .create (
983
1003
0 ,
984
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.1.2.0" , 30 )),
1004
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
1005
+ InetAddresses .forString ("10.1.2.0" ), 30 )),
985
1006
ImmutableList .of (),
986
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.4.0.0" , 16 )),
1007
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
1008
+ InetAddresses .forString ("10.4.0.0" ), 16 )),
987
1009
EnvoyServerProtoData .ConnectionSourceType .ANY ,
988
1010
ImmutableList .of (),
989
1011
ImmutableList .of (),
@@ -997,8 +1019,10 @@ public void filterChain_5stepMatch() throws Exception {
997
1019
EnvoyServerProtoData .FilterChainMatch .create (
998
1020
0 ,
999
1021
ImmutableList .of (
1000
- EnvoyServerProtoData .CidrRange .create ("192.168.2.0" , 24 ),
1001
- EnvoyServerProtoData .CidrRange .create ("10.1.2.0" , 30 )),
1022
+ EnvoyServerProtoData .CidrRange .create (
1023
+ InetAddresses .forString ("192.168.2.0" ), 24 ),
1024
+ EnvoyServerProtoData .CidrRange .create (
1025
+ InetAddresses .forString ("10.1.2.0" ), 30 )),
1002
1026
ImmutableList .of (),
1003
1027
ImmutableList .of (),
1004
1028
EnvoyServerProtoData .ConnectionSourceType .SAME_IP_OR_LOOPBACK ,
@@ -1015,10 +1039,13 @@ public void filterChain_5stepMatch() throws Exception {
1015
1039
EnvoyServerProtoData .FilterChainMatch .create (
1016
1040
0 ,
1017
1041
ImmutableList .of (
1018
- EnvoyServerProtoData .CidrRange .create ("10.1.0.0" , 16 ),
1019
- EnvoyServerProtoData .CidrRange .create ("10.1.2.0" , 30 )),
1042
+ EnvoyServerProtoData .CidrRange .create (
1043
+ InetAddresses .forString ("10.1.0.0" ), 16 ),
1044
+ EnvoyServerProtoData .CidrRange .create (
1045
+ InetAddresses .forString ("10.1.2.0" ), 30 )),
1020
1046
ImmutableList .of (),
1021
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.4.2.0" , 24 )),
1047
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
1048
+ InetAddresses .forString ("10.4.2.0" ), 24 )),
1022
1049
EnvoyServerProtoData .ConnectionSourceType .EXTERNAL ,
1023
1050
ImmutableList .of (16000 , 9000 ),
1024
1051
ImmutableList .of (),
@@ -1034,12 +1061,16 @@ public void filterChain_5stepMatch() throws Exception {
1034
1061
EnvoyServerProtoData .FilterChainMatch .create (
1035
1062
0 ,
1036
1063
ImmutableList .of (
1037
- EnvoyServerProtoData .CidrRange .create ("10.1.0.0" , 16 ),
1038
- EnvoyServerProtoData .CidrRange .create ("10.1.2.0" , 30 )),
1064
+ EnvoyServerProtoData .CidrRange .create (
1065
+ InetAddresses .forString ("10.1.0.0" ), 16 ),
1066
+ EnvoyServerProtoData .CidrRange .create (
1067
+ InetAddresses .forString ("10.1.2.0" ), 30 )),
1039
1068
ImmutableList .of (),
1040
1069
ImmutableList .of (
1041
- EnvoyServerProtoData .CidrRange .create ("10.4.2.0" , 24 ),
1042
- EnvoyServerProtoData .CidrRange .create ("192.168.2.0" , 24 )),
1070
+ EnvoyServerProtoData .CidrRange .create (
1071
+ InetAddresses .forString ("10.4.2.0" ), 24 ),
1072
+ EnvoyServerProtoData .CidrRange .create (
1073
+ InetAddresses .forString ("192.168.2.0" ), 24 )),
1043
1074
EnvoyServerProtoData .ConnectionSourceType .ANY ,
1044
1075
ImmutableList .of (15000 , 8000 ),
1045
1076
ImmutableList .of (),
@@ -1053,7 +1084,8 @@ public void filterChain_5stepMatch() throws Exception {
1053
1084
EnvoyServerProtoData .FilterChainMatch filterChainMatch6 =
1054
1085
EnvoyServerProtoData .FilterChainMatch .create (
1055
1086
0 ,
1056
- ImmutableList .of (EnvoyServerProtoData .CidrRange .create ("10.1.2.0" , 29 )),
1087
+ ImmutableList .of (EnvoyServerProtoData .CidrRange .create (
1088
+ InetAddresses .forString ("10.1.2.0" ), 29 )),
1057
1089
ImmutableList .of (),
1058
1090
ImmutableList .of (),
1059
1091
EnvoyServerProtoData .ConnectionSourceType .ANY ,
@@ -1105,8 +1137,8 @@ public void filterChainMatch_unsupportedMatchers() throws Exception {
1105
1137
EnvoyServerProtoData .FilterChainMatch filterChainMatch1 =
1106
1138
EnvoyServerProtoData .FilterChainMatch .create (
1107
1139
0 /* destinationPort */ ,
1108
- ImmutableList .of (
1109
- EnvoyServerProtoData . CidrRange . create ("10.1.0.0" , 16 )) /* prefixRange */ ,
1140
+ ImmutableList .of (EnvoyServerProtoData . CidrRange . create (
1141
+ InetAddresses . forString ("10.1.0.0" ) , 16 )) /* prefixRange */ ,
1110
1142
ImmutableList .of ("managed-mtls" , "h2" ) /* applicationProtocol */ ,
1111
1143
ImmutableList .of () /* sourcePrefixRanges */ ,
1112
1144
EnvoyServerProtoData .ConnectionSourceType .ANY /* sourceType */ ,
@@ -1117,8 +1149,8 @@ public void filterChainMatch_unsupportedMatchers() throws Exception {
1117
1149
EnvoyServerProtoData .FilterChainMatch filterChainMatch2 =
1118
1150
EnvoyServerProtoData .FilterChainMatch .create (
1119
1151
0 /* destinationPort */ ,
1120
- ImmutableList .of (
1121
- EnvoyServerProtoData . CidrRange . create ("10.0.0.0" , 8 )) /* prefixRange */ ,
1152
+ ImmutableList .of (EnvoyServerProtoData . CidrRange . create (
1153
+ InetAddresses . forString ("10.0.0.0" ) , 8 )) /* prefixRange */ ,
1122
1154
ImmutableList .of () /* applicationProtocol */ ,
1123
1155
ImmutableList .of () /* sourcePrefixRanges */ ,
1124
1156
EnvoyServerProtoData .ConnectionSourceType .ANY /* sourceType */ ,
0 commit comments