diff --git a/src/main/java/io/cryostat/events/S3TemplateService.java b/src/main/java/io/cryostat/events/S3TemplateService.java index bc26d5429..6abf8dbc2 100644 --- a/src/main/java/io/cryostat/events/S3TemplateService.java +++ b/src/main/java/io/cryostat/events/S3TemplateService.java @@ -265,7 +265,6 @@ public Template addTemplate(InputStream stream) } String templateName = labelAttr.getExplicitValue(); - templateName = templateName.replaceAll("[\\W]+", "_"); XMLTagInstance root = model.getRoot(); root.setValue(JFCGrammar.ATTRIBUTE_LABEL_MANDATORY, templateName); diff --git a/src/test/java/itest/CustomEventTemplateTest.java b/src/test/java/itest/CustomEventTemplateTest.java index 2b439146b..557a94340 100644 --- a/src/test/java/itest/CustomEventTemplateTest.java +++ b/src/test/java/itest/CustomEventTemplateTest.java @@ -23,6 +23,7 @@ import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.multipart.MultipartForm; import itest.bases.StandardSelfTest; +import org.apache.http.client.utils.URLEncodedUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; @@ -34,7 +35,7 @@ public class CustomEventTemplateTest extends StandardSelfTest { static final String INVALID_TEMPLATE_FILE_NAME = "invalidTemplate.xml"; - static final String SANITIZE_TEMPLATE_FILE_NAME = "TemplateToSanitize.jfc"; + static final String TEMPLATE_FILE_NAME = "CustomEventTemplate.jfc"; static final String TEMPLATE_NAME = "invalidTemplate"; static final String MEDIA_TYPE = "application/xml"; static final String REQ_URL = "/api/v1/templates"; @@ -87,17 +88,16 @@ public void testDeleteRecordingThrowsOnNonExistentTemplate() throws Exception { } @Test - public void testPostedTemplateIsSanitizedAndCanBeDeleted() throws Exception { + public void testPostedTemplateCanBeDeleted() throws Exception { try { ClassLoader classLoader = getClass().getClassLoader(); - File templateToSanitize = - new File(classLoader.getResource(SANITIZE_TEMPLATE_FILE_NAME).getFile()); - String path = templateToSanitize.getAbsolutePath(); + File customEventTemplate = + new File(classLoader.getResource(TEMPLATE_FILE_NAME).getFile()); + String path = customEventTemplate.getAbsolutePath(); MultipartForm form = MultipartForm.create() - .attribute("template", SANITIZE_TEMPLATE_FILE_NAME) - .binaryFileUpload( - "template", SANITIZE_TEMPLATE_FILE_NAME, path, MEDIA_TYPE); + .attribute("template", TEMPLATE_FILE_NAME) + .binaryFileUpload("template", TEMPLATE_FILE_NAME, path, MEDIA_TYPE); HttpResponse postResp = webClient.extensions().post(REQ_URL, form, REQUEST_TIMEOUT_SECONDS); MatcherAssert.assertThat(postResp.statusCode(), Matchers.equalTo(200)); @@ -115,13 +115,18 @@ public void testPostedTemplateIsSanitizedAndCanBeDeleted() throws Exception { JsonObject json = (JsonObject) o; foundSanitizedTemplate = foundSanitizedTemplate - || json.getString("name").equals("Template_To_Sanitize"); + || json.getString("name").equals("Custom Event Template"); } Assertions.assertTrue(foundSanitizedTemplate); } finally { webClient .extensions() - .delete(REQ_URL + "/Template_To_Sanitize", REQUEST_TIMEOUT_SECONDS); + .delete( + String.format( + "%s/%s", + REQ_URL, + URLEncodedUtils.formatSegments("/Template_To_Sanitize")), + REQUEST_TIMEOUT_SECONDS); } } } diff --git a/src/test/resources/TemplateToSanitize.jfc b/src/test/resources/CustomEventTemplate.jfc similarity index 99% rename from src/test/resources/TemplateToSanitize.jfc rename to src/test/resources/CustomEventTemplate.jfc index 320bd07dd..fc5d05600 100644 --- a/src/test/resources/TemplateToSanitize.jfc +++ b/src/test/resources/CustomEventTemplate.jfc @@ -5,7 +5,7 @@ see Window -> Flight Recorder Template Manager. --> - + true diff --git a/src/test/resources/invalidTemplate.xml b/src/test/resources/invalidTemplate.xml new file mode 100644 index 000000000..2b79f4dc1 --- /dev/null +++ b/src/test/resources/invalidTemplate.xml @@ -0,0 +1 @@ +This is not valid xml.