Skip to content

Commit 0b393fe

Browse files
committed
chore: increase path field max size and improve telemetry errors
1 parent 3675c76 commit 0b393fe

7 files changed

Lines changed: 85 additions & 8 deletions

File tree

owlplug-client/src/main/java/com/owlplug/core/components/TaskRunner.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.slf4j.Logger;
3333
import org.slf4j.LoggerFactory;
3434
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.springframework.core.NestedExceptionUtils;
3536
import org.springframework.core.task.SimpleAsyncTaskExecutor;
3637
import org.springframework.stereotype.Component;
3738

@@ -114,13 +115,15 @@ private synchronized void scheduleNext() {
114115
taskBarController.setErrorLog(
115116
currentTask,
116117
ex.getMessage(),
117-
StringUtils.getStackTraceAsString(ex)
118+
StringUtils.getStackTraceAsString(ex),
119+
NestedExceptionUtils.getMostSpecificCause(ex).getMessage()
118120
);
119121
} else {
120122
taskBarController.setErrorLog(
121123
currentTask,
122124
"Task failed",
123-
"No error information available."
125+
"No error information available.",
126+
"No summary available"
124127
);
125128
}
126129
removeCurrentTask();

owlplug-client/src/main/java/com/owlplug/core/controllers/TaskBarController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ private void showErrorDialog(String title, String content) {
133133
).show();
134134
}
135135

136-
public void setErrorLog(AbstractTask task, String title, String content) {
136+
public void setErrorLog(AbstractTask task, String title, String content, String summary) {
137137

138138
this.getTelemetryService().event("/Error/TaskExecution", p -> {
139139
p.put("taskName", task.getName());
140140
p.put("error", title);
141-
p.put("content", content);
141+
p.put("summary", summary);
142142
});
143143
taskProgressBar.getStyleClass().add("progress-bar-error");
144144
logsButton.setVisible(true);

owlplug-client/src/main/java/com/owlplug/core/services/TelemetryService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ private void send(String name, Map<String, String> params) {
107107
}
108108
}
109109

110-
private void sanitize(Map<String, String> params) {
110+
void sanitize(Map<String, String> params) {
111+
sanitize(params, MAX_PROPS_LENGTH);
112+
}
113+
void sanitize(Map<String, String> params, int maxLength) {
111114
for (Map.Entry<String, String> entry : params.entrySet()) {
112115
String value = entry.getValue();
113-
if (value.length() > MAX_PROPS_LENGTH) {
114-
value = value.substring(0, MAX_PROPS_LENGTH) + "…";
116+
if (value.length() > maxLength) {
117+
value = value.substring(0, maxLength) + "…";
115118
}
116119

117120
// Redact absolute paths (Unix & Windows)

owlplug-client/src/main/java/com/owlplug/plugin/model/Plugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ public class Plugin {
5454
protected String category;
5555
protected String manufacturerName;
5656
protected String identifier;
57+
@Column(length = 512)
5758
protected String path;
59+
@Column(length = 512)
5860
protected String scanDirectoryPath;
5961
protected String bundleId;
6062
protected String version;
6163

62-
// Suggestion: could be renamed to screenshotURI
6364
protected String screenshotUrl;
6465
protected boolean nativeCompatible = false;
6566
protected boolean syncComplete = false;

owlplug-client/src/main/java/com/owlplug/plugin/model/PluginDirectory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
package com.owlplug.plugin.model;
2020

21+
import jakarta.persistence.Column;
2122
import java.util.List;
2223

2324
public class PluginDirectory implements IDirectory {
2425

2526
protected String name;
2627
protected String displayName;
28+
@Column(length = 512)
2729
protected String path;
2830
protected boolean rootDirectory;
2931
protected List<Plugin> pluginList;

owlplug-client/src/main/java/com/owlplug/plugin/model/PluginFootprint.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.owlplug.plugin.model;
2020

21+
import jakarta.persistence.Column;
2122
import jakarta.persistence.Entity;
2223
import jakarta.persistence.GeneratedValue;
2324
import jakarta.persistence.GenerationType;
@@ -33,6 +34,7 @@ public class PluginFootprint {
3334
@Id
3435
@GeneratedValue(strategy = GenerationType.AUTO)
3536
protected Long id;
37+
@Column(length = 512)
3638
protected String path;
3739
protected boolean nativeDiscoveryEnabled = true;
3840

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.owlplug.core.services;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import org.junit.jupiter.api.Test;
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
public class TelemetryServiceTest {
9+
10+
private final TelemetryService telemetryService = new TelemetryService();
11+
12+
@Test
13+
public void testShouldRedactUnixAbsolutePath() {
14+
Map<String, String> params = new HashMap<>();
15+
params.put("key", "Error reading /var/log/app/error.log file");
16+
17+
telemetryService.sanitize(params);
18+
19+
assertEquals("Error reading <path> file", params.get("key"));
20+
}
21+
22+
@Test
23+
public void testShouldRedactWindowsAbsolutePath() {
24+
Map<String, String> params = new HashMap<>();
25+
params.put("key", "Failed at C:\\\\Users\\\\john\\\\secret.txt");
26+
27+
telemetryService.sanitize(params);
28+
29+
assertEquals("Failed at <path>", params.get("key"));
30+
}
31+
32+
@Test
33+
public void testShouldNotRedactClassNamesOrPackages() {
34+
Map<String, String> params = new HashMap<>();
35+
params.put("key", "at com.example.service.MyClass.method(MyClass.java:42)");
36+
37+
telemetryService.sanitize(params);
38+
39+
assertEquals(
40+
"at com.example.service.MyClass.method(MyClass.java:42)",
41+
params.get("key")
42+
);
43+
}
44+
45+
@Test
46+
public void testShouldTruncateLongValuesAndAppendEllipsis() {
47+
Map<String, String> params = new HashMap<>();
48+
params.put("key", "abcdefghijklmnopqrstuvwxyz");
49+
50+
telemetryService.sanitize(params,20);
51+
52+
assertEquals("abcdefghijklmnopqrst…", params.get("key"));
53+
}
54+
55+
@Test
56+
public void testShouldHandleMultipleEntriesIndependently() {
57+
Map<String, String> params = new HashMap<>();
58+
params.put("path", "/etc/passwd");
59+
params.put("text", "hello world");
60+
61+
telemetryService.sanitize(params);
62+
63+
assertEquals("<path>", params.get("path"));
64+
assertEquals("hello world", params.get("text"));
65+
}
66+
}

0 commit comments

Comments
 (0)