-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend/frontend] add architecture to executable payloads for filtering
- Loading branch information
1 parent
43dc264
commit 93cf82a
Showing
34 changed files
with
320 additions
and
38 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
openbas-api/src/main/java/io/openbas/migration/V3_44__Add_column_executable_arch.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,20 @@ | ||
package io.openbas.migration; | ||
|
||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.sql.Connection; | ||
import java.sql.Statement; | ||
|
||
@Component | ||
public class V3_44__Add_column_executable_arch extends BaseJavaMigration { | ||
|
||
@Override | ||
public void migrate(Context context) throws Exception { | ||
Connection connection = context.getConnection(); | ||
Statement statement = connection.createStatement(); | ||
statement.execute("ALTER TABLE payloads ADD executable_arch varchar(255);"); | ||
statement.execute("UPDATE payloads SET executable_arch = 'x86_64' WHERE payload_type ='Executable';"); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -49,7 +49,7 @@ public class InjectHelperTest { | |
void injectsToRunTest() { | ||
// -- PREPARE -- | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setName("Exercise name"); | ||
exercise.setStart(Instant.now()); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setReplyTos(List.of("[email protected]")); | ||
|
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 |
---|---|---|
|
@@ -32,7 +32,7 @@ class InjectCrudTest { | |
void createInjectSuccess() { | ||
// -- PREPARE -- | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setName("Exercise name"); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setReplyTos(List.of("[email protected]")); | ||
Exercise exerciseCreated = this.exerciseRepository.save(exercise); | ||
|
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
68 changes: 68 additions & 0 deletions
68
openbas-api/src/test/java/io/openbas/rest/PayloadApiTest.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,68 @@ | ||
package io.openbas.rest; | ||
|
||
import io.openbas.IntegrationTest; | ||
import io.openbas.database.model.Document; | ||
import io.openbas.database.model.Endpoint; | ||
import io.openbas.database.model.Payload; | ||
import io.openbas.database.repository.DocumentRepository; | ||
import io.openbas.rest.payload.form.PayloadCreateInput; | ||
import io.openbas.utils.mockUser.WithMockAdminUser; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static io.openbas.utils.JsonUtils.asJsonString; | ||
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@TestInstance(PER_CLASS) | ||
public class PayloadApiTest extends IntegrationTest { | ||
|
||
private static final String PAYLOAD_URI = "/api/payloads"; | ||
private static Document EXECUTABLE_FILE; | ||
|
||
@Autowired | ||
private MockMvc mvc; | ||
@Autowired | ||
private DocumentRepository documentRepository; | ||
|
||
@BeforeAll | ||
void beforeAll() { | ||
Document executableFile = new Document(); | ||
executableFile.setName("Executable file"); | ||
executableFile.setType("text/x-sh"); | ||
EXECUTABLE_FILE = documentRepository.save(executableFile); | ||
} | ||
|
||
@AfterAll | ||
void afterAll() { | ||
this.documentRepository.deleteAll(List.of(EXECUTABLE_FILE)); | ||
} | ||
@Test | ||
@DisplayName("Create Executable Payload") | ||
@WithMockAdminUser | ||
void createExecutablePayload() throws Exception { | ||
PayloadCreateInput input = new PayloadCreateInput(); | ||
input.setType("Executable"); | ||
input.setName("My Executable Payload"); | ||
input.setSource(Payload.PAYLOAD_SOURCE.MANUAL); | ||
input.setStatus(Payload.PAYLOAD_STATUS.VERIFIED); | ||
input.setPlatforms(new Endpoint.PLATFORM_TYPE[]{Endpoint.PLATFORM_TYPE.Linux}); | ||
input.setAttackPatternsIds(Collections.emptyList()); | ||
input.setTagIds(Collections.emptyList()); | ||
input.setExecutableArch(Endpoint.PLATFORM_ARCH.x86_64); | ||
input.setExecutableFile(EXECUTABLE_FILE.getId()); | ||
|
||
mvc.perform(post(PAYLOAD_URI) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(asJsonString(input))) | ||
.andExpect(status().is2xxSuccessful()) | ||
.andExpect(jsonPath("$.executable_arch").value("x86_64")); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,10 +7,7 @@ | |
import io.openbas.database.repository.*; | ||
import io.openbas.rest.exercise.form.ExpectationUpdateInput; | ||
import io.openbas.utils.fixtures.InjectExpectationFixture; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
|
@@ -57,6 +54,11 @@ void beforeAll() { | |
getInjectExpectation(injectCreated, teamCreated, exerciseCreated); | ||
} | ||
|
||
@AfterAll | ||
void afterAll() { | ||
this.exerciseRepository.deleteById(EXERCISE_ID); | ||
} | ||
|
||
@DisplayName("Retrieve inject expectations") | ||
@Test | ||
void retrieveInjectExpectations() { | ||
|
@@ -86,7 +88,7 @@ void updateInjectExpectation() { | |
|
||
protected Exercise getExercise() { | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setName("Exercise name"); | ||
exercise.setStatus(SCHEDULED); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setReplyTos(List.of("[email protected]")); | ||
|
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 |
---|---|---|
|
@@ -59,7 +59,7 @@ public class InjectTestStatusServiceTest { | |
@BeforeAll | ||
void beforeAll() { | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setName("Exercise name"); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setReplyTos(List.of("[email protected]")); | ||
EXERCISE = this.exerciseRepository.save(exercise); | ||
|
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 |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
import java.util.NoSuchElementException; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; | ||
|
||
@SpringBootTest | ||
@TestInstance(PER_CLASS) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class VariableServiceTest { | ||
|
||
|
@@ -23,24 +25,32 @@ public class VariableServiceTest { | |
@Autowired | ||
private ExerciseRepository exerciseRepository; | ||
|
||
static String EXERCISE_ID; | ||
static Exercise EXERCISE; | ||
static String VARIABLE_ID; | ||
|
||
@BeforeAll | ||
void beforeAll() { | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercise name"); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setReplyTos(List.of("[email protected]")); | ||
EXERCISE = this.exerciseRepository.save(exercise); | ||
} | ||
|
||
@AfterAll | ||
void afterAll() { | ||
this.exerciseRepository.deleteById(EXERCISE.getId()); | ||
} | ||
|
||
@DisplayName("Create variable") | ||
@Test | ||
@Order(1) | ||
void createVariableTest() { | ||
// -- PREPARE -- | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setReplyTos(List.of("[email protected]")); | ||
Exercise exerciseCreated = this.exerciseRepository.save(exercise); | ||
EXERCISE_ID = exerciseCreated.getId(); | ||
Variable variable = new Variable(); | ||
String variableKey = "key"; | ||
variable.setKey(variableKey); | ||
variable.setExercise(exerciseCreated); | ||
variable.setExercise(EXERCISE); | ||
|
||
// -- EXECUTE -- | ||
Variable variableCreated = this.variableService.createVariable(variable); | ||
|
@@ -60,7 +70,7 @@ void retrieveVariableTest() { | |
Variable variable = this.variableService.variable(VARIABLE_ID); | ||
assertNotNull(variable); | ||
|
||
List<Variable> variables = this.variableService.variablesFromExercise(EXERCISE_ID); | ||
List<Variable> variables = this.variableService.variablesFromExercise(EXERCISE.getId()); | ||
assertNotNull(variable); | ||
assertEquals(VARIABLE_ID, variables.get(0).getId()); | ||
} | ||
|
Oops, something went wrong.