Skip to content
Open
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
6 changes: 5 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion ast-cli-java-wrapper.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.24
2.4.27
1 change: 1 addition & 0 deletions checkmarx-ast-eclipse-plugin-tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand Down
3 changes: 2 additions & 1 deletion checkmarx-ast-eclipse-plugin-tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Require-Bundle:
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ClassPath: .,lib/mockito-core-5.14.2.jar,lib/powermock-core-*.jar, lib/byte-buddy-1.17.8.jar, lib/byte-buddy-agent-1.17.8.jar
Automatic-Module-Name: com.checkmarx.ast.eclipse.tests
Import-Package: com.checkmarx.eclipse.common.runner
Import-Package: com.checkmarx.eclipse.common.runner,
org.slf4j;version="[2.0.0,3.0.0)"
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package checkmarx.ast.eclipse.plugin.tests.integration;


import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.checkmarx.eclipse.common.runner.Authenticator;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;

import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;

import com.checkmarx.eclipse.common.runner.Authenticator;

public class AuthenticatorIntegrationTest extends BaseIntegrationTest {

private static final Logger logger = LoggerFactory.getLogger(AuthenticatorIntegrationTest.class);

@Mock

private Authenticator authenticator;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void testAreCredentialsDefinedTrue() {

try (MockedStatic<Preferences> prefs = Mockito.mockStatic(Preferences.class)) {

prefs.when(Preferences::getApiKey).thenReturn("apikey");
prefs.when(Preferences::isAuthenticated).thenReturn(true);

boolean result = PluginUtils.areCredentialsDefined();

Expand All @@ -180,7 +180,7 @@ void testAreCredentialsDefinedFalse() {

try (MockedStatic<Preferences> prefs = Mockito.mockStatic(Preferences.class)) {

prefs.when(Preferences::getApiKey).thenReturn("");
prefs.when(Preferences::isAuthenticated).thenReturn(false);

boolean result = PluginUtils.areCredentialsDefined();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package checkmarx.ast.eclipse.plugin.tests.unit.wrapper;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.util.concurrent.atomic.AtomicReference;

import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;

import com.checkmarx.ast.wrapper.CxConfig;
import com.checkmarx.ast.wrapper.CxWrapper;
import com.checkmarx.eclipse.common.preferences.Preferences;
import com.checkmarx.eclipse.common.wrapper.CxWrapperFactory;

class CxWrapperFactoryTest {

@Test
void testBuildWithNoArgs_usesSavedPreferencesAndStampsAgentName() throws Exception {
AtomicReference<CxConfig> capturedConfig = new AtomicReference<>();

try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> capturedConfig.set((CxConfig) context.arguments().get(0)));
var mockedPreferences = mockStatic(Preferences.class)) {

mockedPreferences.when(Preferences::getApiKey).thenReturn("saved-api-key");
mockedPreferences.when(Preferences::getAdditionalOptions).thenReturn("--saved-param");

CxWrapperFactory.build();

assertEquals(1, mocked.constructed().size());
CxConfig config = capturedConfig.get();
assertNotNull(config);
assertEquals("saved-api-key", config.getApiKey());
assertEquals("--saved-param", String.join(" ", config.getAdditionalParameters()));
assertNotNull(config.getAgentName());
assertTrue(config.getAgentName().startsWith("Eclipse_"),
"Agent name should be stamped as Eclipse_<version>, was: " + config.getAgentName());
}
}

@Test
void testBuildWithExplicitCredentials_doesNotUseSavedPreferences() throws Exception {
AtomicReference<CxConfig> capturedConfig = new AtomicReference<>();

try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> capturedConfig.set((CxConfig) context.arguments().get(0)));
var mockedPreferences = mockStatic(Preferences.class)) {

CxWrapperFactory.build("typed-api-key", "--typed-param");

assertEquals(1, mocked.constructed().size());
CxConfig config = capturedConfig.get();
assertNotNull(config);
assertEquals("typed-api-key", config.getApiKey());
assertEquals("--typed-param", String.join(" ", config.getAdditionalParameters()));
assertTrue(config.getAgentName().startsWith("Eclipse_"));

mockedPreferences.verifyNoInteractions();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package checkmarx.ast.eclipse.plugin.tests.unit.wrapper;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;

import com.checkmarx.ast.project.Project;
import com.checkmarx.ast.wrapper.CxWrapper;
import com.checkmarx.eclipse.common.wrapper.WrapperProvider;

class WrapperProviderTest {

private final WrapperProvider wrapperProvider = new WrapperProvider();

@Test
void testIsAiMcpServerEnabled_forwardsCredentialsAndReturnsWrapperResult() throws Exception {
try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> when(mock.aiMcpServerEnabled()).thenReturn(true))) {

boolean result = wrapperProvider.isAiMcpServerEnabled("api-key", "--param");

assertTrue(result);
assertEquals(1, mocked.constructed().size());
}
}

@Test
void testIsAiMcpServerEnabled_propagatesFalseWhenDisabled() throws Exception {
try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> when(mock.aiMcpServerEnabled()).thenReturn(false))) {

boolean result = wrapperProvider.isAiMcpServerEnabled("api-key", "--param");

assertFalse(result);
}
}

@Test
void testGetProjects_forwardsLimitAndReturnsWrapperResult() throws Exception {
Project mockProject = mock(Project.class);
try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> when(mock.projectList("limit=10")).thenReturn(List.of(mockProject)))) {

List<Project> projects = wrapperProvider.getProjects("limit=10");

assertEquals(1, projects.size());
assertSame(mockProject, projects.get(0));
}
}

