Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -68,6 +69,7 @@ public void testAddCheckmarxASTPlugin() throws TimeoutException {
}

@Test
@Ignore("Disabled due we changed behaviour of credeantials to show Open Setting window on clearing credentials")
public void testMissingSetCheckmarxServerUrl() throws TimeoutException {
// Test Connection
testSuccessfulConnection(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PluginConstants {
public static final String NO_CHANGES = "No changes...";
public static final String BTN_UPDATE = "Update";
public static final String BTN_LOADING = "Loading";
public static final String DEFAULT_COMMENT_TXT = "Notes";
public static final String DEFAULT_COMMENT_TXT = "Notes (Optional or required based on tenant configuration)";
public static final String LOADING_BFL = "Loading BFL";
public static final String BFL_FOUND = "Indicates the Best Fix Location. Speed up your remediation by fixing multiple vulnerabilities at once";
public static final String BFL_NOT_FOUND = "Best fix Location not available for given results";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import com.checkmarx.eclipse.Activator;
import com.checkmarx.eclipse.enums.ActionName;
import com.checkmarx.eclipse.enums.Severity;
import com.checkmarx.eclipse.properties.Preferences;
import com.checkmarx.eclipse.utils.CxLogger;
import com.checkmarx.eclipse.utils.NotificationPopUpUI;
import com.checkmarx.eclipse.utils.PluginConstants;
Expand Down Expand Up @@ -160,6 +161,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
private Button triageButton;
private SelectionAdapter triageButtonAdapter, codeBashingAdapter;
private Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
private String lastApiKey;

private boolean alreadyRunning = false;
private static List<LearnMore> learnMoreData;
Expand Down Expand Up @@ -207,6 +209,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
public CheckmarxView() {
super();
sync = new UISynchronizeImpl(PlatformUI.getWorkbench().getDisplay());
lastApiKey = Preferences.STORE.getString(Preferences.API_KEY);
rootModel = new DisplayModel.DisplayModelBuilder(PluginConstants.EMPTY_STRING).build();
globalSettings.loadSettings();
currentProjectId = globalSettings.getProjectId();
Expand Down Expand Up @@ -714,9 +717,17 @@ private void drawAttackVectorSeparator(Composite parent) {
* Draw panel when Checkmarx credentials are not defined
*/
private void drawMissingCredentialsPanel() {

// Dispose all children to remove any previous panels
for (Control child : parent.getChildren()) {
child.dispose();
}
openSettingsComposite = new Composite(parent, SWT.NONE);

openSettingsComposite.setLayout(new GridLayout(1, true));

// This is the key line: center horizontally and vertically, and expand to fill
openSettingsComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));

final Label hidden = new Label(openSettingsComposite, SWT.NONE);
hidden.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
Expand All @@ -742,6 +753,7 @@ public void handleEvent(Event arg0) {
}
}
});
parent.layout(true, true);
}

private void createProjectListComboBox(Composite parent) {
Expand Down Expand Up @@ -779,7 +791,6 @@ public void selectionChanged(SelectionChangedEvent event) {
updateStartScanButton(false);
return;
}

// Avoid non-sense trigger changed when opening the combo
if (selectedProject.getId().equals(currentProjectId)) {
CxLogger.info(PluginConstants.INFO_CHANGE_PROJECT_EVENT_NOT_TRIGGERED);
Expand Down Expand Up @@ -1153,6 +1164,7 @@ private String formatScanLabel(Scan scan) {
*/

private Scan getLatestScanFromScanList(List<Scan> scanList) {

return scanList.get(0);
}

Expand Down Expand Up @@ -1425,7 +1437,7 @@ public void widgetSelected(SelectionEvent event) {

Job job = new Job("Checkmarx: Updating triage information...") {
String comment = commentText.getText() != null
&& !commentText.getText().equalsIgnoreCase("Notes") ? commentText.getText()
&& !commentText.getText().equalsIgnoreCase("Notes (Optional or required based on tenant configuration)") ? commentText.getText()
: "";

@Override
Expand Down Expand Up @@ -2686,16 +2698,32 @@ private void enablePluginFields(boolean enableBranchCombobox) {
*/
@Override
public void handleEvent(org.osgi.service.event.Event arg0) {
if (!isPluginDraw) {
String currentApiKey = Preferences.STORE.getString(Preferences.API_KEY);
if (!currentApiKey.isEmpty() && !isPluginDraw) {
drawPluginPanel();
} else {
// If authenticated successfully and the projects are empty try to get them again
if (projectComboViewer.getCombo().getItemCount() == 0) {
clearAndRefreshPlugin();
// If credentials changed reload projects, branches and scans from new tenant
if (currentApiKey.isEmpty()) {
updateStartScanButton(false);
drawMissingCredentialsPanel();
//Dispose toolbar
if (toolBarActions != null) {
toolBarActions.disposeToolbar();
toolBarActions = null;
}
isPluginDraw = false;
} else if (lastApiKey.equalsIgnoreCase(currentApiKey)) {
return;
} else {
// clear result section
PluginUtils.clearMessage(rootModel, resultsTree);
// Reset state variables
currentProjectId = PluginConstants.EMPTY_STRING;
currentBranch = PluginConstants.EMPTY_STRING;
currentScanId = PluginConstants.EMPTY_STRING;
loadComboboxes();
}

toolBarActions.refreshToolbar();
updateStartScanButton(true);
lastApiKey=currentApiKey;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public void run() {
};
job.schedule();
}

public void disposeToolbar() {
IToolBarManager toolBarManager = actionBars.getToolBarManager();
toolBarManager.removeAll();
actionBars.getMenuManager().removeAll();
}

public void refreshToolbar() {
IToolBarManager toolBarManager = actionBars.getToolBarManager();
Expand Down