Skip to content
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

#23971 IPUtils Test failure from incorrect state of IPUtils.disabledIpPrivateSubnet #23972

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/build-core/src/core-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const COMMANDS: Commands = {
gradle: [
{
cmd: gradleCmd,
args: ['createDistPrep'],
args: ['createDistPrep', '--stacktrace'],
wezell marked this conversation as resolved.
Show resolved Hide resolved
workingDir: dotCmsRoot
}
],
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/run-integration-tests/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports.COMMANDS = {
gradle: [
{
cmd: './gradlew',
args: ['integrationTest', `-PdatabaseType=${dbType}`],
args: ['integrationTest', `-PdatabaseType=${dbType}`, '--stacktrace'],
wezell marked this conversation as resolved.
Show resolved Hide resolved
workingDir: dotCmsRoot
}
],
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/run-integration-tests/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const COMMANDS: Commands = {
gradle: [
{
cmd: './gradlew',
args: ['integrationTest', `-PdatabaseType=${dbType}`],
args: ['integrationTest', `-PdatabaseType=${dbType}`, '--stacktrace'],
wezell marked this conversation as resolved.
Show resolved Hide resolved
workingDir: dotCmsRoot
}
],
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/run-unit-tests/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const reportDir = `${dotCmsRoot}/build/reports/tests/test`;
exports.COMMANDS = {
gradle: {
cmd: './gradlew',
args: ['test'],
args: ['test', '--stacktrace'],
wezell marked this conversation as resolved.
Show resolved Hide resolved
workingDir: dotCmsRoot,
outputDir: outputDir,
reportDir: reportDir
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/run-unit-tests/src/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Commands {
export const COMMANDS: Commands = {
gradle: {
cmd: './gradlew',
args: ['test'],
args: ['test', '--stacktrace'],
workingDir: dotCmsRoot,
outputDir: outputDir,
reportDir: reportDir
Expand Down
7 changes: 4 additions & 3 deletions dotCMS/src/main/java/com/dotcms/util/network/IPUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dotcms.util.network;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import org.xbill.DNS.Address;
import com.dotcms.repackage.org.apache.commons.net.util.SubnetUtils;
import com.dotmarketing.util.Config;
Expand All @@ -10,7 +11,7 @@
import io.vavr.control.Try;

public class IPUtils {
private static boolean disabledIpPrivateSubnet = false;
private static final AtomicBoolean disabledIpPrivateSubnet = new AtomicBoolean(false);

private IPUtils() {
throw new IllegalStateException("static Utility class");
Expand Down Expand Up @@ -71,7 +72,7 @@ public static boolean isIpInCIDR(final String ip, final String CIDR) {
public static boolean isIpPrivateSubnet(final String ipOrHostName) {


if (disabledIpPrivateSubnet) {
if (disabledIpPrivateSubnet.get()) {
return false;
}

Expand Down Expand Up @@ -102,6 +103,6 @@ public static boolean isIpPrivateSubnet(final String ipOrHostName) {


public static void disabledIpPrivateSubnet(final boolean disabledIpPrivateSubnet) {
IPUtils.disabledIpPrivateSubnet = disabledIpPrivateSubnet;
IPUtils.disabledIpPrivateSubnet.set(disabledIpPrivateSubnet);
}
}
19 changes: 12 additions & 7 deletions dotCMS/src/test/java/com/dotcms/cube/CubeJSClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,21 @@ public void http404() {
final String cubeServerIp = "127.0.0.1";
final int cubeJsServerPort = 8000;

IPUtils.disabledIpPrivateSubnet(true);
try {
IPUtils.disabledIpPrivateSubnet(true);

final CubeJSQuery cubeJSQuery = new Builder()
.dimensions("Events.experiment", "Events.variant")
.build();
final CubeJSQuery cubeJSQuery = new Builder()
.dimensions("Events.experiment", "Events.variant")
.build();

final CubeJSClient cubeClient = new CubeJSClient(String.format("http://%s:%s", cubeServerIp, cubeJsServerPort));
final CubeJSResultSet cubeJSResultSet = cubeClient.send(cubeJSQuery);
final CubeJSClient cubeClient = new CubeJSClient(
String.format("http://%s:%s", cubeServerIp, cubeJsServerPort));
final CubeJSResultSet cubeJSResultSet = cubeClient.send(cubeJSQuery);

assertEquals(0, cubeJSResultSet.size());
assertEquals(0, cubeJSResultSet.size());
} finally {
IPUtils.disabledIpPrivateSubnet(false);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void test_false_cases() {
@Test
public void test_ip_private_subnets() {
for(String testCase : ipsOnPrivateSubnets) {
assertTrue( IPUtils.isIpPrivateSubnet(testCase));
assertTrue(String.format("Testcase %s failed",testCase), IPUtils.isIpPrivateSubnet(testCase));
}
}
@Test
Expand Down