Skip to content

Commit

Permalink
Bugfix for pds tools cli and added tests #2092
Browse files Browse the repository at this point in the history
  • Loading branch information
de-jcup committed Aug 8, 2023
1 parent a60a42e commit c82a219
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 31 deletions.
Expand Up @@ -20,6 +20,10 @@ public class SystemTestLauncher {

SystemTestAPI systemTestApi;

public SystemTestLauncher() {
systemTestApi = new SystemTestAPI();
}

public SystemTestResult launch(SystemTestCommand systemTestCommand) throws IOException {
SystemTestParametersBuilder builder = SystemTestParameters.builder();

Expand Down
Expand Up @@ -39,6 +39,17 @@ void beforeEach() {
cliToTest.systemTestLauncher = systemTestLauncher;
}

@Test
void a_normal_instanciated_cli_object_has_all_parts_inside() {
/* execute */
cliToTest = new PDSToolsCLI();

/* test */
assertNotNull(cliToTest.consoleHandler);
assertNotNull(cliToTest.exitHandler);
assertNotNull(cliToTest.systemTestLauncher);
}

@Test
void no_argument_fails_with_exit_code_1() throws Exception {

Expand Down
Expand Up @@ -36,6 +36,15 @@ void beforeEach() {
launcherToTest.systemTestApi = systemTestApi;
}

@Test
void new_launcher_has_all_parts_defined() throws Exception {
/* execute */
launcherToTest = new SystemTestLauncher();

/* test */
assertNotNull(launcherToTest.systemTestApi);
}

@Test
void no_config_file_defined_throws_illegal_argument_without_interactions() throws Exception {

Expand Down
Expand Up @@ -22,7 +22,9 @@
import com.mercedesbenz.sechub.test.TestUtil;

/**
* An integration test which needs a running SecHub server
* A local test for developers to check if gosec integration works. Can be
* simply started as a junit test - but also from commandline by using
* pds-tools.
*
* @author Albert Tregnaghi
*
Expand Down Expand Up @@ -59,12 +61,16 @@ void manual_local_gosec_test_can_run_without_errors() throws IOException {
}else {
throw new RuntimeException("this variant is not supported:"+variant);
}
LOG.info("VARIANT: {}", variant);
LOG.info("CONFIG : {}", configFile);

TextFileReader reader = new TextFileReader();
String json = reader.loadTextFile(new File("./src/test/resources/"+configFile));
SystemTestConfiguration config = JSONConverter.get().fromJSON(SystemTestConfiguration.class, json);

TestEnvironmentProvider environmentProvider= createEnvironmentProviderForSecrets() ;
LOG.info("Using variant: {} -> config file: {}", variant, configFile);
LOG.debug("PDS tech user id: {}", environmentProvider.getEnv("TEST_PDS_USERID"));
LOG.debug("PDS tech user apitoken: {}", environmentProvider.getEnv("TEST_PDS_APITOKEN"));

/* execute */
SystemTestResult result = systemTestApi.runSystemTests(
Expand All @@ -89,15 +95,21 @@ private TestEnvironmentProvider createEnvironmentProviderForSecrets() {
String testPDSTechUserName = TestUtil.getSystemProperty("pds.techuser.username", "techuser");
String testPDSTechUserPwd = TestUtil.getSystemProperty("pds.techuser.apitoken", "pds-apitoken");

String testIntTestServerAdminUser = TestUtil.getSystemProperty("pds.inttestadmin.userid", "int-test_superadmin");
String testIntTestServerAdminPwd = TestUtil.getSystemProperty("pds.inttestadmin.apitoken", "int-test_superadmin-pwd");

TestEnvironmentProvider environmentProvider = new TestEnvironmentProvider();
environmentProvider.setEnv("ADMIN_USERID", testSecHubAdminUser);
environmentProvider.setEnv("ADMIN_APITOKEN", testSecHubAdminPwd);
environmentProvider.setEnv("TEST_ADMIN_USERID", testSecHubAdminUser);
environmentProvider.setEnv("TEST_ADMIN_APITOKEN", testSecHubAdminPwd);

environmentProvider.setEnv("TEST_INTTEST_ADMIN_USERID", testIntTestServerAdminUser);
environmentProvider.setEnv("TEST_INTTEST_ADMIN_APITOKEN", testIntTestServerAdminPwd);

environmentProvider.setEnv("PDS_USERID", testPDSTechUserName);
environmentProvider.setEnv("PDS_APITOKEN", testPDSTechUserPwd);
environmentProvider.setEnv("TEST_PDS_USERID", testPDSTechUserName);
environmentProvider.setEnv("TEST_PDS_APITOKEN", testPDSTechUserPwd);

environmentProvider.setEnv("PDS_SERVER", "https://localhost:8444");
environmentProvider.setEnv("SECHUB_SERVER", "https://localhost:8443");
environmentProvider.setEnv("TEST_PDS_SERVER", "https://pds-gosec:8444");
environmentProvider.setEnv("TEST_SECHUB_SERVER", "https://localhost:8443");
return environmentProvider;
}

Expand Down
Expand Up @@ -2,31 +2,33 @@
"setup" : {
"local" : {
"secHub" : {
// we do not define a start script part here, so we can use an integration test
// server at this point - means easier to debug
"admin" : {
"userId" : "${secretEnv.ADMIN_USERID}",
"apiToken" : "${secretEnv.ADMIN_APITOKEN}"
"userId" : "${secretEnv.TEST_INTTEST_ADMIN_USERID}",
"apiToken" : "${secretEnv.TEST_INTTEST_ADMIN_APITOKEN}"
},
"configure" : {
"executors" : [ {
"pdsProductId" : "PDS_GOSEC",
"name" : "system-test-codescan-gosec"
"name" : "system-test-codescan-gosec",
"parameters" : {
"pds.mocking.disabled" : "true",
"pds.config.use.sechub.storage" : "false"
}
} ]
},
"stop" : [ {
"script" : {
"path" : "./01-stop-single-docker-compose.sh"
}
} ]
}
},
"pdsSolutions" : [ {
"name" : "gosec",
"url" : "${env.PDS_SERVER}",
"url" : "${env.TEST_PDS_SERVER}",

// we set this, because the PDS solution is not reachable from localhost
// (port not forwarded)
"waitForAvailable" : false,

"start" : [ {
"script" : {
"path" : "./50-start-multiple-docker-compose.sh",
"arguments" : [ "1" ]
"path" : "./01-start-single-docker-compose.sh",
"arguments" : [ "alpine" ]
}
} ],
"stop" : [ {
Expand All @@ -35,8 +37,8 @@
}
} ],
"techUser" : {
"userId" : "${secretEnv.PDS_USERID}",
"apiToken" : "${secretEnv.PDS_APITOKEN}"
"userId" : "${secretEnv.TEST_PDS_USERID}",
"apiToken" : "${secretEnv.TEST_PDS_APITOKEN}"
}
} ]
}
Expand Down
18 changes: 11 additions & 7 deletions sechub-systemtest/src/test/resources/systemtest_gosec_example.json
Expand Up @@ -3,8 +3,8 @@
"local" : {
"secHub" : {
"admin" : {
"userId" : "${secretEnv.ADMIN_USERID}",
"apiToken" : "${secretEnv.ADMIN_APITOKEN}"
"userId" : "${secretEnv.TEST_ADMIN_USERID}",
"apiToken" : "${secretEnv.TEST_ADMIN_APITOKEN}"
},
"start" : [ {
"script" : {
Expand All @@ -26,11 +26,15 @@
},
"pdsSolutions" : [ {
"name" : "gosec",
"url" : "${env.PDS_SERVER}",
"url" : "${env.TEST_PDS_SERVER}",

// we set this, because the PDS solution is not reachable from localhost
// (port not forwarded)
"waitForAvailable" : false,

"start" : [ {
"script" : {
"path" : "./50-start-multiple-docker-compose.sh",
"arguments" : [ "1" ]
"path" : "./05-start-single-sechub-network-docker-compose.sh"
}
} ],
"stop" : [ {
Expand All @@ -39,8 +43,8 @@
}
} ],
"techUser" : {
"userId" : "${secretEnv.PDS_USERID}",
"apiToken" : "${secretEnv.PDS_APITOKEN}"
"userId" : "${secretEnv.TEST_PDS_USERID}",
"apiToken" : "${secretEnv.TEST_PDS_APITOKEN}"
}
} ]
}
Expand Down

0 comments on commit c82a219

Please sign in to comment.