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
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.33
dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package checkmarx.ast.eclipse.plugin.tests.unit.devassist.telemetry;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.Arrays;
import java.util.Collections;

import org.junit.jupiter.api.Test;

import com.checkmarx.ast.telemetry.TelemetryEvent;
import com.checkmarx.eclipse.devassist.telemetry.TelemetryService;

/**
* Verifies the telemetry events built for login, scan and remediation (AST-184122).
*/
class TelemetryServiceTest {

private static void assertCommonFields(TelemetryEvent event) {
assertEquals("Eclipse", event.getAgent());
assertEquals("IDE", event.getPluginType());
assertFalse(event.getCxPluginVersion() == null || event.getCxPluginVersion().isEmpty());
assertEquals("DevAssist", event.getEventAttributes().get("pluginName"));
}

@Test
void loginSuccess() {
TelemetryEvent event = TelemetryService.buildLoginEvent(true, null);

assertCommonFields(event);
assertEquals("authentication", event.getEventType());
assertEquals("authentication", event.getSubType());
assertEquals("success", event.getStatus());
assertEquals("Authentication successful.", event.getStatusResult());
assertEquals("APIKey", event.getEventAttributes().get("authMethod"));
assertFalse(event.getEventAttributes().get("loginTimestamp").isEmpty());
java.time.Instant.parse(event.getEventAttributes().get("loginTimestamp"));
}

@Test
void installEventCarriesIdAndTimestamp() {
TelemetryEvent event = TelemetryService.buildInstallEvent("eclipse-1234", "2026-11-19T08:00:00Z");

assertCommonFields(event);
assertEquals("install", event.getEventType());
assertEquals("installation", event.getSubType());
assertEquals("success", event.getStatus());
assertEquals("Plugin installed successfully.", event.getStatusResult());
assertEquals("eclipse-1234", event.getEventAttributes().get("installationId"));
assertEquals("2026-11-19T08:00:00Z", event.getEventAttributes().get("installationTimestamp"));
}

@Test
void loginFailureCarriesSanitizedReason() {
TelemetryEvent event = TelemetryService.buildLoginEvent(false, "bad key apikey=abc123 expired");

assertEquals("failure", event.getStatus());
assertEquals("Authentication failed. Reason: bad key apikey=*** expired, Error Code: N/A",
event.getStatusResult());
}

@Test
void scanEventCountsSeveritiesAndReportsHighest() {
TelemetryEvent event = TelemetryService.buildScanEvent("Oss",
Arrays.asList("High", "High", "Medium", "Malicious", "Unknown", "OK", null));

assertCommonFields(event);
assertEquals("Scan", event.getEventType());
assertEquals("scantriggerd", event.getSubType());
assertEquals("success", event.getStatus());
assertEquals("Oss", event.getEngine());
assertEquals("Critical", event.getProblemSeverity());
assertEquals(Integer.valueOf(6), event.getTotalCount());
assertEquals("Critical=1, High=2, Medium=1, Low=0, Info=2", event.getStatusResult());
assertEquals("v2", event.getApiVersion());
assertEquals("v2", event.getEventAttributes().get("apiVersion"));
}

@Test
void scanWithoutFindingsIsStillReported() {
TelemetryEvent event = TelemetryService.buildScanEvent("Secrets", Collections.emptyList());

assertEquals("success", event.getStatus());
assertEquals("", event.getProblemSeverity());
assertEquals(Integer.valueOf(0), event.getTotalCount());
assertEquals("Critical=0, High=0, Medium=0, Low=0, Info=0", event.getStatusResult());
}

@Test
void scanFailure() {
TelemetryEvent event = TelemetryService.buildScanFailureEvent("IaC", "boom");

assertEquals("Scan", event.getEventType());
assertEquals("failure", event.getStatus());
assertEquals("IaC", event.getEngine());
assertEquals("Scan failed. Reason: boom, Error Code: N/A", event.getStatusResult());
}

@Test
void remediationEventHasModeAndVulnerabilityId() {
TelemetryEvent event = TelemetryService.buildClickEvent("Click", "fixWithAIChat", "Oss", "High",
"CVE-2024-1", "success", "");

assertCommonFields(event);
assertEquals("Click", event.getEventType());
assertEquals("fixWithAIChat", event.getSubType());
assertEquals("Copilot", event.getAiProvider());
assertEquals("Oss", event.getEngine());
assertEquals("High", event.getProblemSeverity());
assertEquals("DevAssist", event.getEventAttributes().get("remediationMode"));
assertEquals("CVE-2024-1", event.getEventAttributes().get("vulnerabilityId"));
assertEquals("Remediation completed successfully.", event.getStatusResult());
}

@Test
void clickEventAndScanEventCarryRepoUrl() {
assertEquals("https://github.com/org/repo", TelemetryService.buildClickEvent("click", "fixWithAIChat", "Oss",
"High", "x@1", "success", "", "https://github.com/org/repo").getRepoUrl());
assertEquals("https://github.com/org/repo", TelemetryService.buildScanEvent("Oss", Collections.emptyList(),
"https://github.com/org/repo").getRepoUrl());
}

@Test
void gitRemoteResolverReadsOriginAndStripsCredentials(@org.junit.jupiter.api.io.TempDir java.nio.file.Path dir)
throws java.io.IOException {
java.nio.file.Path git = java.nio.file.Files.createDirectories(dir.resolve(".git"));
java.nio.file.Files.write(git.resolve("config"), Arrays.asList("[core]", " bare = false",
"[remote \"upstream\"]", " url = https://github.com/other/repo.git",
"[remote \"origin\"]", " url = https://user:tok@github.com/org/repo.git"));
java.nio.file.Path file = java.nio.file.Files.createDirectories(dir.resolve("src")).resolve("a.java");

assertEquals("https://github.com/org/repo.git",
com.checkmarx.eclipse.devassist.telemetry.GitRemoteResolver.resolve(file.toString()));
assertNull(com.checkmarx.eclipse.devassist.telemetry.GitRemoteResolver.resolve(null));
}

@Test
void remediationEventOmitsBlankVulnerabilityId() {
TelemetryEvent event = TelemetryService.buildClickEvent("Click", "fixWithAIChat", "Secrets", "High", " ",
"failure", "Remediation failed. Reason: x, Error Code: N/A");

assertFalse(event.getEventAttributes().containsKey("vulnerabilityId"));
assertEquals("failure", event.getStatus());
}

@Test
void otherClickEventsHaveNoRemediationAttributes() {
TelemetryEvent event = TelemetryService.buildClickEvent("Click", "viewDetails", "Oss", "Low", "CVE-1",
"success", "");

assertFalse(event.getEventAttributes().containsKey("remediationMode"));
assertFalse(event.getEventAttributes().containsKey("vulnerabilityId"));
assertNull(event.getApiVersion());
}

@Test
void sanitizeRemovesCredentialsAndTruncates() {
assertEquals("https://***@host/x", TelemetryService.sanitize("https://user:pw@host/x"));
assertEquals("Bearer ***", TelemetryService.sanitize("Bearer abc.def"));
assertEquals(256, TelemetryService.sanitize("a ".repeat(400)).length());
}
}
2 changes: 1 addition & 1 deletion checkmarx-ast-eclipse-plugin/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="../common-lib/lib/ast-cli-java-wrapper-2.4.33.jar"/>
<classpathentry exported="true" kind="lib" path="../common-lib/lib/ast-cli-java-wrapper-dev.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/commons-lang3-3.18.0.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/jackson-core-2.22.3.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/jackson-databind-2.22.3.jar"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.checkmarx.eclipse.devassist.backend.listener.CheckmarxEditorListener;
import com.checkmarx.eclipse.devassist.backend.GlobalScannerController;
import com.checkmarx.eclipse.devassist.backend.listener.ProjectLifecycleListener;
import com.checkmarx.eclipse.devassist.telemetry.TelemetryService;

