-
Notifications
You must be signed in to change notification settings - Fork 4k
xds: listener type validation #11933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
4eb625a
ad90963
01927a6
8780c52
76270a4
da0d5ab
ba8af22
694c2f1
506bbe4
87aad6f
239f167
ca5bb14
cb41652
e07158f
9f79e8c
d8fb13a
6873d59
b3908f1
4dc1039
3a36c2d
f82d899
eee4ea9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -453,14 +453,12 @@ public void onChanged(final LdsUpdate update) { | |
| private boolean ipAddressesMatch(String ldsAddress) { | ||
| HostAndPort ldsAddressHnP = HostAndPort.fromString(ldsAddress); | ||
| HostAndPort listenerAddressHnP = HostAndPort.fromString(listenerAddress); | ||
|
|
||
| InetAddress listenerIp = InetAddresses.forString(listenerAddressHnP.getHost()); | ||
| InetAddress ldsIp = InetAddresses.forString(ldsAddressHnP.getHost()); | ||
| if (!ldsAddressHnP.hasPort() || !listenerAddressHnP.hasPort() | ||
| || ldsAddressHnP.getPort() != listenerAddressHnP.getPort()) { | ||
| return false; | ||
| } | ||
|
|
||
| InetAddress listenerIp = InetAddresses.forString(listenerAddressHnP.getHost()); | ||
| InetAddress ldsIp = InetAddresses.forString(ldsAddressHnP.getHost()); | ||
| return listenerIp.equals(ldsIp); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you get problems with the previous way?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, there were no problems here but I think if port isn't available or ports are not same then there's no point of parsing HostAndPort into InetAddress |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -542,7 +542,36 @@ public void run() { | |
| } | ||
|
|
||
| @Test | ||
| public void onChanged_listenerAddressMismatch() | ||
| public void onChanged_listenerIsNull() | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| xdsServerWrapper = new XdsServerWrapper("10.1.2.3:1", mockBuilder, listener, | ||
| selectorManager, new FakeXdsClientPoolFactory(xdsClient), | ||
| filterRegistry, executor.getScheduledExecutorService()); | ||
| final SettableFuture<Server> start = SettableFuture.create(); | ||
| Executors.newSingleThreadExecutor().execute(new Runnable() { | ||
ejona86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| public void run() { | ||
| try { | ||
| start.set(xdsServerWrapper.start()); | ||
| } catch (Exception ex) { | ||
| start.setException(ex); | ||
| } | ||
| } | ||
| }); | ||
| String ldsResource = xdsClient.ldsResource.get(5, TimeUnit.SECONDS); | ||
| assertThat(ldsResource).isEqualTo("grpc/server?udpa.resource.listening_address=10.1.2.3:1"); | ||
| VirtualHost virtualHost = | ||
| VirtualHost.create( | ||
| "virtual-host", Collections.singletonList("auth"), new ArrayList<Route>(), | ||
| ImmutableMap.<String, FilterConfig>of()); | ||
|
|
||
| xdsClient.deliverLdsUpdateWithApiListener(0L, Arrays.asList(virtualHost)); | ||
|
|
||
| verify(listener, timeout(10000)).onNotServing(any()); | ||
| } | ||
|
|
||
| @Test | ||
| public void onChanged_listenerAddressMissingPort() | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| xdsServerWrapper = new XdsServerWrapper("10.1.2.3:1", mockBuilder, listener, | ||
| selectorManager, new FakeXdsClientPoolFactory(xdsClient), | ||
|
|
@@ -570,7 +599,7 @@ public void run() { | |
| "filter-chain-foo", createMatch(), httpConnectionManager, createTls(), | ||
| mock(TlsContextManager.class)); | ||
| LdsUpdate listenerUpdate = LdsUpdate.forTcpListener( | ||
| Listener.create("listener", "20.3.4.5:1", | ||
| Listener.create("listener", "20.3.4.5:", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it work if you commit the trailing ':' ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For this test case, NO because even if I give same port it will fail at hostname matching, ldsHostname(
No it doesn't work without hostname. It fails when we convert to InetAddress using InetAddresses.forString("") using empty string as hostname. |
||
| ImmutableList.copyOf(Collections.singletonList(filterChain)), null, Protocol.TCP)); | ||
|
|
||
| xdsClient.deliverLdsUpdate(listenerUpdate); | ||
|
|
@@ -579,7 +608,7 @@ public void run() { | |
| } | ||
|
|
||
| @Test | ||
| public void onChanged_listenerIsNull() | ||
| public void onChanged_listenerAddressMismatch() | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| xdsServerWrapper = new XdsServerWrapper("10.1.2.3:1", mockBuilder, listener, | ||
| selectorManager, new FakeXdsClientPoolFactory(xdsClient), | ||
|
|
@@ -601,8 +630,16 @@ public void run() { | |
| VirtualHost.create( | ||
| "virtual-host", Collections.singletonList("auth"), new ArrayList<Route>(), | ||
| ImmutableMap.<String, FilterConfig>of()); | ||
| HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts( | ||
| 0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>()); | ||
| EnvoyServerProtoData.FilterChain filterChain = EnvoyServerProtoData.FilterChain.create( | ||
| "filter-chain-foo", createMatch(), httpConnectionManager, createTls(), | ||
| mock(TlsContextManager.class)); | ||
| LdsUpdate listenerUpdate = LdsUpdate.forTcpListener( | ||
| Listener.create("listener", "20.3.4.5:1", | ||
| ImmutableList.copyOf(Collections.singletonList(filterChain)), null, Protocol.TCP)); | ||
|
|
||
| xdsClient.deliverLdsUpdateWithApiListener(0L, Arrays.asList(virtualHost)); | ||
| xdsClient.deliverLdsUpdate(listenerUpdate); | ||
|
|
||
| verify(listener, timeout(10000)).onNotServing(any()); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.