Skip to content

Commit

Permalink
[backend] Add enabled property to injectInput in order to create inje…
Browse files Browse the repository at this point in the history
…cts with a disable status
  • Loading branch information
savacano28 committed Dec 18, 2024
1 parent e31e29d commit fda570e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class InjectInput {
@JsonProperty("inject_tags")
private List<String> tagIds = new ArrayList<>();

@JsonProperty("inject_enabled")
private boolean enabled = true;

public Inject toInject(@NotNull final InjectorContract injectorContract) {
Inject inject = new Inject();
inject.setTitle(getTitle());
Expand All @@ -66,6 +69,7 @@ public Inject toInject(@NotNull final InjectorContract injectorContract) {
inject.setAllTeams(isAllTeams());
inject.setCountry(getCountry());
inject.setCity(getCity());
inject.setEnabled(isEnabled());
return inject;
}
}
28 changes: 27 additions & 1 deletion openbas-api/src/test/java/io/openbas/octi/OpenCTIApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void testCreateScenario_ValidInput() throws Exception {
@Test
@DisplayName(
"Test to validate existence of 'Add Inject to Scenario' endpoint and validate InjectInput")
public void testCreateInjectForScenario_ValidInput() throws Exception {
public void testCreateInjectForScenario_ValidInput_Additional_param() throws Exception {
// -- PREPARE --
String jsonInput =
"{"
Expand All @@ -174,6 +174,7 @@ public void testCreateInjectForScenario_ValidInput() throws Exception {
+ "\"inject_content\": null, "
+ "\"inject_depends_duration\": 100, "
+ "\"inject_tags\": [\"Tag1\"], "
+ "\"inject_enabled\": false, "
+ "\"inject_additional_param\": \"additional_param\""
+ "}";

Expand All @@ -186,6 +187,31 @@ public void testCreateInjectForScenario_ValidInput() throws Exception {
.andExpect(status().isOk());
}

// -- INJECTS --
@Test
@DisplayName(
"Test to validate existence of 'Add Inject to Scenario' endpoint and validate InjectInput")
public void testCreateInjectForScenario_ValidInput_Without_Param() throws Exception {
// -- PREPARE --
String jsonInput =
"{"
+ "\"inject_title\": \"Valid Title\", "
+ "\"inject_type\": \"openbas_email\", "
+ "\"inject_injector_contract\": \"contract-id\", "
+ "\"inject_content\": null, "
+ "\"inject_depends_duration\": 100, "
+ "\"inject_tags\": [\"Tag1\"] "
+ "}";

// -- EXECUTE --
mockMvc
.perform(
post("/api/scenarios/{scenarioId}/injects", "scenario-id")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonInput))
.andExpect(status().isOk());
}

// -- LAST EXERCISE BY EXTERNAL ID --
@Test
@DisplayName("Test to validate existence of the Get Last Exercise Result endpoint")
Expand Down

0 comments on commit fda570e

Please sign in to comment.