Skip to content

Commit

Permalink
Fixing noRemoteServers wasn't being respected at the JSON file #513 (
Browse files Browse the repository at this point in the history
…#515)

* bug and test fixed

* fixing one more test

* release notes

* [Gradle Release Plugin] - new version commit:  '3.24.1-snapshot'.
  • Loading branch information
mageddo authored Jul 16, 2024
1 parent 5321bd1 commit f7c5148
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 9 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.24.1
* Fixing `noRemoteServers` wasn't being respected at the JSON file #513

## 3.24.0
* Downgraded necessary libc version to run aarch binary to 2.28 #507

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=3.24.0-snapshot
version=3.24.1-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.mageddo.dnsproxyserver.config.Config;
import com.mageddo.dnsproxyserver.config.SolverRemote;
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJson;
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJsonV2;
import com.mageddo.dnsproxyserver.utils.Booleans;
import org.apache.commons.lang3.ObjectUtils;

import java.nio.file.Path;

Expand Down Expand Up @@ -34,14 +36,30 @@ public static Config toConfig(ConfigJson json, Path configFileAbsolutePath) {
}

static SolverRemote toSolverRemote(ConfigJson json) {
final var solverRemote = json.getSolverRemote();
if (solverRemote == null) {
return null;
}
final var circuitBreaker = solverRemote.getCircuitBreaker();
if (circuitBreaker == null) {
if(nothingIsSet(json)){
return null;
} else if (isPossibleToBuildComplete(json)) {
return buildCompleteSolverRemote(json, json.getSolverRemoteCircuitBreaker());
}
return buildSimpleSolverRemote(json);
}

static boolean nothingIsSet(ConfigJson json) {
return ObjectUtils.allNull(json.getNoRemoteServers(), json.getSolverRemote(), json.getSolverRemoteCircuitBreaker());
}

static boolean isPossibleToBuildComplete(ConfigJson json) {
return ObjectUtils.allNotNull(json.getSolverRemote(), json.getSolverRemoteCircuitBreaker());
}

static SolverRemote buildSimpleSolverRemote(ConfigJson json) {
return SolverRemote
.builder()
.active(Booleans.reverseWhenNotNull(json.getNoRemoteServers()))
.build();
}

static SolverRemote buildCompleteSolverRemote(ConfigJson json, ConfigJsonV2.CircuitBreaker circuitBreaker) {
return SolverRemote
.builder()
.active(Booleans.reverseWhenNotNull(json.getNoRemoteServers()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public interface ConfigJson {

ConfigJsonV2.SolverRemote getSolverRemote();

ConfigJsonV2.CircuitBreaker getSolverRemoteCircuitBreaker();

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public ConfigJsonV2.SolverRemote getSolverRemote() {
return null;
}

@Override
public ConfigJsonV2.CircuitBreaker getSolverRemoteCircuitBreaker() {
return null;
}

public ConfigJsonV2 toConfigV2() {
return new ConfigJsonV2()
.setDomain(this.getDomain())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public Boolean getDockerSolverHostMachineFallbackActive() {
return this.dockerSolverHostMachineFallbackActive;
}

@JsonIgnore
@Override
public CircuitBreaker getSolverRemoteCircuitBreaker() {
if (this.solverRemote != null) {
return this.solverRemote.circuitBreaker;
}
return null;
}

@Data
@Accessors(chain = true)
public static class Env {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.mageddo.dnsproxyserver.config.Config;
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJson;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import testing.templates.ConfigJsonTemplates;

import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;

class ConfigJsonV2MapperTest {

Expand All @@ -28,7 +28,6 @@ void mustMapSolverRemoteAsInactiveWhenNoRemoteServersFlagIsSet(){
}

@Test
@Disabled("by the bug reported at #513")
void mustMapSolverRemoteAsInactiveEvenWhenCircuitBreakerIsNOTSet(){
// arrange
final var configJson = ConfigJsonTemplates.withoutCircuitBreakerDefinedWithNoRemoteServers();
Expand All @@ -40,6 +39,18 @@ void mustMapSolverRemoteAsInactiveEvenWhenCircuitBreakerIsNOTSet(){
assertFalse(config.isSolverRemoteActive());
}

@Test
void mustReturnNullWhenNothingIsSet(){
// arrange
final var configJson = ConfigJsonTemplates.noRemoteServerFlagsSet();

// act
final var config = toConfig(configJson);

// assert
assertNull(config.getSolverRemote());
}

static Config toConfig(ConfigJson configJson) {
return ConfigJsonV2Mapper.toConfig(configJson, RANDOM_CONFIG_PATH);
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/testing/templates/ConfigJsonTemplates.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ public static ConfigJson withoutCircuitBreakerDefinedWithNoRemoteServers() {
final var path = "/configs-test/007.json";
return JsonConfigs.loadConfig(TestUtils.readString(path));
}

public static ConfigJson noRemoteServerFlagsSet() {
final var path = "/configs-test/008.json";
return JsonConfigs.loadConfig(TestUtils.readString(path));
}

}
19 changes: 19 additions & 0 deletions src/test/resources/configs-test/008.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version" : 2,
"activeEnv" : "MARROI",
"remoteDnsServers" : [ ],
"envs" : [ {
"name" : "MARROI",
"hostnames" : null
} ],
"webServerPort" : 9393,
"dnsServerPort" : 5391,
"defaultDns" : false,
"logLevel" : "DEBUG",
"logFile" : "true",
"registerContainerNames" : true,
"hostMachineHostname" : "batata.com",
"domain" : "acme",
"dpsNetwork" : true,
"dpsNetworkAutoConnect" : true
}

0 comments on commit f7c5148

Please sign in to comment.