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 @@ -32,6 +32,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -114,13 +115,15 @@ private synchronized void scheduleNext() {
taskBarController.setErrorLog(
currentTask,
ex.getMessage(),
StringUtils.getStackTraceAsString(ex)
StringUtils.getStackTraceAsString(ex),
NestedExceptionUtils.getMostSpecificCause(ex).getMessage()
);
Comment thread
DropSnorz marked this conversation as resolved.
} else {
taskBarController.setErrorLog(
currentTask,
"Task failed",
"No error information available."
"No error information available.",
"No summary available"
);
}
removeCurrentTask();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ private void showErrorDialog(String title, String content) {
).show();
}

public void setErrorLog(AbstractTask task, String title, String content) {
public void setErrorLog(AbstractTask task, String title, String content, String summary) {

this.getTelemetryService().event("/Error/TaskExecution", p -> {
p.put("taskName", task.getName());
p.put("error", title);
p.put("content", content);
p.put("summary", summary);
});
taskProgressBar.getStyleClass().add("progress-bar-error");
logsButton.setVisible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ private void send(String name, Map<String, String> params) {
}
}

private void sanitize(Map<String, String> params) {
void sanitize(Map<String, String> params) {
sanitize(params, MAX_PROPS_LENGTH);
}
void sanitize(Map<String, String> params, int maxLength) {
for (Map.Entry<String, String> entry : params.entrySet()) {
String value = entry.getValue();
if (value.length() > MAX_PROPS_LENGTH) {
value = value.substring(0, MAX_PROPS_LENGTH) + "…";
if (value.length() > maxLength) {
value = value.substring(0, maxLength) + "…";
}

// Redact absolute paths (Unix & Windows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ public class Plugin {
protected String category;
protected String manufacturerName;
protected String identifier;
@Column(length = 512)
protected String path;
@Column(length = 512)
protected String scanDirectoryPath;
protected String bundleId;
protected String version;

// Suggestion: could be renamed to screenshotURI
protected String screenshotUrl;
protected boolean nativeCompatible = false;
protected boolean syncComplete = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

package com.owlplug.plugin.model;

import jakarta.persistence.Column;
import java.util.List;

public class PluginDirectory implements IDirectory {

protected String name;
protected String displayName;
@Column(length = 512)
protected String path;
protected boolean rootDirectory;
protected List<Plugin> pluginList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.owlplug.plugin.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -33,6 +34,7 @@ public class PluginFootprint {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
@Column(length = 512)
protected String path;
protected boolean nativeDiscoveryEnabled = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.owlplug.core.services;

import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class TelemetryServiceTest {

private final TelemetryService telemetryService = new TelemetryService();

@Test
public void testShouldRedactUnixAbsolutePath() {
Map<String, String> params = new HashMap<>();
params.put("key", "Error reading /var/log/app/error.log file");

telemetryService.sanitize(params);

assertEquals("Error reading <path> file", params.get("key"));
}

@Test
public void testShouldRedactWindowsAbsolutePath() {
Map<String, String> params = new HashMap<>();
params.put("key", "Failed at C:\\\\Users\\\\john\\\\secret.txt");

telemetryService.sanitize(params);

assertEquals("Failed at <path>", params.get("key"));
}

@Test
public void testShouldNotRedactClassNamesOrPackages() {
Map<String, String> params = new HashMap<>();
params.put("key", "at com.example.service.MyClass.method(MyClass.java:42)");

telemetryService.sanitize(params);

assertEquals(
"at com.example.service.MyClass.method(MyClass.java:42)",
params.get("key")
);
}

@Test
public void testShouldTruncateLongValuesAndAppendEllipsis() {
Map<String, String> params = new HashMap<>();
params.put("key", "abcdefghijklmnopqrstuvwxyz");

telemetryService.sanitize(params,20);

assertEquals("abcdefghijklmnopqrst…", params.get("key"));
}

@Test
public void testShouldHandleMultipleEntriesIndependently() {
Map<String, String> params = new HashMap<>();
params.put("path", "/etc/passwd");
params.put("text", "hello world");

telemetryService.sanitize(params);

assertEquals("<path>", params.get("path"));
assertEquals("hello world", params.get("text"));
}
}