-
Notifications
You must be signed in to change notification settings - Fork 1
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 #116 from AikidoSec/AIK-4395
Add more test coverage
- Loading branch information
Showing
8 changed files
with
474 additions
and
0 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
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,27 @@ | ||
import dev.aikido.agent_api.helpers.logging.LogLevel; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class LogLevelTest { | ||
|
||
@Test | ||
public void testLogLevelValues() { | ||
assertEquals(0, LogLevel.TRACE.getLevel()); | ||
assertEquals(1, LogLevel.DEBUG.getLevel()); | ||
assertEquals(2, LogLevel.INFO.getLevel()); | ||
assertEquals(3, LogLevel.WARN.getLevel()); | ||
assertEquals(4, LogLevel.ERROR.getLevel()); | ||
assertEquals(5, LogLevel.FATAL.getLevel()); | ||
} | ||
|
||
@Test | ||
public void testLogLevelToString() { | ||
assertEquals("TRACE", LogLevel.TRACE.toString()); | ||
assertEquals("DEBUG", LogLevel.DEBUG.toString()); | ||
assertEquals("INFO", LogLevel.INFO.toString()); | ||
assertEquals("WARN", LogLevel.WARN.toString()); | ||
assertEquals("ERROR", LogLevel.ERROR.toString()); | ||
assertEquals("FATAL", LogLevel.FATAL.toString()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package helpers.env; | ||
|
||
import dev.aikido.agent_api.helpers.env.BooleanEnv; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junitpioneer.jupiter.SetEnvironmentVariable; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class BooleanEnvTest { | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "1") | ||
public void testBooleanEnv_WithValueOne() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", false); | ||
assertTrue(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "true") | ||
public void testBooleanEnv_WithValueTrue() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", false); | ||
assertTrue(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "TRUE") | ||
public void testBooleanEnv_WithValueTrueUppercase() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", false); | ||
assertTrue(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "0") | ||
public void testBooleanEnv_WithValueZero() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", true); | ||
assertFalse(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "false") | ||
public void testBooleanEnv_WithValueFalse() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", true); | ||
assertFalse(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "FALSE") | ||
public void testBooleanEnv_WithValueFalseUppercase() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", true); | ||
assertFalse(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "") | ||
public void testBooleanEnv_WithEmptyString() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", true); | ||
assertTrue(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
public void testBooleanEnv_WithNullEnvironmentVariable() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", true); | ||
assertTrue(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "randomString") | ||
public void testBooleanEnv_WithRandomString() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", false); | ||
assertFalse(booleanEnv.getValue()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "TEST_BOOLEAN_ENV", value = "TrUe") | ||
public void testBooleanEnv_WithMixedCaseTrue() { | ||
BooleanEnv booleanEnv = new BooleanEnv("TEST_BOOLEAN_ENV", false); | ||
assertTrue(booleanEnv.getValue()); | ||
} | ||
} |
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,104 @@ | ||
package helpers.env; | ||
|
||
import dev.aikido.agent_api.helpers.env.Endpoints; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junitpioneer.jupiter.SetEnvironmentVariable; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class EndpointsTest { | ||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_ENDPOINT", value = "https://custom.aikido.dev") | ||
public void testGetAikidoAPIEndpoint_WithCustomEndpoint() { | ||
String result = Endpoints.getAikidoAPIEndpoint(); | ||
assertEquals("https://custom.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_ENDPOINT", value = "https://custom.aikido.dev") | ||
public void testGetAikidoAPIEndpoint_WithCustomEndpointWithoutTrailingSlash() { | ||
String result = Endpoints.getAikidoAPIEndpoint(); | ||
assertEquals("https://custom.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_ENDPOINT", value = "") | ||
public void testGetAikidoAPIEndpoint_WithEmptyEnvironmentVariable() { | ||
String result = Endpoints.getAikidoAPIEndpoint(); | ||
assertEquals("https://guard.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
public void testGetAikidoAPIEndpoint_WithNullEnvironmentVariable() { | ||
// No environment variable set, should return default | ||
String result = Endpoints.getAikidoAPIEndpoint(); | ||
assertEquals("https://guard.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_REALTIME_ENDPOINT", value = "https://realtime.aikido.dev") | ||
public void testGetAikidoRealtimeEndpoint_WithCustomEndpoint() { | ||
String result = Endpoints.getAikidoRealtimeEndpoint(); | ||
assertEquals("https://realtime.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_REALTIME_ENDPOINT", value = "https://realtime.aikido.dev") | ||
public void testGetAikidoRealtimeEndpoint_WithCustomEndpointWithoutTrailingSlash() { | ||
String result = Endpoints.getAikidoRealtimeEndpoint(); | ||
assertEquals("https://realtime.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
public void testGetAikidoRealtimeEndpoint_WithNullEnvironmentVariable() { | ||
// No environment variable set, should return default | ||
String result = Endpoints.getAikidoRealtimeEndpoint(); | ||
assertEquals("https://runtime.aikido.dev/", result); | ||
} | ||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_REALTIME_ENDPOINT", value = "https://realtime.aikido.dev/") | ||
public void testGetAikidoRealtimeEndpoint_WithCustomEndpointWithTrailingSlash() { | ||
String result = Endpoints.getAikidoRealtimeEndpoint(); | ||
assertEquals("https://realtime.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_REALTIME_ENDPOINT", value = "") | ||
public void testGetAikidoRealtimeEndpoint_WithEmptyEnvironmentVariable() { | ||
String result = Endpoints.getAikidoRealtimeEndpoint(); | ||
assertEquals("https://runtime.aikido.dev/", result); | ||
} | ||
|
||
// Additional tests | ||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_ENDPOINT", value = "https://missing-slash.aikido.dev") | ||
public void testGetAikidoAPIEndpoint_WithMissingSlash() { | ||
String result = Endpoints.getAikidoAPIEndpoint(); | ||
assertEquals("https://missing-slash.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_ENDPOINT", value = "https://missing-slash.aikido.dev/") | ||
public void testGetAikidoAPIEndpoint_WithTrailingSlashAlreadyPresent() { | ||
String result = Endpoints.getAikidoAPIEndpoint(); | ||
assertEquals("https://missing-slash.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_ENDPOINT", value = "https://another-custom.aikido.dev") | ||
public void testGetAikidoAPIEndpoint_WithAnotherCustomEndpoint() { | ||
String result = Endpoints.getAikidoAPIEndpoint(); | ||
assertEquals("https://another-custom.aikido.dev/", result); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "AIKIDO_ENDPOINT", value = "https://another-custom.aikido.dev/") | ||
public void testGetAikidoAPIEndpoint_WithAnotherCustomEndpointWithTrailingSlash() { | ||
String result = Endpoints.getAikidoAPIEndpoint(); | ||
assertEquals("https://another-custom.aikido.dev/", result); | ||
} | ||
} |
Oops, something went wrong.