From ff5a0c82a9fe4cc403fbc40595e47c0b60d67cce Mon Sep 17 00:00:00 2001 From: Elvis Souza Date: Thu, 31 Oct 2024 15:16:01 -0300 Subject: [PATCH] Bugfix: Treating npe at networks mapping when network hasn't a gateway ip #580 (#592) * treating npe at network without gateway ip mapping * release notes * [Gradle Release Plugin] - new version commit: '3.30.5-snapshot'. --- RELEASE-NOTES.md | 3 ++ gradle.properties | 2 +- .../dataprovider/mapper/NetworkMapper.java | 1 + .../mapper/NetworkMapperTest.java | 14 +++++++ .../templates/docker/NetworkTemplates.java | 4 ++ .../templates/docker/network/005.json | 39 +++++++++++++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/templates/docker/network/005.json diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 3155555c0..871005db4 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,6 @@ +## 3.30.5 +* Bugfix: Treating npe at networks mapping when network hasn't a gateway ip #580. + ## 3.30.4 * Adjusting binary generation to compatibility. #586 diff --git a/gradle.properties b/gradle.properties index 75a43a930..0de3c7810 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=3.30.4-snapshot +version=3.30.5-snapshot diff --git a/src/main/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/mapper/NetworkMapper.java b/src/main/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/mapper/NetworkMapper.java index e0212689f..ca78526aa 100644 --- a/src/main/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/mapper/NetworkMapper.java +++ b/src/main/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/mapper/NetworkMapper.java @@ -46,6 +46,7 @@ static IP findGatewayIp(com.github.dockerjava.api.model.Network network, IP.Vers .getConfig() .stream() .map(com.github.dockerjava.api.model.Network.Ipam.Config::getGateway) + .filter(Objects::nonNull) .map(NetworkMapper::extractIpIfNeedledWhenGatewayIsSubnet) .map(IP::of) .filter(it -> it.version() == version) diff --git a/src/test/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/mapper/NetworkMapperTest.java b/src/test/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/mapper/NetworkMapperTest.java index 64292f6c0..ebc43482e 100644 --- a/src/test/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/mapper/NetworkMapperTest.java +++ b/src/test/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/mapper/NetworkMapperTest.java @@ -95,4 +95,18 @@ void mustExtractIpWhenASubnetIsSetAtIpv6TheGatewayIp(){ assertEquals("[172.19.0.1, fddb:21e4:36d4:2:0:0:0:1]", network.getGateways().toString()); } + @Test + void mustMapFromCustomNetworkWithoutGateway(){ + + // arrange + final var dockerNetwork = NetworkTemplates.buildCustomIpv4NetworkWithoutGateway(); + + // act + final var network = NetworkMapper.of(dockerNetwork); + + // assert + assertNotNull(network); + assertFalse(network.hasAnyGateway()); + } + } diff --git a/src/test/java/testing/templates/docker/NetworkTemplates.java b/src/test/java/testing/templates/docker/NetworkTemplates.java index 1ae6021c1..1f051219a 100644 --- a/src/test/java/testing/templates/docker/NetworkTemplates.java +++ b/src/test/java/testing/templates/docker/NetworkTemplates.java @@ -47,4 +47,8 @@ public static Network buildHostNetworkWithNoIpam() { public static Network buildBridgeWithSubnetIPAtGatewayProp() { return JsonUtils.readValue(readString("/templates/docker/network/004.json"), Network.class); } + + public static Network buildCustomIpv4NetworkWithoutGateway() { + return JsonUtils.readValue(readString("/templates/docker/network/005.json"), Network.class); + } } diff --git a/src/test/resources/templates/docker/network/005.json b/src/test/resources/templates/docker/network/005.json new file mode 100644 index 000000000..d6c377e98 --- /dev/null +++ b/src/test/resources/templates/docker/network/005.json @@ -0,0 +1,39 @@ +{ + "Name": "tmp_my_network", + "Id": "4832d0e4bb48513ee3fde20aaecfaf6b8ac83476d4365f82fae4001517b20cce", + "Created": "2024-10-31T14:47:27.608173734-03:00", + "Scope": "local", + "Driver": "bridge", + "EnableIPv6": false, + "IPAM": { + "Driver": "default", + "Options": null, + "Config": [ + { + "Subnet": "171.18.0.0/16" + } + ] + }, + "Internal": false, + "Attachable": false, + "Ingress": false, + "ConfigFrom": { + "Network": "" + }, + "ConfigOnly": false, + "Containers": { + "2343a2ab9f8f1898674f349e21316593f31fce539b2b804d7e97cc16d3bf8a3b": { + "Name": "tmp-dns-proxy-1", + "EndpointID": "a809c879ba3dc31d0c387f47eb4f817745534bcf4cf7385a9916832452db4bae", + "MacAddress": "02:42:ab:12:00:0a", + "IPv4Address": "171.18.0.10/16", + "IPv6Address": "" + } + }, + "Options": {}, + "Labels": { + "com.docker.compose.network": "my_network", + "com.docker.compose.project": "tmp", + "com.docker.compose.version": "2.26.1" + } +}