@Test
void testTriageGetStates_propagatesExceptionFromWrapper() throws Exception {
try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> when(mock.triageGetStates(false)).thenThrow(new RuntimeException("boom")))) {

assertThrows(RuntimeException.class, () -> wrapperProvider.triageGetStates(false));
}
}
}
3 changes: 2 additions & 1 deletion checkmarx-ast-eclipse-plugin/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand All @@ -12,7 +13,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="../common-lib/lib/ast-cli-java-wrapper-2.4.24.jar"/>
<classpathentry exported="true" kind="lib" path="../common-lib/lib/ast-cli-java-wrapper-2.4.27.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/commons-lang3-3.18.0.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/jackson-core-2.21.4.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/jackson-databind-2.21.5.jar"/>
Expand Down
2 changes: 0 additions & 2 deletions checkmarx-ast-eclipse-plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ Import-Package: org.eclipse.core.resources,
Bundle-ActivationPolicy: lazy
Bundle-Activator: com.checkmarx.eclipse.Activator
Export-Package: com.checkmarx.eclipse.enums,
com.checkmarx.eclipse.properties,
com.checkmarx.eclipse.utils
Bundle-ClassPath: .,
lib/org.eclipse.mylyn.commons.ui_4.9.0.v20251121-0615.jar,
lib/org-eclipse-mylyn-commons-core.jar

2 changes: 1 addition & 1 deletion checkmarx-ast-eclipse-plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<page
class="com.checkmarx.eclipse.common.preferences.CheckmarxPreferencePage"
id="com.checkmarx.eclipse.devassist.prefs.checkmarxpreferencepage"
name="Checkmarx Scanner Configuration"
name="Checkmarx One Assist"
category="com.checkmarx.eclipse.properties.preferencespage">
</page>
</extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.PlatformUI;
import org.apache.commons.lang3.StringUtils;
import com.checkmarx.ast.results.result.Node;
import com.checkmarx.ast.results.result.Result;
import com.checkmarx.eclipse.enums.ActionName;
Expand Down Expand Up @@ -155,12 +154,12 @@ public static IEventBroker getEventBroker() {
}

/**
* Check if checkmarx credentials are defined in the Preferences
*
* Check if the user is currently authenticated to Checkmarx One.
*
* @return
*/
public static boolean areCredentialsDefined() {
return StringUtils.isNotBlank(Preferences.getApiKey());
return Preferences.isAuthenticated();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2898,17 +2898,18 @@ public void handleEvent(org.osgi.service.event.Event arg0) {
return;
}
String currentApiKey = Preferences.STORE.getString(Preferences.API_KEY);
boolean isAuthenticated = Preferences.isAuthenticated();

// Handle case: credentials just set (plugin panel not yet drawn)
if (!currentApiKey.isEmpty() && !isPluginDraw) {
if (isAuthenticated && !isPluginDraw) {
CxLogger.info("Credentials detected, drawing plugin panel");
drawPluginPanel();
lastApiKey = currentApiKey;
return;
}

// Handle case: credentials just removed (plugin panel is drawn)
if (currentApiKey.isEmpty() && isPluginDraw) {
if (!isAuthenticated && isPluginDraw) {
CxLogger.info("Credentials removed, showing missing credentials panel");
updateStartScanButton(false);
drawMissingCredentialsPanel();
Expand All @@ -2922,15 +2923,15 @@ public void handleEvent(org.osgi.service.event.Event arg0) {
return;
}

// Handle case: no credentials and panel not drawn (initial state)
if (currentApiKey.isEmpty() && !isPluginDraw) {
// Handle case: not authenticated and panel not drawn (initial state)
if (!isAuthenticated && !isPluginDraw) {
// Already showing missing credentials panel, nothing to do
lastApiKey = currentApiKey;
return;
}

// Handle case: API key changed but still authenticated (plugin already drawn)
if (!currentApiKey.isEmpty() && isPluginDraw) {
if (isAuthenticated && isPluginDraw) {
if (lastApiKey != null && lastApiKey.equalsIgnoreCase(currentApiKey)) {
// Same credentials, no reload needed
return;
Expand Down
Loading
Loading