Skip to contentSkip to conversation

Fixed the failing BadConfigExceptionTest unit test

PATCH In review Michal Murin 3 participants 3 messages Jan 25, 2022 – Jan 26, 2022

lore
Share & tools
lore
#0 lore raw

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
index 694f313..5bd4da7 100644
@@ -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
index 2889111..6a1e3b6 100644
@@ -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)
#1 lore raw

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.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
index 694f313..5bd4da7 100644
@@ -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
index 2889111..6a1e3b6 100644
@@ -1,6 +1,6 @@

[Interface]
Address = 192.0.2.2/32,2001:db8:ffff:ffff:ffff:ffff:ffff:ffff/128

tunnel/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/0

Signature · 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

#2 lore raw
In reply to Michal Murin
Quoted 1 line · Michal Murin

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.

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