-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4025 from DataDog/shatzi/DEBUG-1115/sanitize-env-…
…version-rc-requests Sanitize env version in remote config request
- Loading branch information
Showing
14 changed files
with
194 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/ProbeStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/sink/SnapshotSink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/util/TagsHelper.java
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
...t-debugger/src/test/java/com/datadog/debugger/agent/EnvironmentAndVersionCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.datadog.debugger.agent; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.lenient; | ||
|
||
import datadog.trace.api.Config; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class EnvironmentAndVersionCheckerTest { | ||
|
||
private static final String SERVICE_ENV_PROD = "prod"; | ||
private static final String SERVICE_ENV_PROD_CAP = "PROD"; | ||
private static final String SERVICE_VERSION_1 = "v1.0.0"; | ||
private static final String SERVICE_VERSION_2 = "v1.0.0-SNAPSHOT"; | ||
|
||
@Mock private Config config; | ||
|
||
@Test | ||
public void EmptyTagsPassValidation() { | ||
lenient().when(config.getEnv()).thenReturn(SERVICE_ENV_PROD); | ||
lenient().when(config.getVersion()).thenReturn(SERVICE_VERSION_1); | ||
|
||
EnvironmentAndVersionChecker checker = new EnvironmentAndVersionChecker(config); | ||
|
||
assertEquals(true, checker.isEnvAndVersionMatch(getProbeWithTags())); | ||
} | ||
|
||
@Test | ||
public void EnvironmentTagPassValidation() { | ||
lenient().when(config.getEnv()).thenReturn(SERVICE_ENV_PROD); | ||
lenient().when(config.getVersion()).thenReturn(SERVICE_VERSION_1); | ||
|
||
EnvironmentAndVersionChecker checker = new EnvironmentAndVersionChecker(config); | ||
|
||
assertEquals(true, checker.isEnvAndVersionMatch(getProbeWithTags("env:" + SERVICE_ENV_PROD))); | ||
} | ||
|
||
@Test | ||
public void EnvironmentTagFailedValidation() { | ||
lenient().when(config.getEnv()).thenReturn(SERVICE_ENV_PROD); | ||
lenient().when(config.getVersion()).thenReturn(SERVICE_VERSION_1); | ||
|
||
EnvironmentAndVersionChecker checker = new EnvironmentAndVersionChecker(config); | ||
|
||
assertEquals(false, checker.isEnvAndVersionMatch(getProbeWithTags("env:staging"))); | ||
assertEquals( | ||
false, | ||
checker.isEnvAndVersionMatch( | ||
getProbeWithTags("env:staging", "version:" + SERVICE_VERSION_1))); | ||
} | ||
|
||
@Test | ||
public void EnvironmentTagPassValidationAfterSanitization() { | ||
lenient().when(config.getEnv()).thenReturn(SERVICE_ENV_PROD_CAP); | ||
lenient().when(config.getVersion()).thenReturn(SERVICE_VERSION_1); | ||
|
||
EnvironmentAndVersionChecker checker = new EnvironmentAndVersionChecker(config); | ||
|
||
assertEquals(true, checker.isEnvAndVersionMatch(getProbeWithTags("env:" + SERVICE_ENV_PROD))); | ||
} | ||
|
||
@Test | ||
public void VersionTagFailedValidation() { | ||
lenient().when(config.getEnv()).thenReturn(SERVICE_ENV_PROD); | ||
lenient().when(config.getVersion()).thenReturn(SERVICE_VERSION_1); | ||
|
||
EnvironmentAndVersionChecker checker = new EnvironmentAndVersionChecker(config); | ||
|
||
assertEquals(false, checker.isEnvAndVersionMatch(getProbeWithTags("version:1.2.3"))); | ||
assertEquals( | ||
false, | ||
checker.isEnvAndVersionMatch(getProbeWithTags("env:" + SERVICE_ENV_PROD, "version:1.2.3"))); | ||
} | ||
|
||
@Test | ||
public void VersionTagPassValidation() { | ||
lenient().when(config.getEnv()).thenReturn(SERVICE_ENV_PROD); | ||
lenient().when(config.getVersion()).thenReturn(SERVICE_VERSION_1); | ||
|
||
EnvironmentAndVersionChecker checker = new EnvironmentAndVersionChecker(config); | ||
|
||
assertEquals( | ||
true, checker.isEnvAndVersionMatch(getProbeWithTags("version:" + SERVICE_VERSION_1))); | ||
assertEquals( | ||
true, | ||
checker.isEnvAndVersionMatch( | ||
getProbeWithTags("env:" + SERVICE_ENV_PROD, "version:" + SERVICE_VERSION_1))); | ||
} | ||
|
||
@Test | ||
public void VersionTagPassValidationAfterSanitization() { | ||
lenient().when(config.getEnv()).thenReturn(SERVICE_ENV_PROD_CAP); | ||
lenient().when(config.getVersion()).thenReturn(SERVICE_VERSION_2); | ||
|
||
EnvironmentAndVersionChecker checker = new EnvironmentAndVersionChecker(config); | ||
|
||
assertEquals( | ||
true, | ||
checker.isEnvAndVersionMatch( | ||
getProbeWithTags("version:" + SERVICE_VERSION_2.toLowerCase()))); | ||
} | ||
|
||
private com.datadog.debugger.agent.ProbeDefinition getProbeWithTags(String... tags) { | ||
SnapshotProbe probe = new SnapshotProbe("java", "1", true, tags, null, null, null, null); | ||
|
||
return probe; | ||
} | ||
} |
59 changes: 0 additions & 59 deletions
59
dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/util/TagsHelperTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.