From 03b59279d74a50812451010058e17f2c723174e1 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 29 Aug 2024 19:30:12 +0200 Subject: [PATCH] Artifact id must match [A-Za-z0-9-]+ --- .../org/fugerit/java/doc/playground/init/ProjectRest.java | 4 ++++ .../java/org/fugerit/java/doc/playground/InitRestTest.java | 1 + .../src/test/resources/request/payload/init/init_ko_2.json | 1 + 3 files changed, 6 insertions(+) create mode 100644 fj-doc-playground-quarkus/src/test/resources/request/payload/init/init_ko_2.json diff --git a/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectRest.java b/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectRest.java index c5202f39c..51fe58ca0 100644 --- a/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectRest.java +++ b/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectRest.java @@ -56,6 +56,10 @@ private File initConfigWorker( String base ) { @Path("/init") public Response init( ProjectInitInput input) { return RestHelper.defaultHandle( () -> { + // check artifact id naming + if ( !input.getArtifactId().matches( "[A-Za-z0-9-]+" ) ) { + return Response.status( Response.Status.BAD_REQUEST ).build(); + } long time = System.currentTimeMillis(); ProjectInitOutput output = new ProjectInitOutput(); try ( ByteArrayOutputStream buffer = new ByteArrayOutputStream() ) { diff --git a/fj-doc-playground-quarkus/src/test/java/org/fugerit/java/doc/playground/InitRestTest.java b/fj-doc-playground-quarkus/src/test/java/org/fugerit/java/doc/playground/InitRestTest.java index 06bc9485e..1157fc37a 100644 --- a/fj-doc-playground-quarkus/src/test/java/org/fugerit/java/doc/playground/InitRestTest.java +++ b/fj-doc-playground-quarkus/src/test/java/org/fugerit/java/doc/playground/InitRestTest.java @@ -44,6 +44,7 @@ private void testWorker( String apiPath, String jsonPayloadPath, int code ) { void testInit() { this.testWorker( "/project/init", "request/payload/init/init_ok_1.json", 200 ); this.testWorker( "/project/init", "request/payload/init/init_ko_1.json", 200 ); + this.testWorker( "/project/init", "request/payload/init/init_ko_2.json", 400 ); Assertions.assertTrue( Boolean.TRUE ); // the condition is actually checked by rest assured } diff --git a/fj-doc-playground-quarkus/src/test/resources/request/payload/init/init_ko_2.json b/fj-doc-playground-quarkus/src/test/resources/request/payload/init/init_ko_2.json new file mode 100644 index 000000000..4845c64e3 --- /dev/null +++ b/fj-doc-playground-quarkus/src/test/resources/request/payload/init/init_ko_2.json @@ -0,0 +1 @@ +{"groupId":"org.fugerit.java.demo","artifactId":"../fugerit-doc-demo","projectVersion":"1.0.0-SNAPSHOT","javaVersion":"21","venusVersion":"8.7.4"} \ No newline at end of file