aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-08-31 17:09:34 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-08-31 17:09:34 +0200
commit24be6f6f96c95c9ea05b91d277fe513355d18fba (patch)
tree8a71006463fe7f55aefaae65b3229234fbbe3c30
parent4be216b93444d2c4befffa1ef483d828b0fd8ba2 (diff)
Escape all non-alphanumeric characters
-rw-r--r--node-admin/pom.xml10
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImpl.java9
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImplTest.java21
3 files changed, 35 insertions, 5 deletions
diff --git a/node-admin/pom.xml b/node-admin/pom.xml
index 473d106775e..d7da29bbba7 100644
--- a/node-admin/pom.xml
+++ b/node-admin/pom.xml
@@ -95,6 +95,16 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.yahoo.vespa</groupId>
<artifactId>application</artifactId>
<version>${project.version}</version>
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImpl.java
index 9ebaa614fb8..7df971c979c 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImpl.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImpl.java
@@ -1,6 +1,7 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.maintenance.servicedump;
+import com.yahoo.text.Lowercase;
import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeAttributes;
import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeRepository;
import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeSpec;
@@ -154,11 +155,9 @@ public class VespaServiceDumperImpl implements VespaServiceDumper {
request.configId(), request.expireAt(), message);
}
- private static String createDumpId(ServiceDumpReport report) {
- String sanitizedConfigId = report.configId()
- .replace('/', '-')
- .replace('@', '-');
- return sanitizedConfigId + "-" + report.getCreatedMillisOrNull().toString();
+ static String createDumpId(ServiceDumpReport request) {
+ String sanitizedConfigId = Lowercase.toLowerCase(request.configId()).replaceAll("[^a-z_0-9]", "-");
+ return sanitizedConfigId + "-" + request.getCreatedMillisOrNull().toString();
}
private static URI serviceDumpDestination(NodeSpec spec, String dumpId) {
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImplTest.java
new file mode 100644
index 00000000000..9e7cd4c14bb
--- /dev/null
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/VespaServiceDumperImplTest.java
@@ -0,0 +1,21 @@
+package com.yahoo.vespa.hosted.node.admin.maintenance.servicedump;// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Instant;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * @author bjorncs
+ */
+class VespaServiceDumperImplTest {
+ @Test
+ void creates_valid_dump_id_from_dump_request() {
+ long nowMillis = Instant.now().toEpochMilli();
+ ServiceDumpReport request = new ServiceDumpReport(
+ nowMillis, null, null, null, null, "default/container.3", null, null);
+ String dumpId = VespaServiceDumperImpl.createDumpId(request);
+ assertEquals("default-container-3-" + nowMillis, dumpId);
+ }
+} \ No newline at end of file