Fixed the failing BadConfigExceptionTest unit test
PATCH 1/1 Fixed the failing BadConfigExceptionTest unit test
Fixed the test by changing the DNS to a string with an invalid char in the invalid-value.conf test configuration file. Also removed the getParsingClass() condition from the parseDnsServers() method as the condition can be never met - the InetAddresses.parse(dnsServer) method always throws the ParseException with the parsingClass set to InetAddress.class.
--- tunnel/src/main/java/com/wireguard/config/Interface.java | 2 +- tunnel/src/test/resources/invalid-value.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tunnel/src/main/java/com/wireguard/config/Interface.java +1 -1
@@ -356,7 +356,7 @@ public final class Interface { try { addDnsServer(InetAddresses.parse(dnsServer)); } catch (final ParseException e) { - if (e.getParsingClass() != InetAddress.class || !InetAddresses.isHostname(dnsServer)) + if (!InetAddresses.isHostname(dnsServer)) throw e; addDnsSearchDomain(dnsServer); }
tunnel/src/test/resources/invalid-value.conf +1 -1
@@ -1,6 +1,6 @@ [Interface] Address = 192.0.2.2/32,2001:db8:ffff:ffff:ffff:ffff:ffff:ffff/128 -DNS = 192.0.2.0,yes +DNS = 192.0.2.0,invalid_value PrivateKey = TFlmmEUC7V7VtiDYLKsbP5rySTKLIZq1yn8lMqK83wo= [Peer] AllowedIPs = 0.0.0.0/0, ::0/0
Signature · 1 line
2.30.1 (Apple Git-130)
Hey Michal,
Quoted 34 lines · Michal Murin
Fixed the test by changing the DNS to a string with an invalid char in the
invalid-value.conftest configuration file. Also removed thegetParsingClass()condition from theparseDnsServers()method as the condition can be never met - theInetAddresses.parse(dnsServer)method always throws theParseExceptionwith theparsingClassset toInetAddress.class.
---
tunnel/src/main/java/com/wireguard/config/Interface.java | 2 +-tunnel/src/test/resources/invalid-value.conf| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)tunnel/src/main/java/com/wireguard/config/Interface.java +1
-1@@ -356,7 +356,7 @@ public final class Interface { try { addDnsServer(InetAddresses.parse(dnsServer)); } catch (final ParseException e) { - if (e.getParsingClass() != InetAddress.class || !InetAddresses.isHostname(dnsServer)) + if (!InetAddresses.isHostname(dnsServer)) throw e; addDnsSearchDomain(dnsServer);}tunnel/src/test/resources/invalid-value.conf +0
-0@@ -1,6 +1,6 @@[Interface]
Address = 192.0.2.2/32,2001:db8:ffff:ffff:ffff:ffff:ffff:ffff/128tunnel/src/test/resources/invalid-value.conf +1
-1-DNS = 192.0.2.0,yes +DNS = 192.0.2.0,invalid_value
Quoted 7 lines
PrivateKey = TFlmmEUC7V7VtiDYLKsbP5rySTKLIZq1yn8lMqK83wo= [Peer]
AllowedIPs = 0.0.0.0/0, ::0/0Signature · 1 line
2.30.1 (Apple Git-130)
Thanks! The patch looks good, if you can send a v2 with a Signed-off-by line I'd be happy to apply this.
Cheers,
Harsh Shandilya
Quoted 1 line · Michal Murin
Also removed the
getParsingClass()condition from theparseDnsServers()method as the condition can be never met - theInetAddresses.parse(dnsServer)method always throws theParseExceptionwith theparsingClassset toInetAddress.class.
Until one day it doesn't, and then we have to remember this subtle behavior. On the contrary, what's there now means that the code is correct regardless of changes.
tunnel/src/main/java/com/wireguard/config/Interface.java public final class Interface { · line 359
Quoted 2 lines
tunnel/src/main/java/com/wireguard/config/Interface.java +1
-1- if (e.getParsingClass() != InetAddress.class || !InetAddresses.isHostname(dnsServer)) + if (!InetAddresses.isHostname(dnsServer))
Please drop this snippet from v2.
As Harsh said, we need your sign off line. It would also be appreciated if you'd wrap your commit message and adjust your commit subject to match what the project uses conventionally.
Thanks,
Jason