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 @@ -20,9 +20,6 @@ public abstract class BaseUITest {
protected static final String ITEM_CHECKMARX_AST = "Checkmarx AST";
protected static final String ITEM_CHECKMARX_AST_SCAN = "Checkmarx AST Scan";

protected static final String LABEL_SERVER_URL = "Server Url:";
protected static final String LABEL_TENANT = "Tenant:";
protected static final String LABEL_AST_API_KEY = "AST API Key:";
protected static final String LABEL_SCAN_ID = "Scan Id:";

protected static final String COLUMN_TITLE = "Title";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
Expand All @@ -28,7 +27,7 @@ public class TestUI extends BaseUITest {

private static final String ERROR_SERVER_URL_NOT_SET = "Error: Checkmarx server URL is not set";

private static final String INFO_SUCCESSFUL_CONNECTION = "Connection successfull !";
private static final String INFO_SUCCESSFUL_CONNECTION = "Successfully authenticated to AST server!";

private static final String ASSERT_FILTER_ACTIONS_IN_TOOLBAR = "All filter actions must be in the tool bar";
private static final String ASSERT_GROUP_BY_ACTIONS_IN_TOOLBAR = "All group by actions must be in the tool bar";
Expand All @@ -43,7 +42,7 @@ public class TestUI extends BaseUITest {
private static boolean _cxSettingsDefined = false;

@Test
public void testSuccessfulConnetion() {
public void testSuccessfulConnetion() throws TimeoutException {
testSuccessfulConnection();
}

Expand Down Expand Up @@ -294,8 +293,10 @@ private List<String> expandTreeUntilFirstEngineAndGetCurrentSeverities() {

/**
* Test successful connection
*
* @throws TimeoutException
*/
private void testSuccessfulConnection() {
private void testSuccessfulConnection() throws TimeoutException {
preventWidgetWasNullInCIEnvironment();

if(_cxSettingsDefined) return;
Expand All @@ -306,18 +307,18 @@ private void testSuccessfulConnection() {

_bot.sleep(1000);

_bot.textWithLabel(LABEL_SERVER_URL).setText(Environment.BASE_URL);
_bot.textWithLabel(LABEL_TENANT).setText(Environment.TENANT);
_bot.textWithLabel(LABEL_AST_API_KEY).setText(Environment.API_KEY);
_bot.textWithLabel(PluginConstants.PREFERENCES_SERVER_URL).setText(Environment.BASE_URL);
_bot.textWithLabel(PluginConstants.PREFERENCES_TENANT).setText(Environment.TENANT);
_bot.textWithLabel(PluginConstants.PREFERENCES_API_KEY).setText(Environment.API_KEY);

_bot.button(BTN_APPLY).click();
_bot.button(BTN_TEST_CONNECTION).click();
_bot.waitUntil(Conditions.shellIsActive(SHELL_AUTHENTICATION));

assertEquals(INFO_SUCCESSFUL_CONNECTION, _bot.label(INFO_SUCCESSFUL_CONNECTION).getText());

_bot.button(BTN_OK).click();
//Do waitUntil Method to get text from text(6)
waitForConnectionResponse();

assertEquals(INFO_SUCCESSFUL_CONNECTION, _bot.text(6).getText());

_bot.shell(ITEM_PREFERENCES).setFocus(); // Need to set focus to avoid failing in CI environment
_bot.button(BTN_APPLY_AND_CLOSE).click();

Expand Down Expand Up @@ -372,9 +373,9 @@ private void clearCheckmarxCredentials() {
_bot.shell(ITEM_PREFERENCES).activate();
_bot.tree().select(ITEM_CHECKMARX_AST);

_bot.textWithLabel(LABEL_SERVER_URL).setText("");
_bot.textWithLabel(LABEL_TENANT).setText("");
_bot.textWithLabel(LABEL_AST_API_KEY).setText("");
_bot.textWithLabel(PluginConstants.PREFERENCES_SERVER_URL).setText("");
_bot.textWithLabel(PluginConstants.PREFERENCES_TENANT).setText("");
_bot.textWithLabel(PluginConstants.PREFERENCES_API_KEY).setText("");

_bot.button(BTN_APPLY).click();
_bot.button(BTN_APPLY_AND_CLOSE).click();
Expand Down Expand Up @@ -458,4 +459,27 @@ private static void waitUntilBranchComboIsEnabled() throws TimeoutException {
throw new TimeoutException("Timeout after 5000ms. Branches' combobox must be enabled");
}
}

/**
* Wait while tree node equals to a a specific message. Fails after 10 retries
*
* @param nodeText
* @throws TimeoutException
*/
private static void waitForConnectionResponse() throws TimeoutException {
int retryIdx = 0;

while (!_bot.text(6).getText().equals(INFO_SUCCESSFUL_CONNECTION)) {
if (retryIdx == 10) {
break;
}

_bot.sleep(1000);
retryIdx++;
}

if (retryIdx == 10) {
throw new TimeoutException("Connection validation timeout after 10000ms.");
}
}
}
10 changes: 7 additions & 3 deletions checkmarx-ast-eclipse-plugin/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/slf4j-simple-1.7.5.jar"/>
<classpathentry exported="true" kind="lib" path="lib/slf4j-log4j12-1.7.5.jar"/>
Expand All @@ -9,7 +13,7 @@
<classpathentry exported="true" kind="lib" path="lib/jackson-core-2.12.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jackson-databind-2.12.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-lang3-3.12.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/ast-cli-java-wrapper-1.0.18.jar"/>
<classpathentry kind="src" path="src/"/>
<classpathentry exported="true" kind="lib" path="lib/ast-cli-java-wrapper-1.0.22.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion checkmarx-ast-eclipse-plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Bundle-ClassPath: lib/slf4j-simple-1.7.5.jar,
lib/jackson-core-2.12.4.jar,
lib/jackson-databind-2.12.4.jar,
lib/commons-lang3-3.12.0.jar,
lib/ast-cli-java-wrapper-1.0.18.jar,
lib/ast-cli-java-wrapper-1.0.22.jar,
.
4 changes: 2 additions & 2 deletions checkmarx-ast-eclipse-plugin/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ bin.includes = plugin.xml,\
lib/jackson-core-2.12.4.jar,\
lib/jackson-databind-2.12.4.jar,\
lib/commons-lang3-3.12.0.jar,\
lib/ast-cli-java-wrapper-1.0.18.jar,\
.
.,\
lib/ast-cli-java-wrapper-1.0.22.jar
source.. = src/
Binary file added checkmarx-ast-eclipse-plugin/icons/high_untoggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added checkmarx-ast-eclipse-plugin/icons/info_untoggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added checkmarx-ast-eclipse-plugin/icons/low_untoggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,41 +1,71 @@
package com.checkmarx.eclipse.properties;

import org.eclipse.jface.dialogs.MessageDialog;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

import org.eclipse.jface.preference.StringButtonFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

import com.checkmarx.eclipse.runner.Authenticator;
import com.checkmarx.eclipse.utils.CxLogger;
import com.checkmarx.eclipse.utils.PluginConstants;

public class AuthButtonFieldEditor extends StringButtonFieldEditor {

protected AuthButtonFieldEditor(String name, String labelText,
Composite parent) {
super(name, labelText, parent);
setChangeButtonText("Test Connection");
Consumer<String> consumer;

}
private StringFieldEditor serverUrl;
private StringFieldEditor authUrl;
private StringFieldEditor tenant;
private StringFieldEditor apiKey;
private StringFieldEditor additionalParams;
private CLabel connectionLabel;

@Override
protected String changePressed() {
AuthButtonFieldEditor(String name, String labelText, Composite parent, StringFieldEditor serverUrl,
StringFieldEditor authUrl, StringFieldEditor tenant, StringFieldEditor apiKey,
StringFieldEditor additionalParams, CLabel connectionLabel) {
super(name, labelText, parent);
setChangeButtonText(labelText);
this.serverUrl = serverUrl;
this.authUrl = authUrl;
this.tenant = tenant;
this.apiKey = apiKey;
this.additionalParams = additionalParams;
this.connectionLabel = connectionLabel;
}

String result = Authenticator.INSTANCE.doAuthentication();
if(!result.isEmpty())
{
MessageDialog.openInformation(null, "Authentication", "Connection successfull !");
}
else
{
MessageDialog.openInformation(null, "Authentication", "Please check your credentials!");
@Override
protected String changePressed() {
Comment thread
cx-pedro-lopes marked this conversation as resolved.
connectionLabel.setText(PluginConstants.PREFERENCES_VALIDATING_STATE);

String serverUrl_str = serverUrl.getStringValue();
String authUrl_str = authUrl.getStringValue();
String tenant_str = tenant.getStringValue();
String apiKey_str = apiKey.getStringValue();
String additionalParams_str = additionalParams.getStringValue();

CompletableFuture.supplyAsync(() -> {
try {
return Authenticator.INSTANCE.doAuthentication(serverUrl_str, authUrl_str, tenant_str, apiKey_str,
additionalParams_str);
} catch (Throwable t) {
CxLogger.error(PluginConstants.ERROR_AUTHENTICATING_AST, new Exception(t));
return t.getMessage();
}

return null;
}

public void emptyTextfield() {
setStringValue("");
Preferences.store(Preferences.API_KEY, "");
}


}).thenAccept((result) -> Display.getDefault().syncExec(() -> connectionLabel.setText(result)));

return null;
}

public void emptyTextfield() {
setStringValue("");
Preferences.store("", "");
}

void setValues() {
}

}
Loading