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,192 @@
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 static org.junit.jupiter.api.Assertions.assertTrue;

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 clickSeverityUsesAnalyticsLabels() {
assertEquals("Critical", TelemetryService.analyticsSeverity("critical"));
assertEquals("Critical", TelemetryService.analyticsSeverity("Malicious"));
assertEquals("High", TelemetryService.analyticsSeverity(" HIGH "));
assertEquals("Medium", TelemetryService.analyticsSeverity("Medium"));
assertEquals("Low", TelemetryService.analyticsSeverity("Low"));
assertEquals("Info", TelemetryService.analyticsSeverity("Unknown"));
assertEquals("Info", TelemetryService.analyticsSeverity(null));
assertEquals("", TelemetryService.analyticsSeverity("OK"));
}

@Test
void scanFailureReasonFallsBackToClassName() {
assertEquals("docker not running", TelemetryService.scanFailureReason(new RuntimeException("docker not running")));
assertEquals("IllegalStateException", TelemetryService.scanFailureReason(new IllegalStateException()));
assertEquals("IllegalStateException", TelemetryService.scanFailureReason(new IllegalStateException(" ")));
assertEquals("unknown", TelemetryService.scanFailureReason(null));
}

@Test
void cancelledScansAreNotFailures() {
assertTrue(TelemetryService.isCancellation(new InterruptedException()));
assertTrue(TelemetryService.isCancellation(new RuntimeException("wrapped", new java.io.InterruptedIOException())));
assertFalse(TelemetryService.isCancellation(new RuntimeException("container engine not running")));
assertFalse(TelemetryService.isCancellation(null));
}

@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);
}
Loading
Loading