Skip to content

Commit 6199ea8

Browse files
committed
Vertx gradle test
1 parent 9f01834 commit 6199ea8

File tree

8 files changed

+162
-1
lines changed

8 files changed

+162
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ plugins {
2222
id 'pl.allegro.tech.build.axion-release' version '1.14.4'
2323
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
2424

25-
id "com.github.johnrengelman.shadow" version "7.1.2" apply false
25+
id "com.github.johnrengelman.shadow" version "8.1.1" apply false
2626
id "me.champeau.jmh" version "0.7.0" apply false
2727
id 'org.gradle.playframework' version '0.13' apply false
2828
id 'info.solidsoft.pitest' version '1.9.11' apply false

dd-java-agent/agent-iast/src/main/java/com/datadog/iast/overhead/Operations.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.datadog.iast.overhead;
22

3+
import datadog.trace.api.Config;
4+
35
import javax.annotation.Nullable;
46

57
public class Operations {
@@ -18,6 +20,9 @@ public boolean hasQuota(@Nullable final OverheadContext context) {
1820

1921
@Override
2022
public boolean consumeQuota(@Nullable final OverheadContext context) {
23+
// if(Config.get().isCiVisibilityEnabled()){
24+
// return true;
25+
// }
2126
if (context == null) {
2227
return false;
2328
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plugins {
2+
id 'java'
3+
id 'application'
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
implementation 'io.vertx:vertx-core:3.9.13'
12+
implementation 'io.vertx:vertx-web:3.9.13'
13+
14+
testImplementation 'io.vertx:vertx-unit:3.9.13'
15+
testImplementation 'junit:junit:4.13.2'
16+
}
17+
18+
application {
19+
mainClass = 'com.example.MainVerticle'
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'Vertx3-IW'
2+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.example;
2+
3+
import io.vertx.core.AbstractVerticle;
4+
import io.vertx.core.Future;
5+
import io.vertx.ext.web.Router;
6+
7+
import java.security.MessageDigest;
8+
import java.security.NoSuchAlgorithmException;
9+
import java.util.Arrays;
10+
11+
public class MainVerticle extends AbstractVerticle {
12+
13+
@Override
14+
public void start(Future<Void> startFuture) {
15+
Router router = Router.router(vertx);
16+
17+
router.get("/greetings").handler(ctx -> {
18+
String param = ctx.request().getParam("param");
19+
if (param == null) {
20+
ctx.response()
21+
.setStatusCode(400)
22+
.end("Missing 'param' query parameter");
23+
} else {
24+
ctx.response()
25+
.putHeader("content-type", "text/plain")
26+
.end("Hello " + param);
27+
}
28+
});
29+
30+
router.get("/insecure_hash").handler(ctx -> {
31+
try {
32+
MessageDigest md = MessageDigest.getInstance("MD5");
33+
ctx.response()
34+
.putHeader("content-type", "text/plain")
35+
.end("insecure hash");
36+
} catch (NoSuchAlgorithmException e) {
37+
throw new RuntimeException(e);
38+
}
39+
});
40+
41+
// Iniciar servidor HTTP
42+
vertx.createHttpServer()
43+
.requestHandler(router)
44+
.listen(8080, http -> {
45+
if (http.succeeded()) {
46+
startFuture.complete();
47+
System.out.println("HTTP server started on port 8080");
48+
} else {
49+
startFuture.fail(http.cause());
50+
}
51+
});
52+
}
53+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.example;
2+
3+
import io.vertx.core.Vertx;
4+
import io.vertx.ext.unit.Async;
5+
import io.vertx.ext.unit.TestContext;
6+
import io.vertx.ext.unit.junit.VertxUnitRunner;
7+
import org.junit.After;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
12+
import java.security.MessageDigest;
13+
import java.security.NoSuchAlgorithmException;
14+
15+
@RunWith(VertxUnitRunner.class)
16+
public class MainVerticleTest {
17+
18+
private Vertx vertx;
19+
private TestContext context;
20+
21+
@Before
22+
public void setUp(TestContext testContext) {
23+
context = testContext;
24+
vertx = Vertx.vertx();
25+
vertx.deployVerticle(MainVerticle.class.getName(), testContext.asyncAssertSuccess());
26+
}
27+
28+
@After
29+
public void tearDown() {
30+
vertx.close(context.asyncAssertSuccess());
31+
}
32+
33+
@Test
34+
public void testGreetingsEndpoint() {
35+
Async async = context.async();
36+
37+
vertx.createHttpClient().getNow(8080, "localhost", "/greetings?param=World", response -> {
38+
context.assertEquals(200, response.statusCode());
39+
40+
response.bodyHandler(body -> {
41+
context.assertEquals("Hello World", body.toString());
42+
async.complete();
43+
});
44+
});
45+
}
46+
47+
@Test
48+
public void testInsecureHashEndpoint() {
49+
Async async = context.async();
50+
51+
vertx.createHttpClient().getNow(8080, "localhost", "/insecure_hash", response -> {
52+
context.assertEquals(200, response.statusCode());
53+
54+
response.bodyHandler(body -> {
55+
context.assertEquals("insecure hash", body.toString());
56+
async.complete();
57+
});
58+
});
59+
}
60+
61+
@Test
62+
public void testInsecureHash() throws NoSuchAlgorithmException {
63+
MessageDigest.getInstance("MD5");
64+
assert true;
65+
}
66+
67+
68+
69+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
./gradlew dd-smoke-tests:vertx3-iast-ci:test --rerun-tasks -Dorg.gradle.jvmargs=\
2+
-javaagent:/Users/alejandro.gonzalez/IdeaProjects/dd-trace-java/dd-java-agent/build/libs/dd-java-agent-1.44.0-SNAPSHOT.jar=\
3+
dd.civisibility.enabled=true,\
4+
dd.env=local,\
5+
dd.service=dd—java-trace-vertx-iw-q42024,\
6+
dd.iast.enabled=true,\
7+
dd.iast.detection.mode=FULL,\
8+
dd.iast.context.mode=GLOBAL,\
9+
dd.civisibility.debug.port=5005

settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,6 @@ include ':dd-java-agent:benchmark'
507507
include ':dd-java-agent:benchmark-integration'
508508
include ':dd-java-agent:benchmark-integration:jetty-perftest'
509509
include ':dd-java-agent:benchmark-integration:play-perftest'
510+
include 'dd-smoke-tests:vertx3-iast-ci'
511+
findProject(':dd-smoke-tests:vertx3-iast-ci')?.name = 'vertx3-iast-ci'
512+

0 commit comments

Comments
 (0)