|
17 | 17 | package io.grpc.xds; |
18 | 18 |
|
19 | 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | +import static org.junit.Assert.assertThrows; |
20 | 21 | import static org.mockito.Mockito.mock; |
21 | 22 |
|
22 | 23 | import com.google.common.collect.ImmutableMap; |
@@ -159,6 +160,45 @@ public void findVirtualHostForHostName_exactMatch() { |
159 | 160 | virtualHosts, "foo.googleapis")).isNull(); |
160 | 161 | } |
161 | 162 |
|
| 163 | + @Test |
| 164 | + public void findVirtualHostForHostName_invalidHostName() { |
| 165 | + List<Route> routes = Collections.emptyList(); |
| 166 | + VirtualHost vHost = VirtualHost.create("vhost", |
| 167 | + Collections.singletonList("a.googleapis.com"), routes, |
| 168 | + ImmutableMap.of()); |
| 169 | + List<VirtualHost> virtualHosts = Collections.singletonList(vHost); |
| 170 | + |
| 171 | + // Empty hostName. |
| 172 | + assertThrows(IllegalArgumentException.class, |
| 173 | + () -> RoutingUtils.findVirtualHostForHostName( |
| 174 | + virtualHosts, "")); |
| 175 | + // HostName starting with dot. |
| 176 | + assertThrows(IllegalArgumentException.class, |
| 177 | + () -> RoutingUtils.findVirtualHostForHostName( |
| 178 | + virtualHosts, ".a.googleapis.com")); |
| 179 | + } |
| 180 | + |
| 181 | + @Test |
| 182 | + public void findVirtualHostForHostName_invalidPattern() { |
| 183 | + List<Route> routes = Collections.emptyList(); |
| 184 | + // Empty domain pattern. |
| 185 | + VirtualHost vHostEmpty = VirtualHost.create("vhost-empty", |
| 186 | + Collections.singletonList(""), routes, |
| 187 | + ImmutableMap.of()); |
| 188 | + assertThrows(IllegalArgumentException.class, |
| 189 | + () -> RoutingUtils.findVirtualHostForHostName( |
| 190 | + Collections.singletonList(vHostEmpty), |
| 191 | + "a.googleapis.com")); |
| 192 | + // Domain pattern starting with dot. |
| 193 | + VirtualHost vHostDot = VirtualHost.create("vhost-dot", |
| 194 | + Collections.singletonList(".a.googleapis.com"), routes, |
| 195 | + ImmutableMap.of()); |
| 196 | + assertThrows(IllegalArgumentException.class, |
| 197 | + () -> RoutingUtils.findVirtualHostForHostName( |
| 198 | + Collections.singletonList(vHostDot), |
| 199 | + "a.googleapis.com")); |
| 200 | + } |
| 201 | + |
162 | 202 | @Test |
163 | 203 | public void findVirtualHostForHostName_prefixWildcard() { |
164 | 204 | List<Route> routes = Collections.emptyList(); |
|
0 commit comments