Skip to content

Commit

Permalink
Add testing endpoints in RX vert.x
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-alvarez-alvarez committed Nov 14, 2024
1 parent 6c2819a commit 038ec19
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import io.vertx.reactivex.core.MultiMap
import io.vertx.reactivex.ext.web.Router
import io.vertx.reactivex.ext.web.RoutingContext
import io.vertx.reactivex.ext.web.handler.BodyHandler
import io.vertx.reactivex.ext.web.handler.CookieHandler
import io.vertx.reactivex.ext.web.handler.SessionHandler
import io.vertx.reactivex.ext.web.sstore.LocalSessionStore

import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_MULTIPART
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_URLENCODED
Expand All @@ -22,6 +25,7 @@ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_QUERY
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SESSION_ID
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.USER_BLOCK
import static server.VertxTestServer.CONFIG_HTTP_SERVER_PORT
Expand Down Expand Up @@ -233,6 +237,26 @@ class VertxRxCircuitBreakerHttpServerForkedTest extends VertxHttpServerForkedTes
})
}

router.route(SESSION_ID.getPath()).handler(CookieHandler.create())
final LocalSessionStore sessionStorage = LocalSessionStore.create(super.@vertx)
router
.route(SESSION_ID.getPath())
.handler(SessionHandler.create(sessionStorage).setCookieSecureFlag(true).setCookieHttpOnlyFlag(true))
router
.route(SESSION_ID.getPath())
.handler { ctx ->
controller(SESSION_ID) {
final session = ctx.session()
if (!session) {
ctx.response()
.setStatusCode(500)
.end('Cookie/Session handlers not present')
} else {
ctx.response().setStatusCode(SESSION_ID.getStatus()).end(session.id())
}
}
}

super.@vertx.createHttpServer(new HttpServerOptions().setHandle100ContinueAutomatically(true))
.requestHandler { router.accept(it) }
.listen(port) { startFuture.complete() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import io.vertx.core.AbstractVerticle
import io.vertx.core.Future
import io.vertx.core.http.HttpServerOptions
import io.vertx.ext.web.Router
import io.vertx.ext.web.handler.CookieHandler
import io.vertx.ext.web.handler.SessionHandler
import io.vertx.ext.web.sstore.LocalSessionStore
import spock.lang.Ignore

import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
Expand All @@ -12,6 +15,7 @@ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.FORWAR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SESSION_ID
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static server.VertxTestServer.CONFIG_HTTP_SERVER_PORT

Expand Down Expand Up @@ -72,6 +76,24 @@ class VertxRxHttpServerForkedTest extends VertxHttpServerForkedTest {
}
}

router.route(SESSION_ID.getPath()).handler(CookieHandler.create())
final LocalSessionStore sessionStorage = LocalSessionStore.create(vertx)
router
.route(SESSION_ID.getPath())
.handler(SessionHandler.create(sessionStorage).setCookieSecureFlag(true).setCookieHttpOnlyFlag(true))
router.route(SESSION_ID.getPath()).handler { ctx ->
controller(SESSION_ID) {
final session = ctx.session()
if (session == null) {
ctx.response()
.setStatusCode(500)
.end('Cookie/Session handlers not present')
} else {
ctx.response().setStatusCode(SESSION_ID.getStatus()).end(session.id())
}
}
}

super.@vertx.createHttpServer(new HttpServerOptions().setHandle100ContinueAutomatically(true))
.requestHandler { router.accept(it) }
.listen(port) { startFuture.complete() }
Expand Down

0 comments on commit 038ec19

Please sign in to comment.