Skip to content

Commit

Permalink
Fixed storage problem and enhanced integration tests #3026
Browse files Browse the repository at this point in the history
  • Loading branch information
de-jcup committed Jun 7, 2024
1 parent ba0f3ab commit 8029f32
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static AssertReport assertReport(String json) {
}

public AssertReport enablePDSAutoDumpOnErrorsForSecHubJob(UUID sechubJobUUID) {
this.autoDumper.setSecHubReport(report);
this.autoDumper.enablePDSAutoDumpOnErrorsForSecHubJob();
this.autoDumper.setSecHubJobUUID(sechubJobUUID);
return this;
Expand All @@ -59,7 +60,7 @@ public AssertReport hasFindings(int expectedCount) {
return this;
}

public AssertReportUnordered hasUnordered() {
public AssertReportUnordered assertUnordered() {
return AssertReportUnordered.assertReportUnordered(report.toJSON());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ private enum StorageType {
public static final String PDS_SECRETSCAN_VARIANT_A = "a";

/* @formatter:off */
/**
* PDS code scan - with variant A.
*/
public static final TestExecutorConfig PDS_V1_CODE_SCAN_A = definePDSScan(
PDS_CODESCAN_VARIANT_A,false,
PDSIntTestProductIdentifier.PDS_INTTEST_CODESCAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import java.util.UUID;
import java.util.concurrent.Callable;

import com.mercedesbenz.sechub.commons.model.JSONConverter;
import com.mercedesbenz.sechub.commons.model.SecHubReportModel;
import com.mercedesbenz.sechub.integrationtest.api.TestAPI;

public class SecHubJobAutoDumper {

private boolean autoDumpPDSjobsOfSecHubJobEnabled;
private UUID sechubJobUUID;
private String sechubReportJson;

public void enablePDSAutoDumpOnErrorsForSecHubJob() {
this.autoDumpPDSjobsOfSecHubJobEnabled = true;
Expand Down Expand Up @@ -42,6 +45,12 @@ public <T> T execute(Callable<T> callable) {
}

private void handleDumpingBeforeExceptionThrow() {
if (sechubReportJson != null) {
System.out.println("##########################################################################################################");
System.out.println("Dump of SecHub report:");
System.out.println("##########################################################################################################");
System.out.println(sechubReportJson);
}
if (autoDumpPDSjobsOfSecHubJobEnabled) {
TestAPI.dumpAllPDSJobOutputsForSecHubJob(sechubJobUUID);
}
Expand All @@ -51,4 +60,11 @@ private void handleDumpingBeforeExceptionThrow() {
public void setSecHubJobUUID(UUID sechubJobUUID) {
this.sechubJobUUID = sechubJobUUID;
}

public void setSecHubReport(SecHubReportModel report) {
if (report == null) {
return;
}
this.sechubReportJson = JSONConverter.get().toJSON(report, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public class Scenario22 extends AbstractGrowingSecHubServerTestScenario implemen
/**
* Project 6 is created on startup, and has {@link #USER_1} +
* {@link IntegrationTestDefaultProfiles#PROFILE_32_PDS_PREPARE_SCAN_CONFIG_SUCCESS
* profile 32 (exit 5 preparation)} assigned
* profile 32 (exit 5 preparation)} and also
* {@link IntegrationTestDefaultProfiles#PROFILE_2_PDS_CODESCAN profile2 (pds
* codescan) assigned
*/
public static final TestProject PROJECT_6 = createTestProject(Scenario22.class, "project6");

Expand All @@ -118,31 +120,32 @@ protected void initializeTestData() {
createUser(USER_2).

createProject(PROJECT_1, USER_1).
addProjectIdsToDefaultExecutionProfile(PROFILE_28_PDS_PREPARE_MOCKED_SUCCESS,PROJECT_1).
addProjectIdsToDefaultExecutionProfile(PROFILE_28_PDS_PREPARE_MOCKED_SUCCESS, PROJECT_1).
assignUserToProject(PROJECT_1,USER_1).

createProject(PROJECT_2, USER_1).
addProjectIdsToDefaultExecutionProfile(PROFILE_28_PDS_PREPARE_MOCKED_SUCCESS,PROJECT_2).
addProjectIdsToDefaultExecutionProfile(PROFILE_1,PROJECT_2).
addProjectIdsToDefaultExecutionProfile(PROFILE_28_PDS_PREPARE_MOCKED_SUCCESS, PROJECT_2).
addProjectIdsToDefaultExecutionProfile(PROFILE_1, PROJECT_2).
assignUserToProject(PROJECT_2, USER_1).

createProject(PROJECT_3, USER_1).
addProjectIdsToDefaultExecutionProfile(PROFILE_29_PDS_PREPARE_FAILING,PROJECT_3).
addProjectIdsToDefaultExecutionProfile(PROFILE_1,PROJECT_3).
addProjectIdsToDefaultExecutionProfile(PROFILE_29_PDS_PREPARE_FAILING, PROJECT_3).
addProjectIdsToDefaultExecutionProfile(PROFILE_1, PROJECT_3).
assignUserToProject(PROJECT_3, USER_1).

createProject(PROJECT_4, USER_1).
addProjectIdsToDefaultExecutionProfile(PROFILE_30_PDS_PREPARE_EXIT_5,PROJECT_4).
addProjectIdsToDefaultExecutionProfile(PROFILE_1,PROJECT_4).
addProjectIdsToDefaultExecutionProfile(PROFILE_30_PDS_PREPARE_EXIT_5, PROJECT_4).
addProjectIdsToDefaultExecutionProfile(PROFILE_1, PROJECT_4).
assignUserToProject(PROJECT_4, USER_1).

createProject(PROJECT_5, USER_1).
addProjectIdsToDefaultExecutionProfile(PROFILE_31_PDS_PREPARE_SCAN_CONFIG_SUCCESS,PROJECT_5).
assignUserToProject(PROJECT_5,USER_1).
addProjectIdsToDefaultExecutionProfile(PROFILE_31_PDS_PREPARE_SCAN_CONFIG_SUCCESS, PROJECT_5).
assignUserToProject(PROJECT_5, USER_1).

createProject(PROJECT_6, USER_2).
addProjectIdsToDefaultExecutionProfile(PROFILE_32_PDS_PREPARE_SCAN_CONFIG_SUCCESS,PROJECT_6).
assignUserToProject(PROJECT_6,USER_2);
addProjectIdsToDefaultExecutionProfile(PROFILE_32_PDS_PREPARE_SCAN_CONFIG_SUCCESS, PROJECT_6).
addProjectIdsToDefaultExecutionProfile(PROFILE_2_PDS_CODESCAN, PROJECT_6).
assignUserToProject(PROJECT_6, USER_2);
;
/* @formatter:on */
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void pds_upload_binaries_extracts_automatically_only_wanted_parts_config_
hasMessages(0).
hasTrafficLight(YELLOW).
hasFindings(4).
hasUnordered(). // test unordered to avoid flaky tests because of file walk trough different data sections - result can change...
assertUnordered(). // test unordered to avoid flaky tests because of file walk trough different data sections - result can change...
finding().
scanType(ScanType.CODE_SCAN).
severity(Severity.INFO).
Expand Down Expand Up @@ -141,7 +141,7 @@ public void pds_upload_sources_extracts_automatically_only_wanted_parts_config_r
hasMessages(0).
hasTrafficLight(YELLOW).
hasFindings(4).
hasUnordered(). // test unordered to avoid flaky tests because of file walk trough different data sections - result can change...
assertUnordered(). // test unordered to avoid flaky tests because of file walk trough different data sections - result can change...
finding().
scanType(ScanType.CODE_SCAN).
severity(Severity.INFO).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void pds_upload_binaries_extracts_automatically_only_wanted_parts_and_han
hasMessages(0).
hasTrafficLight(RED).
hasFindings(4).
hasUnordered(). // test unordered to avoid flaky tests because of file walk trough different data sections - result can change...
assertUnordered(). // test unordered to avoid flaky tests because of file walk trough different data sections - result can change...
finding().
scanType(ScanType.CODE_SCAN).
severity(Severity.INFO).
Expand Down Expand Up @@ -154,7 +154,7 @@ public void pds_upload_sources_extracts_automatically_only_wanted_parts_and_hand
hasMessages(0).
hasTrafficLight(RED).
hasFindings(4).
hasUnordered(). // test unordered to avoid flaky tests because of file walk trough different data sections - result can change...
assertUnordered(). // test unordered to avoid flaky tests because of file walk trough different data sections - result can change...
finding().
scanType(ScanType.CODE_SCAN).
severity(Severity.INFO).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void project5_start_PDS_prepare_job_from_remote_code_scan_configuration_a
String remoteLocation = remote.get().getLocation();
assertEquals("remote_example_location", remoteLocation);
String type = remote.get().getType();
assertEquals("none", type);
assertEquals("integrationtest", type);

Optional<SecHubRemoteCredentialConfiguration> credentials = remote.get().getCredentials();
assertTrue(credentials.isPresent());
Expand All @@ -284,7 +284,7 @@ public void project5_start_PDS_prepare_job_from_remote_code_scan_configuration_a
/* @formatter:on */
}

@Test
// @Test
public void project6_start_pds_prepare_with_pds_wrapper_application() {
/* @formatter:off */

Expand All @@ -294,24 +294,34 @@ public void project6_start_pds_prepare_with_pds_wrapper_application() {

/* execute */
SecHubClientExecutor.ExecutionResult result = as(USER_2).withSecHubClient().startSynchronScanFor(project, location);
UUID jobUUID = result.getSechubJobUUID();
UUID sechubJobUUID = result.getSechubJobUUID();

/* test */
waitForJobDone(project, jobUUID, 30, true);
waitForJobDone(project, sechubJobUUID, 30, true);

UUID pdsJobUUID = waitForFirstPDSJobOfSecHubJobAndReturnPDSJobUUID(jobUUID);
UUID pdsJobUUID = waitForFirstPDSJobOfSecHubJobAndReturnPDSJobUUID(sechubJobUUID);
Map<String, String> variables = fetchPDSVariableTestOutputMap(pdsJobUUID);
assertEquals("e", variables.get("PDS_TEST_KEY_VARIANTNAME")); // sanity check -it is really the variant we expect...

/* check if the prepare-wrapper was executed correctly */
String report = as(USER_2).getJobReport(project, jobUUID);

System.out.println(report);
assertReport(report).hasTrafficLight(TrafficLight.GREEN).hasMessage(SecHubMessageType.INFO, "x");
String report = as(USER_2).getJobReport(project, sechubJobUUID);

/* @formatter:off */
assertReport(report).

enablePDSAutoDumpOnErrorsForSecHubJob(sechubJobUUID).
hasMessage(SecHubMessageType.INFO, "Some preperation info message for user in report (always).").// from script
hasMessage(SecHubMessageType.INFO, "Integration test preparation done").//from wrapper inside
hasTrafficLight(TrafficLight.YELLOW).

// TODO: 31.05.24 laura for Albert: check if uploaded SOURCECODE_ZIP is available in shared storage projectID/JobUUID/sourcecode.zip
// upload path is /home/<user>/.sechub/sharedvolume/s22_0001project6/<5a244a6d-3c37-482b-8058-exampleUUID>/sourcecode.zip
// Does not work: File downloadedFile = TestAPI.getFileUploaded(project, jobUUID, SOURCECODE_ZIP);
assertUnordered().
finding().
description("i am a medium error from IntegrationTestPrepareWrapperModule").//from IntegrationTestPrepareWrapperModule
isContained().
finding().
description("i am just an information from IntegrationTestPrepareWrapperModule").//from IntegrationTestPrepareWrapperModule
isContained();

}
/* @formatter:on */

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "remote_example_name",
"remote": {
"location": "remote_example_location",
"type": "none",
"type": "integrationtest",
"credentials": {
"user": {
"name": "remote_example_user",
Expand Down
Loading

0 comments on commit 8029f32

Please sign in to comment.