@@ -27,6 +27,7 @@ const podIPOpaque = "172.17.0.14"
27
27
const podIPSkipped = "172.17.0.15"
28
28
const podIPPolicy = "172.17.0.16"
29
29
const podIPStatefulSet = "172.17.13.15"
30
+ const externalIP = "192.168.1.20"
30
31
const port uint32 = 8989
31
32
const opaquePort uint32 = 4242
32
33
const skippedPort uint32 = 24224
@@ -1069,6 +1070,68 @@ func TestGetProfiles(t *testing.T) {
1069
1070
t .Fatalf ("Expected pod to support opaque traffic on port 4143" )
1070
1071
}
1071
1072
})
1073
+
1074
+ t .Run ("Return profile with opaque protocol when using an opaque port with an external IP" , func (t * testing.T ) {
1075
+ server := makeServer (t )
1076
+ stream := & bufferingGetProfileStream {
1077
+ updates : []* pb.DestinationProfile {},
1078
+ MockServerStream : util .NewMockServerStream (),
1079
+ }
1080
+ stream .Cancel ()
1081
+
1082
+ _ , err := toAddress (externalIP , 3306 )
1083
+ if err != nil {
1084
+ t .Fatalf ("Got error: %s" , err )
1085
+ }
1086
+ err = server .GetProfile (& pb.GetDestination {
1087
+ Scheme : "k8s" ,
1088
+ Path : fmt .Sprintf ("%s:%d" , externalIP , 3306 ),
1089
+ }, stream )
1090
+ if err != nil {
1091
+ t .Fatalf ("Got error: %s" , err )
1092
+ }
1093
+
1094
+ // Test that the first update has a destination profile with an
1095
+ // opaque protocol and opaque transport.
1096
+ if len (stream .updates ) == 0 {
1097
+ t .Fatalf ("Expected at least 1 update but got 0" )
1098
+ }
1099
+ update := stream .updates [0 ]
1100
+ if ! update .OpaqueProtocol {
1101
+ t .Fatalf ("Expected port %d to be an opaque protocol, but it was not" , 3306 )
1102
+ }
1103
+ })
1104
+
1105
+ t .Run ("Return profile with non-opaque protocol when using an arbitrary port with an external IP" , func (t * testing.T ) {
1106
+ server := makeServer (t )
1107
+ stream := & bufferingGetProfileStream {
1108
+ updates : []* pb.DestinationProfile {},
1109
+ MockServerStream : util .NewMockServerStream (),
1110
+ }
1111
+ stream .Cancel ()
1112
+
1113
+ _ , err := toAddress (externalIP , 80 )
1114
+ if err != nil {
1115
+ t .Fatalf ("Got error: %s" , err )
1116
+ }
1117
+ err = server .GetProfile (& pb.GetDestination {
1118
+ Scheme : "k8s" ,
1119
+ Path : fmt .Sprintf ("%s:%d" , externalIP , 80 ),
1120
+ }, stream )
1121
+ if err != nil {
1122
+ t .Fatalf ("Got error: %s" , err )
1123
+ }
1124
+
1125
+ // Test that the first update has a destination profile with an
1126
+ // opaque protocol and opaque transport.
1127
+ if len (stream .updates ) == 0 {
1128
+ t .Fatalf ("Expected at least 1 update but got 0" )
1129
+ }
1130
+ update := stream .updates [0 ]
1131
+ if update .OpaqueProtocol {
1132
+ t .Fatalf ("Expected port %d to be a non-opaque protocol, but it was opaque" , 80 )
1133
+ }
1134
+ })
1072
1135
}
1073
1136
1074
1137
func TestTokenStructure (t * testing.T ) {
0 commit comments