Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import com.checkmarx.eclipse.utils.PluginConstants;
import com.checkmarx.eclipse.views.actions.ActionName;
import com.checkmarx.eclipse.views.actions.ToolBarActions;
import com.checkmarx.eclipse.views.filters.Severity;
Expand All @@ -28,8 +29,6 @@ public class TestUI extends BaseUITest {
private static final String ERROR_INCORRECT_SCAN_ID_FORMAT = "Incorrect scanId format.";
private static final String ERROR_SERVER_URL_NOT_SET = "Error: Checkmarx server URL is not set";

private static final String INFO_SCAN_RETRIVING_RESULTS = "Retrieving the results for the scan id: " + Environment.SCAN_ID + " .";

private static final String INFO_SUCCESSFUL_CONNECTION = "Connection successfull !";

private static final String ASSERT_FILTER_ACTIONS_IN_TOOLBAR = "All filter actions must be in the tool bar";
Expand All @@ -50,7 +49,7 @@ public void testSuccessfulConnetion() {
}

@Test
public void testAddCheckmarxASTPlugin() {
public void testAddCheckmarxASTPlugin() throws TimeoutException {
// Add Checkmarx plugin to the eclipse view
addCheckmarxPlugin();

Expand All @@ -62,28 +61,33 @@ public void testAddCheckmarxASTPlugin() {
}

@Test
public void testMissingSetCheckmarxServerUrl() {
// Clear Checkmarx credentials to expect missing Server Url
clearCheckmarxCredentials();
public void testMissingSetCheckmarxServerUrl() throws TimeoutException {
// Test Connection
testSuccessfulConnection();

// Add Checkmarx plugin to the eclipse perspective view
// Add Checkmarx AST Plugin
addCheckmarxPlugin();

// Clear Checkmarx credentials to expect missing Server Url
clearCheckmarxCredentials();

// Type a valid and existing scan id
typeValidScanID();

sleep();

assertEquals("The tree must contain a single row", _bot.tree().rowCount(), 1);

String firstTreeCell = _bot.tree().cell(0, COLUMN_TITLE);

// The first row must have a message saying that AST is getting results or failing due the missing Server Url
boolean expectedResult = firstTreeCell.equals(INFO_SCAN_RETRIVING_RESULTS) || firstTreeCell.equals(ERROR_SERVER_URL_NOT_SET);
boolean expectedResult = firstTreeCell.equals(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.SCAN_ID)) || firstTreeCell.equals(ERROR_SERVER_URL_NOT_SET);
assertTrue("Plugin should be retrieving results or failed due Server Url not set", expectedResult);

sleep();

// After a sleep the missing Server Url message must be displayed
assertEquals("", ERROR_SERVER_URL_NOT_SET, _bot.tree().cell(0, COLUMN_TITLE));
assertEquals(ERROR_SERVER_URL_NOT_SET, _bot.tree().cell(0, COLUMN_TITLE));

// Close Checkmarx AST Scan view
_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
Expand All @@ -103,7 +107,7 @@ public void testMissingSetCheckmarxServerUrl() {
@Test
public void testEnd2End() throws TimeoutException {
// Set credentials, test connection and add checkmarx plugin
setUpCheckmarxPlugin();
setUpCheckmarxPlugin(false);

String firstNodeName = _bot.tree().cell(0, COLUMN_TITLE);
String secondNodeName = _bot.tree().getTreeItem(firstNodeName).expand().getNode(0).getText();
Expand Down Expand Up @@ -143,7 +147,7 @@ public void testFilterButtonsAndGroupByActionsInToolBar() throws TimeoutExceptio
@Test
public void testFilteringAndGroupingResults() throws TimeoutException {
// Set credentials, test connection and add checkmarx plugin
setUpCheckmarxPlugin();
setUpCheckmarxPlugin(true);

ArrayList<String> currentActiveFilters = new ArrayList<>(Arrays.asList(Severity.HIGH.name(), Severity.MEDIUM.name()));

Expand Down Expand Up @@ -237,7 +241,7 @@ public void testFilteringAndGroupingResults() throws TimeoutException {
*
* @throws TimeoutException
*/
private void setUpCheckmarxPlugin() throws TimeoutException{
private void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws TimeoutException{
// Test Connection
testSuccessfulConnection();

Expand All @@ -248,22 +252,25 @@ private void setUpCheckmarxPlugin() throws TimeoutException{

sleep(1000);

// Test incorrect Scan ID format
_bot.textWithLabel(LABEL_SCAN_ID).setText("invalid-scan-id");
_bot.textWithLabel(LABEL_SCAN_ID).pressShortcut(Keystrokes.LF);
if(!ignoreWrongScanValidation) {
// Test incorrect Scan ID format
_bot.comboBox(2).setText("invalid-scan-id");
_bot.comboBox(2).pressShortcut(Keystrokes.LF);

sleep(1000);

assertEquals("The tree must contain one row with an error message", _bot.tree().rowCount(), 1);
assertEquals("An incorrect scanId format message must be displayed", ERROR_INCORRECT_SCAN_ID_FORMAT, _bot.tree().cell(0, COLUMN_TITLE));
sleep(1000);

assertEquals("The tree must contain one row with an error message", _bot.tree().rowCount(), 1);
assertEquals("An incorrect scanId format message must be displayed", ERROR_INCORRECT_SCAN_ID_FORMAT, _bot.tree().cell(0, COLUMN_TITLE));
}

// type a valid and existing Scan ID
typeValidScanID();

assertEquals("The tree must contain one row", _bot.tree().rowCount(), 1);
assertEquals("The plugin should be retrieving results", INFO_SCAN_RETRIVING_RESULTS, _bot.tree().cell(0, COLUMN_TITLE));
boolean retrievingOrRetrievedResults = _bot.tree().cell(0, COLUMN_TITLE).contains(Environment.SCAN_ID);
assertTrue("The plugin should have or should be retrieving results", retrievingOrRetrievedResults);

waitWhileTreeNodeEqualsTo(INFO_SCAN_RETRIVING_RESULTS);
waitWhileTreeNodeEqualsTo(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.SCAN_ID));

assertTrue("The plugin should retrieve results", _bot.tree().cell(0, COLUMN_TITLE).startsWith(Environment.SCAN_ID));
}
Expand Down Expand Up @@ -299,6 +306,8 @@ private List<String> expandTreeUntilFirstEngineAndGetCurrentSeverities() {
private void testSuccessfulConnection() {
preventWidgetWasNullInCIEnvironment();

if(_cxSettingsDefined) return;

_bot.menu(TAB_WINDOW).menu(ITEM_PREFERENCES).click();
_bot.shell(ITEM_PREFERENCES).activate();
_bot.tree().select(ITEM_CHECKMARX_AST);
Expand All @@ -325,24 +334,32 @@ private void testSuccessfulConnection() {

/**
* Add Checkmarx plugin in the show view perspective
*
* @throws TimeoutException
*/
private void addCheckmarxPlugin() {
private void addCheckmarxPlugin() throws TimeoutException {
preventWidgetWasNullInCIEnvironment();

_bot.menu(TAB_WINDOW).menu(ITEM_SHOW_VIEW).menu(ITEM_OTHER).click();
_bot.shell(ITEM_SHOW_VIEW).activate();
_bot.tree().expandNode(ITEM_CHECKMARX).select(ITEM_CHECKMARX_AST_SCAN);
_bot.button(BTN_OPEN).click();

waitUntilBranchComboIsEnabled();
}

/**
* Type a valid Scan ID to get results
*
* @throws TimeoutException
*/
private void typeValidScanID() {
private void typeValidScanID() throws TimeoutException {
preventWidgetWasNullInCIEnvironment();

_bot.textWithLabel(LABEL_SCAN_ID).setText(Environment.SCAN_ID);
_bot.textWithLabel(LABEL_SCAN_ID).pressShortcut(Keystrokes.LF);
_bot.comboBox(2).setText(Environment.SCAN_ID);
_bot.comboBox(2).pressShortcut(Keystrokes.LF);

waitUntilBranchComboIsEnabled();
}

/**
Expand Down Expand Up @@ -409,4 +426,36 @@ private static void waitWhileTreeNodeEqualsTo(String nodeText) throws TimeoutExc
throw new TimeoutException("Timeout after 5000ms. Scan results should be retrieved");
}
}

/**
* Wait until branch combobox is enabled
*
* @throws TimeoutException
*/
private static void waitUntilBranchComboIsEnabled() throws TimeoutException {
preventWidgetWasNullInCIEnvironment();

boolean emptyScanId = _bot.comboBox(2).getText().isEmpty() || _bot.comboBox(2).getText().equals(PluginConstants.COMBOBOX_SCAND_ID_PLACEHOLDER);

if(emptyScanId) {
return;
}

int retryIdx = 0;

while (!_bot.comboBox(1).isEnabled()) {

if (retryIdx == 10) {
break;
}

_bot.sleep(1000);

retryIdx++;
}

if (retryIdx == 10) {
throw new TimeoutException("Timeout after 5000ms. Branches' combobox must be enabled");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.checkmarx.eclipse.runner;

import java.io.IOException;
import java.net.URISyntaxException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -36,7 +35,7 @@ public class Authenticator {

public String doAuthentication() {

CxConfig config = CxConfig.builder().baseUri(Preferences.getServerUrl()).tenant(Preferences.getTenant()).apiKey(Preferences.getApiKey()).additionalParameters("").build();
CxConfig config = CxConfig.builder().baseUri(Preferences.getServerUrl()).tenant(Preferences.getTenant()).apiKey(Preferences.getApiKey()).additionalParameters(Preferences.getAdditionalOptions()).build();

// config.setBaseUri(Preferences.getServerUrl());
// config.setTenant(Preferences.getTenant());
Expand All @@ -48,7 +47,7 @@ public String doAuthentication() {
try {
wrapper = new CxWrapper(config, log);
String cxValidateOutput = wrapper.authValidate();
// Integer result = cxValidateOutput.getExitCode();

System.out.println("Authentication Status :" + cxValidateOutput);
return cxValidateOutput;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class PluginConstants {
public static final String SAST = "sast";
public static final String SCA_DEPENDENCY = "dependency";
public static final String KICS_INFRASTRUCTURE = "infrastructure";
public static final String MSG_RETRIEVING_RESULTS = "Retrieving the results for the scan id: %s .";
public static final String RETRIEVING_RESULTS_FOR_SCAN = "Retrieving results for scan id: %s";
public static final String COMBOBOX_SCAND_ID_PLACEHOLDER = "Select project or paste a Scan Id here and hit Enter.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static void enableComboViewer(ComboViewer comboviewer, boolean enable) {
*/
public static void setTextForComboViewer(ComboViewer comboViewer, String text) {
comboViewer.getCombo().setText(text);
comboViewer.getCombo().update();
}

/**
Expand Down
Loading