public class PluginStartup implements IStartup {

Expand Down Expand Up @@ -48,6 +49,10 @@ public void earlyStartup() {
realtimeScanListener = new CheckmarxEditorListener();
window.getPartService().addPartListener(realtimeScanListener);

// Report login for an already logged-in user (once per launch), queued ahead of
// every scan event the scanners below will produce.
TelemetryService.logStartupLoginEvent();

// Initialize backend scanner infrastructure
initializeBackendScanners();
}
Expand Down
2 changes: 1 addition & 1 deletion common-lib/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/ast-cli-java-wrapper-2.4.33.jar"/>
<classpathentry exported="true" kind="lib" path="lib/ast-cli-java-wrapper-dev.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.18.0.jar"/>
<classpathentry kind="lib" path="lib/jackson-annotations-2.21.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-2.0.17.jar"/>
Expand Down
3 changes: 2 additions & 1 deletion common-lib/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bundle-SymbolicName: com.checkmarx.eclipse.common
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Checkmarx
Bundle-ClassPath: .,
lib/ast-cli-java-wrapper-2.4.33.jar,
lib/ast-cli-java-wrapper-dev.jar,
lib/jackson-core-2.22.3.jar,
lib/jackson-databind-2.22.3.jar,
lib/jackson-annotations-2.21.jar,
Expand Down Expand Up @@ -39,6 +39,7 @@ Export-Package: com.checkmarx.ast.asca,
com.checkmarx.ast.results.result,
com.checkmarx.ast.scan,
com.checkmarx.ast.secretsrealtime,
com.checkmarx.ast.telemetry,
com.checkmarx.ast.tenant,
com.checkmarx.ast.utils,
com.checkmarx.ast.wrapper,
Expand Down
2 changes: 1 addition & 1 deletion common-lib/build.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
output.. = bin/
bin.includes = META-INF/,\
lib/ast-cli-java-wrapper-2.4.33.jar,\
lib/ast-cli-java-wrapper-dev.jar,\
lib/jackson-core-2.22.3.jar,\
lib/jackson-databind-2.22.3.jar,\
lib/jackson-annotations-2.21.jar,\
Expand Down
3 changes: 0 additions & 3 deletions common-lib/lib/ast-cli-java-wrapper-2.4.33.jar

This file was deleted.

3 changes: 3 additions & 0 deletions common-lib/lib/ast-cli-java-wrapper-dev.jar
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.checkmarx.eclipse.common.listener;

/**
* Handler for login telemetry events (AST-184122).
*
* Allows devassist-lib to report an authentication result from PreferencesPage
* without creating a reverse dependency from common-lib to devassist-lib.
*/
public interface ILoginTelemetryHandler {

/**
* Called with the result of an API key authentication attempt.
*
* @param success true if authentication succeeded
* @param failureReason reason for a failed attempt (may be null on success)
*/
void onLogin(boolean success, String failureReason);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.eclipse.ui.preferences.ScopedPreferenceStore;

import com.checkmarx.eclipse.common.listener.IAuthenticationSuccessHandler;
import com.checkmarx.eclipse.common.listener.ILoginTelemetryHandler;
import com.checkmarx.eclipse.common.listener.IMcpInstallHandler;
import com.checkmarx.eclipse.common.listener.IMcpUninstallHandler;
import com.checkmarx.eclipse.common.listener.ISettingsChangeNotifier;
Expand Down Expand Up @@ -47,6 +48,9 @@ public class Preferences {
// Handler for post-authentication UI setup (registered by devassist-lib)
private static IAuthenticationSuccessHandler authSuccessHandler;

// Handler that reports login telemetry (registered by devassist-lib)
private static ILoginTelemetryHandler loginTelemetryHandler;

// Notifiers for settings changes (registered by main plugin and devassist-lib).
// A List is used because both bundles register their own notifier for different
// purposes (UI panel refresh vs. scanner-state sync); a single-slot field would
Expand Down Expand Up @@ -104,6 +108,14 @@ public static void setAuthenticationSuccessHandler(IAuthenticationSuccessHandler
authSuccessHandler = handler;
}

public static void setLoginTelemetryHandler(ILoginTelemetryHandler handler) {
loginTelemetryHandler = handler;
}

public static ILoginTelemetryHandler getLoginTelemetryHandler() {
return loginTelemetryHandler;
}

public static IAuthenticationSuccessHandler getAuthenticationSuccessHandler() {
return authSuccessHandler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.checkmarx.eclipse.common.utils.PluginConstants;
import com.checkmarx.eclipse.common.listener.IAuthenticationSuccessHandler;
import com.checkmarx.eclipse.common.listener.ILoginTelemetryHandler;
import com.checkmarx.eclipse.common.listener.IMcpUninstallCallback;
import com.checkmarx.eclipse.common.listener.IMcpUninstallHandler;
import com.checkmarx.eclipse.common.listener.ISettingsChangeNotifier;
Expand Down Expand Up @@ -315,6 +316,10 @@ public void widgetSelected(SelectionEvent e) {
// anything else gated on login) actually sees it.
Preferences.STORE.setValue(Preferences.API_KEY, apiKey_str);
Preferences.STORE.setValue(Preferences.ADDITIONAL_OPTIONS, additionalParams_str);
// Report the login BEFORE credentialsValidated flips: that change starts a
// workspace scan immediately, and the login event must reach the CLI first
// (it creates the session id the scan events reuse).
reportLoginTelemetry(true, null);
Preferences.setCredentialsValidated(true);
// connectionButton stays disabled - it's only re-enabled on logout, or
// below if this attempt actually failed.
Expand All @@ -335,6 +340,7 @@ public void widgetSelected(SelectionEvent e) {
// Authentication failed - the flow ends here with no welcome dialog,
// so show the failure message right away, restore Logout, and let the
// user retry the connect.
reportLoginTelemetry(false, result);
if (!connectionButton.isDisposed()) {
connectionButton.setEnabled(true);
}
Expand Down Expand Up @@ -429,6 +435,21 @@ public void widgetSelected(SelectionEvent e) {
});
}

/**
* Reports the result of a Connect attempt to the login telemetry handler
* (registered by devassist-lib). Never throws - telemetry must not affect login.
*/
private static void reportLoginTelemetry(boolean success, String failureReason) {
try {
ILoginTelemetryHandler handler = Preferences.getLoginTelemetryHandler();
if (handler != null) {
handler.onLogin(success, failureReason);
}
} catch (Exception e) {
CxLogger.warning("Telemetry: login event could not be reported - " + e.getMessage());
}
}

private static String mapAuthResult(String result) {
if (result != null && result.contains(PluginConstants.AUTH_SUCCESS_PATTERN)) {
return PluginConstants.AUTH_SUCCESS_DISPLAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static String getAgentInfo() {
* build (Tycho replaces the "qualifier" placeholder in MANIFEST.MF with the
* real build qualifier), falling back when running outside an OSGi framework.
*/
private static String getPluginVersion() {
public static String getPluginVersion() {
try {
Bundle bundle = FrameworkUtil.getBundle(CxWrapperFactory.class);
return bundle != null ? bundle.getVersion().toString() : "0.0.0";
Expand Down
2 changes: 1 addition & 1 deletion devassist-lib/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="../common-lib/lib/ast-cli-java-wrapper-2.4.33.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/ast-cli-java-wrapper-dev.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/commons-lang3-3.18.0.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/jackson-core-2.22.3.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/jackson-databind-2.22.3.jar"/>
Expand Down
1 change: 1 addition & 0 deletions devassist-lib/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ Import-Package: com.fasterxml.jackson.annotation,
Export-Package: com.checkmarx.eclipse.devassist.backend,
com.checkmarx.eclipse.devassist.backend.listener,
com.checkmarx.eclipse.devassist.ignore,
com.checkmarx.eclipse.devassist.telemetry,
com.checkmarx.eclipse.devassist.ui.findings.ignore
Loading
Loading