diff --git a/.gitleaks.toml b/.gitleaks.toml new file mode 100644 index 000000000..4a070d6a5 --- /dev/null +++ b/.gitleaks.toml @@ -0,0 +1,5 @@ +[allowlist] + description = "Global Allowlist" + paths = [ + '''smoketest\/''' + ] diff --git a/pom.xml b/pom.xml index 050f2bf4d..f137e0187 100644 --- a/pom.xml +++ b/pom.xml @@ -98,10 +98,6 @@ io.quarkus quarkus-arc - - io.quarkus - quarkus-elytron-security-properties-file - io.quarkus quarkus-resteasy-reactive-jackson diff --git a/smoketest.bash b/smoketest.bash index 588825136..c1fd22bcc 100755 --- a/smoketest.bash +++ b/smoketest.bash @@ -9,6 +9,7 @@ DIR="$(dirname "$(readlink -f "$0")")" FILES=( "${DIR}/smoketest/compose/db.yml" + "${DIR}/smoketest/compose/auth_proxy.yml" ) USE_USERHOSTS=${USE_USERHOSTS:-true} @@ -79,8 +80,10 @@ FILES+=("${s3Manifest}") if [ "${ce}" = "podman" ]; then FILES+=("${DIR}/smoketest/compose/cryostat.yml") + container_engine="podman" elif [ "${ce}" = "docker" ]; then FILES+=("${DIR}/smoketest/compose/cryostat_docker.yml") + container_engine="docker" else echo "Unknown Container Engine selection: ${ce}" display_usage @@ -107,6 +110,8 @@ cleanup() { docker-compose \ "${CMD[@]}" \ down "${downFlags[@]}" + ${container_engine} rm proxy_cfg_helper + ${container_engine} volume rm auth_proxy_cfg # podman kill hoster || true truncate -s 0 "${HOSTSFILE}" for i in "${PIDS[@]}"; do @@ -117,6 +122,14 @@ cleanup() { trap cleanup EXIT cleanup +createProxyCfgVolume() { + "${container_engine}" volume create auth_proxy_cfg + "${container_engine}" container create --name proxy_cfg_helper -v auth_proxy_cfg:/tmp busybox + "${container_engine}" cp "${DIR}/smoketest/compose/auth_proxy_htpasswd" proxy_cfg_helper:/tmp/auth_proxy_htpasswd + "${container_engine}" cp "${DIR}/smoketest/compose/auth_proxy_alpha_config.yaml" proxy_cfg_helper:/tmp/auth_proxy_alpha_config.yaml +} +createProxyCfgVolume + setupUserHosts() { # FIXME this is broken: it puts the containers' bridge-internal IP addresses # into the user hosts file, but these IPs are in a subnet not reachable from the host. @@ -157,6 +170,9 @@ openBrowserTabs() { local port if [ "${USE_USERHOSTS}" = "true" ]; then host="$(echo "${yaml}" | yq ".[${i}].host" | grep -v null)" + if [ "${host}" = "auth" ]; then + host="localhost" + fi else host="localhost" fi @@ -170,7 +186,16 @@ openBrowserTabs() { echo "Service URLs:" "${urls[@]}" for url in "${urls[@]}"; do ( - until timeout 1s curl -s -f -o /dev/null "${url}" + testSvc() { + timeout 1s curl -s -f -o /dev/null "$1" + local sc="$?" + if [ "${sc}" = "0" ] || [ "${sc}" = "22" ]; then + return 0 + else + return "${sc}" + fi + } + until testSvc "${url}" do sleep 5 done diff --git a/smoketest/compose/auth_proxy.yml b/smoketest/compose/auth_proxy.yml new file mode 100644 index 000000000..e7975cc63 --- /dev/null +++ b/smoketest/compose/auth_proxy.yml @@ -0,0 +1,48 @@ +version: "3" +services: + cryostat: + environment: + QUARKUS_HTTP_PROXY_PROXY_ADDRESS_FORWARDING: 'true' + QUARKUS_HTTP_PROXY_ALLOW_X_FORWARDED: 'true' + QUARKUS_HTTP_PROXY_ENABLE_FORWARDED_HOST: 'true' + QUARKUS_HTTP_PROXY_ENABLE_FORWARDED_PREFIX: 'true' + QUARKUS_HTTP_PROXY_TRUSTED_PROXIES: localhost:8080,auth:8080 + auth: + # the proxy does not actually depend on cryostat being up, but we use this + # to ensure that when the smoketest tries to open the auth login page in a + # browser tab, it does so only after the upstream cryostat is actually + # available to be proxied to + depends_on: + cryostat: + condition: service_healthy + deploy: + resources: + limits: + cpus: '0.1' + memory: 32m + image: quay.io/oauth2-proxy/oauth2-proxy:latest + command: --alpha-config=/tmp/auth_proxy_alpha_config.yaml + volumes: + - auth_proxy_cfg:/tmp + hostname: auth + ports: + - "8080:8080" + labels: + kompose.service.expose: "auth" + environment: + OAUTH2_PROXY_HTPASSWD_FILE: /tmp/auth_proxy_htpasswd + OAUTH2_PROXY_HTPASSWD_USER_GROUP: write + OAUTH2_PROXY_REDIRECT_URL: http://localhost:8080/oauth2/callback + OAUTH2_PROXY_COOKIE_SECRET: __24_BYTE_COOKIE_SECRET_ + # OAUTH2_PROXY_SKIP_AUTH_ROUTES: .* + restart: unless-stopped + healthcheck: + test: wget -q --spider http://localhost:8080/ping || exit 1 + interval: 10s + retries: 3 + start_period: 30s + timeout: 5s + +volumes: + auth_proxy_cfg: + external: true diff --git a/smoketest/compose/auth_proxy_alpha_config.yaml b/smoketest/compose/auth_proxy_alpha_config.yaml new file mode 100644 index 000000000..67f152218 --- /dev/null +++ b/smoketest/compose/auth_proxy_alpha_config.yaml @@ -0,0 +1,14 @@ +server: + BindAddress: http://0.0.0.0:8080 +upstreamConfig: + proxyRawPath: true + upstreams: + - id: cryostat + path: / + uri: http://cryostat:8181 +providers: + - id: dummy + name: Unused - Sign In Below + clientId: CLIENT_ID + clientSecret: CLIENT_SECRET + provider: google diff --git a/smoketest/compose/auth_proxy_htpasswd b/smoketest/compose/auth_proxy_htpasswd new file mode 100644 index 000000000..0398db4f7 --- /dev/null +++ b/smoketest/compose/auth_proxy_htpasswd @@ -0,0 +1 @@ +user:$2y$05$.p1/68oBWKX1FhAtZOArYOoNoMqsB4yuUNXGOeSATHPq3geKqEaZS diff --git a/smoketest/compose/cryostat-grafana.yml b/smoketest/compose/cryostat-grafana.yml index e1a58af6e..33e0c8d4e 100644 --- a/smoketest/compose/cryostat-grafana.yml +++ b/smoketest/compose/cryostat-grafana.yml @@ -25,5 +25,5 @@ services: test: curl --fail http://localhost:3000/ || exit 1 retries: 3 interval: 30s - start_period: 10s + start_period: 30s timeout: 1s diff --git a/smoketest/compose/cryostat.yml b/smoketest/compose/cryostat.yml index f7c3c285f..b95950082 100644 --- a/smoketest/compose/cryostat.yml +++ b/smoketest/compose/cryostat.yml @@ -9,19 +9,17 @@ services: deploy: resources: limits: - cpus: '0.5' + cpus: '2' memory: 512m image: quay.io/cryostat/cryostat:3.0.0-snapshot volumes: - - ${XDG_RUNTIME_DIR}/podman/podman.sock:/run/user/0/podman/podman.sock:Z + - ${XDG_RUNTIME_DIR}/podman/podman.sock:/run/user/1000/podman/podman.sock:Z security_opt: - label:disable hostname: cryostat3 - user: "0" + user: "1000" expose: - - "9091" - ports: - - "8181:8181" + - "8181" labels: kompose.service.expose: "cryostat3" io.cryostat.discovery: "true" @@ -29,13 +27,14 @@ services: io.cryostat.jmxPort: "0" io.cryostat.jmxUrl: "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi" environment: + QUARKUS_HTTP_HOST: "cryostat" CRYOSTAT_DISCOVERY_PODMAN_ENABLED: "true" CRYOSTAT_DISCOVERY_JDP_ENABLED: "true" JAVA_OPTS_APPEND: "-XX:+FlightRecorder -XX:StartFlightRecording=name=onstart,settings=default,disk=true,maxage=5m -Dcom.sun.management.jmxremote.autodiscovery=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9091 -Dcom.sun.management.jmxremote.rmi.port=9091 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false" restart: unless-stopped healthcheck: - test: curl --fail http://localhost:8181/health/liveness || exit 1 + test: curl --fail http://cryostat:8181/health/liveness || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s diff --git a/smoketest/compose/cryostat_docker.yml b/smoketest/compose/cryostat_docker.yml index 9a35f25b3..263006ff3 100644 --- a/smoketest/compose/cryostat_docker.yml +++ b/smoketest/compose/cryostat_docker.yml @@ -9,7 +9,7 @@ services: deploy: resources: limits: - cpus: '0.5' + cpus: '2' memory: 512m image: quay.io/cryostat/cryostat:3.0.0-snapshot volumes: @@ -17,7 +17,7 @@ services: security_opt: - label:disable hostname: cryostat3 - user: "0" + user: "1000" expose: - "9091" ports: @@ -29,13 +29,16 @@ services: io.cryostat.jmxPort: "0" io.cryostat.jmxUrl: "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi" environment: + QUARKUS_HTTP_HOST: "cryostat" + CRYOSTAT_HTTP_PROXY_HOST: "auth" + CRYOSTAT_HTTP_PROXY_PORT: "8080" CRYOSTAT_DISCOVERY_DOCKER_ENABLED: "true" CRYOSTAT_DISCOVERY_JDP_ENABLED: "true" JAVA_OPTS_APPEND: "-XX:+FlightRecorder -XX:StartFlightRecording=name=onstart,settings=default,disk=true,maxage=5m -Dcom.sun.management.jmxremote.autodiscovery=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9091 -Dcom.sun.management.jmxremote.rmi.port=9091 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false" restart: unless-stopped healthcheck: - test: curl --fail http://localhost:8181/health/liveness || exit 1 + test: curl --fail http://cryostat:8181/health/liveness || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s diff --git a/smoketest/compose/cryostat_k8s.yml b/smoketest/compose/cryostat_k8s.yml index 4da589f30..765d34dcf 100644 --- a/smoketest/compose/cryostat_k8s.yml +++ b/smoketest/compose/cryostat_k8s.yml @@ -8,7 +8,6 @@ services: condition: service_healthy image: quay.io/cryostat/cryostat:3.0.0-snapshot hostname: cryostat3 - user: "0" expose: - "9091" ports: @@ -28,5 +27,5 @@ services: test: curl --fail http://localhost:8181/health/liveness || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s diff --git a/smoketest/compose/db-viewer.yml b/smoketest/compose/db-viewer.yml index 822cb82c1..0196712f1 100644 --- a/smoketest/compose/db-viewer.yml +++ b/smoketest/compose/db-viewer.yml @@ -23,7 +23,7 @@ services: test: wget --no-verbose --tries=1 --spider http://localhost:8989 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s volumes: diff --git a/smoketest/compose/db.yml b/smoketest/compose/db.yml index 712181f03..2382dedee 100644 --- a/smoketest/compose/db.yml +++ b/smoketest/compose/db.yml @@ -23,7 +23,7 @@ services: test: pg_isready -U cryostat3 -d cryostat3 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s volumes: diff --git a/smoketest/compose/db_k8s.yml b/smoketest/compose/db_k8s.yml index 53c685793..2e9895376 100644 --- a/smoketest/compose/db_k8s.yml +++ b/smoketest/compose/db_k8s.yml @@ -24,7 +24,7 @@ services: test: pg_isready -U cryostat3 -d cryostat3 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s db-viewer: depends_on: @@ -48,7 +48,7 @@ services: test: wget --no-verbose --tries=1 --spider http://localhost:8989 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s volumes: diff --git a/smoketest/compose/jfr-datasource.yml b/smoketest/compose/jfr-datasource.yml index 0329c763e..dca03a33c 100644 --- a/smoketest/compose/jfr-datasource.yml +++ b/smoketest/compose/jfr-datasource.yml @@ -25,5 +25,5 @@ services: test: curl --fail http://localhost:8080/ || exit 1 retries: 3 interval: 30s - start_period: 10s + start_period: 30s timeout: 1s diff --git a/smoketest/compose/s3-cloudserver.yml b/smoketest/compose/s3-cloudserver.yml index f1313367f..d56a0ca96 100644 --- a/smoketest/compose/s3-cloudserver.yml +++ b/smoketest/compose/s3-cloudserver.yml @@ -34,5 +34,5 @@ services: # - http://localhost:8000/ # interval: 10s # retries: 3 - # start_period: 10s + # start_period: 30s # timeout: 5s diff --git a/smoketest/compose/s3-localstack.yml b/smoketest/compose/s3-localstack.yml index 7f967ebea..89ffa04e2 100644 --- a/smoketest/compose/s3-localstack.yml +++ b/smoketest/compose/s3-localstack.yml @@ -34,7 +34,7 @@ services: test: curl --fail http://localhost:4566 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s volumes: diff --git a/smoketest/compose/s3-minio.yml b/smoketest/compose/s3-minio.yml index 46fe83b44..5d1dcc510 100644 --- a/smoketest/compose/s3-minio.yml +++ b/smoketest/compose/s3-minio.yml @@ -38,7 +38,7 @@ services: - local interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s volumes: @@ -46,4 +46,3 @@ volumes: driver: local minio_certs: driver: local - diff --git a/smoketest/compose/sample-apps.yml b/smoketest/compose/sample-apps.yml index 90fc24e18..0df7724cb 100644 --- a/smoketest/compose/sample-apps.yml +++ b/smoketest/compose/sample-apps.yml @@ -2,22 +2,22 @@ version: "3" services: sample-app-1: depends_on: - cryostat: + auth: condition: service_healthy image: quay.io/andrewazores/vertx-fib-demo:0.13.0 hostname: vertx-fib-demo-1 environment: HTTP_PORT: 8081 JMX_PORT: 9093 - CRYOSTAT_AGENT_APP_NAME: "vertx-fib-demo-1" + CRYOSTAT_AGENT_APP_NAME: vertx-fib-demo-1 CRYOSTAT_AGENT_WEBCLIENT_SSL_TRUST_ALL: "true" CRYOSTAT_AGENT_WEBCLIENT_SSL_VERIFY_HOSTNAME: "false" CRYOSTAT_AGENT_WEBSERVER_HOST: "sample-app-1" CRYOSTAT_AGENT_WEBSERVER_PORT: "8910" CRYOSTAT_AGENT_CALLBACK: "http://sample-app-1:8910/" - CRYOSTAT_AGENT_BASEURI: "http://cryostat:8181/" + CRYOSTAT_AGENT_BASEURI: "http://auth:8080/" CRYOSTAT_AGENT_TRUST_ALL: "true" - CRYOSTAT_AGENT_AUTHORIZATION: "Basic dXNlcjpwYXNz" + CRYOSTAT_AGENT_AUTHORIZATION: Basic dXNlcjpwYXNz ports: - "8081:8081" labels: @@ -29,11 +29,11 @@ services: test: curl --fail http://localhost:8081 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s sample-app-2: depends_on: - cryostat: + auth: condition: service_healthy image: quay.io/andrewazores/vertx-fib-demo:0.13.0 hostname: vertx-fib-demo-2 @@ -47,7 +47,7 @@ services: CRYOSTAT_AGENT_WEBSERVER_HOST: "sample-app-2" CRYOSTAT_AGENT_WEBSERVER_PORT: "8911" CRYOSTAT_AGENT_CALLBACK: "http://sample-app-2:8911/" - CRYOSTAT_AGENT_BASEURI: "http://cryostat:8181/" + CRYOSTAT_AGENT_BASEURI: "http://auth:8080/" CRYOSTAT_AGENT_TRUST_ALL: "true" CRYOSTAT_AGENT_AUTHORIZATION: "Basic dXNlcjpwYXNz" ports: @@ -57,11 +57,11 @@ services: test: curl --fail http://localhost:8081 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s sample-app-3: depends_on: - cryostat: + auth: condition: service_healthy image: quay.io/andrewazores/vertx-fib-demo:0.13.0 hostname: vertx-fib-demo-3 @@ -76,7 +76,7 @@ services: CRYOSTAT_AGENT_WEBSERVER_HOST: "sample-app-3" CRYOSTAT_AGENT_WEBSERVER_PORT: "8910" CRYOSTAT_AGENT_CALLBACK: "http://sample-app-3:8912/" - CRYOSTAT_AGENT_BASEURI: "http://cryostat:8181/" + CRYOSTAT_AGENT_BASEURI: "http://auth:8080/" CRYOSTAT_AGENT_TRUST_ALL: "true" CRYOSTAT_AGENT_AUTHORIZATION: "Basic dXNlcjpwYXNz" ports: @@ -86,11 +86,11 @@ services: test: curl --fail http://localhost:8081 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s quarkus-test-agent: image: quay.io/andrewazores/quarkus-test:latest - # do not add a depends_on:cryostat here, so that we can test that the agent is tolerant of that state + # do not add a depends_on:cryostat/depends_on:auth here, so that we can test that the agent is tolerant of that state hostname: quarkus-test-agent ports: - "10010:10010" @@ -104,7 +104,8 @@ services: CRYOSTAT_AGENT_WEBSERVER_HOST: quarkus-test-agent CRYOSTAT_AGENT_WEBSERVER_PORT: 9977 CRYOSTAT_AGENT_CALLBACK: http://quarkus-test-agent:9977/ - CRYOSTAT_AGENT_BASEURI: http://cryostat:8181/ + CRYOSTAT_AGENT_BASEURI: http://auth:8080/ + CRYOSTAT_AGENT_BASEURI_RANGE: public CRYOSTAT_AGENT_SSL_TRUST_ALL: "true" CRYOSTAT_AGENT_SSL_VERIFY_HOSTNAME: "false" CRYOSTAT_AGENT_AUTHORIZATION: Basic dXNlcjpwYXNz # "Basic $(echo -n user:pass | base64)" @@ -117,6 +118,6 @@ services: test: curl --fail http://localhost:10010 || exit 1 interval: 10s retries: 3 - start_period: 10s + start_period: 30s timeout: 5s diff --git a/src/main/java/io/cryostat/Health.java b/src/main/java/io/cryostat/Health.java index 68ea85238..7884b3b17 100644 --- a/src/main/java/io/cryostat/Health.java +++ b/src/main/java/io/cryostat/Health.java @@ -49,18 +49,6 @@ class Health { @ConfigProperty(name = "quarkus.application.version") String version; - @ConfigProperty(name = "quarkus.http.host") - String host; - - @ConfigProperty(name = "quarkus.http.port") - int port; - - @ConfigProperty(name = "quarkus.http.ssl-port") - int sslPort; - - @ConfigProperty(name = "quarkus.http.ssl.certificate.key-store-password") - Optional sslPass; - @ConfigProperty(name = ConfigProperties.GRAFANA_DASHBOARD_URL) Optional dashboardURL; @@ -117,21 +105,6 @@ public Response health() { @PermitAll public void liveness() {} - @GET - @Path("/api/v1/notifications_url") - @PermitAll - public Response notificationsUrl() { - boolean ssl = sslPass.isPresent(); - return new PermittedResponseBuilder( - Response.ok( - Map.of( - "notificationsUrl", - String.format( - "%s://%s:%d/api/v1/notifications", - ssl ? "wss" : "ws", host, ssl ? sslPort : port)))) - .build(); - } - @GET @Path("/api/v1/grafana_dashboard_url") @PermitAll diff --git a/src/main/java/io/cryostat/recordings/EventOptionsBuilder.java b/src/main/java/io/cryostat/recordings/EventOptionsBuilder.java index 3c0e25162..3029aa9f5 100644 --- a/src/main/java/io/cryostat/recordings/EventOptionsBuilder.java +++ b/src/main/java/io/cryostat/recordings/EventOptionsBuilder.java @@ -33,6 +33,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +// FIXME remove this and use the one from -core instead public class EventOptionsBuilder { private final IMutableConstrainedMap map; diff --git a/src/main/java/io/cryostat/security/Auth.java b/src/main/java/io/cryostat/security/Auth.java index e7553937a..4d72a0b13 100644 --- a/src/main/java/io/cryostat/security/Auth.java +++ b/src/main/java/io/cryostat/security/Auth.java @@ -15,49 +15,28 @@ */ package io.cryostat.security; -import java.time.Duration; -import java.util.HashMap; import java.util.Map; -import io.quarkus.vertx.http.runtime.security.HttpAuthenticator; +import io.cryostat.V2Response; + import io.vertx.ext.web.RoutingContext; import jakarta.annotation.security.PermitAll; -import jakarta.inject.Inject; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import org.jboss.logging.Logger; @Path("") public class Auth { - @Inject Logger logger; - @POST @Path("/api/v2.1/logout") @PermitAll @Produces(MediaType.APPLICATION_JSON) public Response logout(@Context RoutingContext context) { - HttpAuthenticator authenticator = context.get(HttpAuthenticator.class.getName()); - return authenticator - .attemptAuthentication(context) - .onItemOrFailure() - .transform( - (id, t) -> { - if (id == null) { - return unauthorizedResponse(context); - } - if (t != null) { - logger.error("Internal authentication failure", t); - return unauthorizedResponse(context); - } - return okResponse(context, null); - }) - .await() - .atMost(Duration.ofSeconds(20)); + return Response.noContent().build(); } @POST @@ -65,56 +44,9 @@ public Response logout(@Context RoutingContext context) { @PermitAll @Produces(MediaType.APPLICATION_JSON) public Response login(@Context RoutingContext context) { - HttpAuthenticator authenticator = context.get(HttpAuthenticator.class.getName()); - return authenticator - .attemptAuthentication(context) - .onItemOrFailure() - .transform( - (id, t) -> { - if (id == null) { - return unauthorizedResponse(context); - } - if (t != null) { - logger.error("Internal authentication failure", t); - return unauthorizedResponse(context); - } - return okResponse( - context, Map.of("username", id.getPrincipal().getName())); - }) - .await() - .atMost(Duration.ofSeconds(20)); - } - - private Response unauthorizedResponse(RoutingContext context) { - HttpAuthenticator authenticator = context.get(HttpAuthenticator.class.getName()); - var challengeData = authenticator.getChallenge(context).await().indefinitely(); - return Response.status(challengeData.status) - .header(challengeData.headerName.toString(), challengeData.headerContent) - .entity( - Map.of( - "meta", - Map.of( - "status", "Unauthorized", - "type", "text/plain"), - "data", - Map.of("reason", "HTTP Authorization Failure"))) - .build(); - } - - private Response okResponse(RoutingContext context, Object result) { - HttpAuthenticator authenticator = context.get(HttpAuthenticator.class.getName()); - var challengeData = authenticator.getChallenge(context).await().indefinitely(); - var data = new HashMap(); - data.put("result", result); - return Response.ok( - Map.of( - "meta", - Map.of( - "status", "OK", - "type", "application/json"), - "data", - data)) - .header(challengeData.headerName.toString(), challengeData.headerContent) + return Response.ok() + .header("X-WWW-Authenticate", "None") + .entity(V2Response.json(Response.Status.OK, Map.of("username", "user"))) .build(); } } diff --git a/src/main/java/io/cryostat/security/auth/CryostatWebAuthMechanism.java b/src/main/java/io/cryostat/security/auth/CryostatWebAuthMechanism.java deleted file mode 100644 index eb964351b..000000000 --- a/src/main/java/io/cryostat/security/auth/CryostatWebAuthMechanism.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.cryostat.security.auth; - -import java.util.Set; - -import io.netty.handler.codec.http.HttpResponseStatus; -import io.quarkus.security.identity.IdentityProviderManager; -import io.quarkus.security.identity.SecurityIdentity; -import io.quarkus.security.identity.request.AuthenticationRequest; -import io.quarkus.vertx.http.runtime.security.BasicAuthenticationMechanism; -import io.quarkus.vertx.http.runtime.security.ChallengeData; -import io.quarkus.vertx.http.runtime.security.HttpAuthenticationMechanism; -import io.smallrye.mutiny.Uni; -import io.vertx.ext.web.RoutingContext; -import jakarta.annotation.Priority; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.inject.Alternative; -import jakarta.inject.Inject; -import jakarta.ws.rs.core.HttpHeaders; -import org.jboss.logging.Logger; - -@ApplicationScoped -@Alternative -@Priority(0) -public class CryostatWebAuthMechanism implements HttpAuthenticationMechanism { - - @Inject Logger logger; - // TODO replace this with an OAuth mechanism full-time - @Inject BasicAuthenticationMechanism delegate; - - @Override - public Uni authenticate( - RoutingContext context, IdentityProviderManager identityProviderManager) { - return delegate.authenticate(context, identityProviderManager); - } - - @Override - public Uni getChallenge(RoutingContext context) { - int statusCode = HttpResponseStatus.UNAUTHORIZED.code(); - // prepend the 'X-' to the header name so the web-client JS can read it and the browser does - // not intervene as it normally does to this header - String headerName = "X-" + HttpHeaders.WWW_AUTHENTICATE; - // FIXME the content should not need to be capitalized, but the web-client currently - // requires this - String content = "Basic"; - var cd = new ChallengeData(statusCode, headerName, content); - return Uni.createFrom().item(cd); - } - - @Override - public Set> getCredentialTypes() { - return delegate.getCredentialTypes(); - } -} diff --git a/src/main/java/io/cryostat/ws/MessagingServer.java b/src/main/java/io/cryostat/ws/MessagingServer.java index 8ad65bdfa..aa08d0659 100644 --- a/src/main/java/io/cryostat/ws/MessagingServer.java +++ b/src/main/java/io/cryostat/ws/MessagingServer.java @@ -16,7 +16,6 @@ package io.cryostat.ws; import java.io.IOException; -import java.nio.channels.ClosedChannelException; import java.util.Map; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; @@ -30,7 +29,6 @@ import io.quarkus.runtime.ShutdownEvent; import io.quarkus.runtime.StartupEvent; import io.quarkus.vertx.ConsumeEvent; -import io.smallrye.common.annotation.Blocking; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; @@ -40,14 +38,15 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.logging.Logger; @ApplicationScoped -@ServerEndpoint("/api/v1/notifications") +@ServerEndpoint("/api/notifications") public class MessagingServer { + private static final String CLIENT_ACTIVITY_CATEGORY = "WsClientActivity"; + @Inject Logger logger; private final ExecutorService executor = Executors.newSingleThreadExecutor(); private final BlockingQueue msgQ; @@ -58,17 +57,20 @@ public class MessagingServer { this.msgQ = new ArrayBlockingQueue<>(capacity); } - // TODO implement authentication check @OnOpen public void onOpen(Session session) { - logger.infov("Adding session {0}", session.getId()); + logger.debugv("Adding session {0}", session.getId()); sessions.add(session); + broadcast(new Notification(CLIENT_ACTIVITY_CATEGORY, Map.of(session.getId(), "connected"))); } @OnClose public void onClose(Session session) { - logger.infov("Removing session {0}", session.getId()); + logger.debugv("Removing session {0}", session.getId()); sessions.remove(session); + broadcast( + new Notification( + CLIENT_ACTIVITY_CATEGORY, Map.of(session.getId(), "disconnected"))); } @OnError @@ -80,6 +82,9 @@ public void onError(Session session, Throwable throwable) { } catch (IOException ioe) { logger.error("Unable to close session", ioe); } + broadcast( + new Notification( + CLIENT_ACTIVITY_CATEGORY, Map.of(session.getId(), "disconnected"))); } void start(@Observes StartupEvent evt) { @@ -99,25 +104,10 @@ void start(@Observes StartupEvent evt) { sessions.forEach( s -> { try { - s.getBasicRemote() + s.getAsyncRemote() .sendText(mapper.writeValueAsString(map)); } catch (JsonProcessingException e) { logger.error("Unable to serialize message to JSON", e); - } catch (IOException e) { - // ignored simple ClosedChannelExceptions since this - // just means the connection has already been closed, - // either due to an error or the client closing it. This - // does not actually indicate a problem - if (!ExceptionUtils.getThrowableList(e).stream() - .anyMatch( - t -> - t - instanceof - ClosedChannelException)) { - logger.errorv( - "Unable to send message to {0}", s.getId()); - logger.error(e); - } } }); } catch (InterruptedException ie) { @@ -136,11 +126,10 @@ void shutdown(@Observes ShutdownEvent evt) { @OnMessage public void onMessage(Session session, String message) { - logger.infov("{0} message: \"{1}\"", session.getId(), message); + logger.debugv("{0} message: \"{1}\"", session.getId(), message); } @ConsumeEvent - @Blocking void broadcast(Notification notification) { msgQ.add(notification); } diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 3af3648d8..ef12b7ea5 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -3,7 +3,6 @@ quarkus.smallrye-openapi.info-title=Cryostat API (test) cryostat.discovery.jdp.enabled=true cryostat.discovery.podman.enabled=true cryostat.discovery.docker.enabled=true -cryostat.auth.disabled=true quarkus.test.env.JAVA_OPTS_APPEND=-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9091 -Dcom.sun.management.jmxremote.rmi.port=9091 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 839db9919..3a38e6fbe 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -9,7 +9,6 @@ cryostat.messaging.queue.size=1024 quarkus.http.auth.proactive=false quarkus.http.host=0.0.0.0 quarkus.http.port=8181 -quarkus.http.ssl-port=8443 quarkus.http.body.handle-file-uploads=true quarkus.http.body.delete-uploaded-files-on-end=true quarkus.http.limits.max-form-attribute-size=1G @@ -42,17 +41,6 @@ quarkus.http.filter.static.matches=/static/.+ quarkus.http.filter.static.methods=GET quarkus.http.filter.static.order=1 -# FIXME this should be enabled for dev only and use OAuth2 for prod -quarkus.http.auth.basic=true -quarkus.security.users.embedded.enabled=true -quarkus.security.users.embedded.plain-text=true -quarkus.security.users.embedded.users.admin=admin -quarkus.security.users.embedded.roles.admin=read,write,admin -quarkus.security.users.embedded.users.user=pass -quarkus.security.users.embedded.roles.user=read,write -quarkus.security.users.embedded.users.reader=reader -quarkus.security.users.embedded.roles.reader=read - storage.buckets.archives.name=archivedrecordings storage.buckets.archives.expiration-label=expiration diff --git a/src/test/java/io/cryostat/HealthTest.java b/src/test/java/io/cryostat/HealthTest.java index 373fc0916..85ab911fe 100644 --- a/src/test/java/io/cryostat/HealthTest.java +++ b/src/test/java/io/cryostat/HealthTest.java @@ -75,20 +75,6 @@ public void testHealthLiveness() { when().get("/health/liveness").then().statusCode(204); } - @Test - public void testNotificationsUrl() { - boolean ssl = sslPass.isPresent(); - when().get("/api/v1/notifications_url") - .then() - .statusCode(200) - .body( - "notificationsUrl", - is( - String.format( - "%s://%s:%d/api/v1/notifications", - ssl ? "wss" : "ws", host, ssl ? sslPort : port))); - } - @Test public void testGrafanaDashboardUrl() { when().get("/api/v1/grafana_dashboard_url") diff --git a/src/test/java/io/cryostat/TestUtils.java b/src/test/java/io/cryostat/TestUtils.java deleted file mode 100644 index c654f283f..000000000 --- a/src/test/java/io/cryostat/TestUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.cryostat; - -import static io.restassured.RestAssured.given; - -import io.restassured.specification.RequestSpecification; - -public class TestUtils { - public static RequestSpecification givenBasicAuth() { - return given().auth().preemptive().basic("user", "pass"); - } -} diff --git a/src/test/java/io/cryostat/credentials/CredentialsTest.java b/src/test/java/io/cryostat/credentials/CredentialsTest.java index dfa267dc4..35a713e5c 100644 --- a/src/test/java/io/cryostat/credentials/CredentialsTest.java +++ b/src/test/java/io/cryostat/credentials/CredentialsTest.java @@ -15,7 +15,7 @@ */ package io.cryostat.credentials; -import static io.cryostat.TestUtils.givenBasicAuth; +import static io.restassured.RestAssured.given; import java.util.List; @@ -30,8 +30,7 @@ public class CredentialsTest { @Test public void testHealth() { - givenBasicAuth() - .when() + given().when() .get() .then() .statusCode(200) diff --git a/src/test/java/io/cryostat/expressions/MatchExpressionsTest.java b/src/test/java/io/cryostat/expressions/MatchExpressionsTest.java index 724aad986..e4738d5f3 100644 --- a/src/test/java/io/cryostat/expressions/MatchExpressionsTest.java +++ b/src/test/java/io/cryostat/expressions/MatchExpressionsTest.java @@ -15,9 +15,7 @@ */ package io.cryostat.expressions; -import static io.cryostat.TestUtils.givenBasicAuth; import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.*; import java.util.HashMap; import java.util.List; @@ -43,19 +41,13 @@ public void afterEach() { MatchExpression.deleteAll(); } - @Test - public void testUnauthorizedPost() { - given().body(ALL_MATCHING_EXPRESSION).when().post().then().assertThat().statusCode(401); - } - @Test public void testPostWithoutTargets() { var expectation = new HashMap<>(); expectation.put("id", null); expectation.put("expression", "true"); expectation.put("targets", List.of()); - givenBasicAuth() - .contentType(ContentType.JSON) + given().contentType(ContentType.JSON) .body(ALL_MATCHING_EXPRESSION) .when() .post() diff --git a/src/test/java/io/cryostat/rules/RulesTest.java b/src/test/java/io/cryostat/rules/RulesTest.java index ec153dd72..d96cf00ed 100644 --- a/src/test/java/io/cryostat/rules/RulesTest.java +++ b/src/test/java/io/cryostat/rules/RulesTest.java @@ -15,8 +15,7 @@ */ package io.cryostat.rules; -import static io.cryostat.TestUtils.givenBasicAuth; -import static io.restassured.RestAssured.when; +import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.*; @@ -63,15 +62,9 @@ public void afterEach() { Rule.deleteAll(); } - @Test - public void testUnauthorized() { - when().get().then().statusCode(401); - } - @Test public void testListEmpty() { - givenBasicAuth() - .get() + given().get() .then() .statusCode(200) .body( @@ -83,15 +76,9 @@ public void testListEmpty() { @Test @Transactional public void testList() { - givenBasicAuth() - .body(rule.toString()) - .contentType(ContentType.JSON) - .post() - .then() - .statusCode(201); + given().body(rule.toString()).contentType(ContentType.JSON).post().then().statusCode(201); - givenBasicAuth() - .get() + given().get() .then() .statusCode(200) .body( @@ -107,8 +94,7 @@ public void testList() { public void testUpdate() { var copy = rule.copy(); copy.put("enabled", false); - givenBasicAuth() - .body(copy.toString()) + given().body(copy.toString()) .contentType(ContentType.JSON) .post() .then() @@ -118,8 +104,7 @@ public void testUpdate() { "meta.status", is("Created"), "data.result", is(RULE_NAME)); - givenBasicAuth() - .get() + given().get() .then() .statusCode(200) .body( @@ -129,8 +114,7 @@ public void testUpdate() { "data.result[0].name", is(RULE_NAME), "data.result[0].enabled", is(false)); - givenBasicAuth() - .body(new JsonObject().put("enabled", true).toString()) + given().body(new JsonObject().put("enabled", true).toString()) .contentType(ContentType.JSON) .patch(RULE_NAME) .then() @@ -144,15 +128,9 @@ public void testUpdate() { @Test public void testUpdateWithClean() { - givenBasicAuth() - .body(rule.toString()) - .contentType(ContentType.JSON) - .post() - .then() - .statusCode(201); + given().body(rule.toString()).contentType(ContentType.JSON).post().then().statusCode(201); - givenBasicAuth() - .queryParam("clean", true) + given().queryParam("clean", true) .body(new JsonObject().put("enabled", false).toString()) .contentType(ContentType.JSON) .patch(RULE_NAME) @@ -171,12 +149,7 @@ public void testUpdateWithClean() { @Test public void testCreateThrowsWhenRuleNameExists() { // Created: rule_name - givenBasicAuth() - .body(rule.toString()) - .contentType(ContentType.JSON) - .post() - .then() - .statusCode(201); + given().body(rule.toString()).contentType(ContentType.JSON).post().then().statusCode(201); // Try to create again var conflictRule = new JsonObject(); @@ -184,17 +157,12 @@ public void testCreateThrowsWhenRuleNameExists() { conflictRule.put("matchExpression", EXPR_2); conflictRule.put("eventSpecifier", "some_other_event_specifier"); - givenBasicAuth() - .body(rule.toString()) - .contentType(ContentType.JSON) - .post() - .then() - .statusCode(409); + given().body(rule.toString()).contentType(ContentType.JSON).post().then().statusCode(409); } @Test public void testCreateThrowsWhenBodyNull() { - givenBasicAuth().contentType(ContentType.JSON).post().then().statusCode(400); + given().contentType(ContentType.JSON).post().then().statusCode(400); } @Test @@ -203,8 +171,7 @@ public void testCreateThrowsWhenMandatoryFieldsUnspecified() { badRule.put("name", RULE_NAME); badRule.put("matchExpression", EXPR_2); // MISSING: badRule.put("eventSpecifier", "some_other_event_specifier"); - givenBasicAuth() - .body(badRule.toString()) + given().body(badRule.toString()) .contentType(ContentType.JSON) .post() .then() @@ -213,20 +180,14 @@ public void testCreateThrowsWhenMandatoryFieldsUnspecified() { @Test public void testDeleteEmpty() { - givenBasicAuth().delete(RULE_NAME).then().statusCode(404); + given().delete(RULE_NAME).then().statusCode(404); } @Test public void testDelete() { - givenBasicAuth() - .body(rule.toString()) - .contentType(ContentType.JSON) - .post() - .then() - .statusCode(201); + given().body(rule.toString()).contentType(ContentType.JSON).post().then().statusCode(201); - givenBasicAuth() - .delete(RULE_NAME) + given().delete(RULE_NAME) .then() .statusCode(200) .body( @@ -237,15 +198,9 @@ public void testDelete() { @Test public void testDeleteWithClean() { - givenBasicAuth() - .body(rule.toString()) - .contentType(ContentType.JSON) - .post() - .then() - .statusCode(201); + given().body(rule.toString()).contentType(ContentType.JSON).post().then().statusCode(201); - givenBasicAuth() - .queryParam("clean", true) + given().queryParam("clean", true) .delete(RULE_NAME) .then() .statusCode(200) diff --git a/src/test/java/itest/CustomTargetsTest.java b/src/test/java/itest/CustomTargetsTest.java index b7a08d123..ccfea9b51 100644 --- a/src/test/java/itest/CustomTargetsTest.java +++ b/src/test/java/itest/CustomTargetsTest.java @@ -16,10 +16,8 @@ package itest; import java.net.UnknownHostException; -import java.util.HashMap; import java.util.Map; import java.util.UUID; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -28,8 +26,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import io.cryostat.util.HttpMimeType; - import io.quarkus.test.junit.QuarkusTest; import io.vertx.core.MultiMap; import io.vertx.core.buffer.Buffer; @@ -37,7 +33,6 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.web.client.HttpResponse; import itest.bases.StandardSelfTest; -import itest.util.ITestCleanupFailedException; import itest.util.http.JvmIdWebRequest; import itest.util.http.StoredCredential; import org.apache.http.client.utils.URLEncodedUtils; @@ -73,7 +68,7 @@ static void removeTestHarnessTargetDefinition() JsonArray list = webClient .extensions() - .get("/api/v3/targets", true, REQUEST_TIMEOUT_SECONDS) + .get("/api/v3/targets", REQUEST_TIMEOUT_SECONDS) .bodyAsJsonArray(); if (!list.isEmpty()) throw new IllegalStateException(); } @@ -93,37 +88,10 @@ static void cleanup() throws Exception { if (storedCredential == null) { return; } - CompletableFuture deleteResponse = new CompletableFuture<>(); webClient - .delete("/api/v2.2/credentials/" + storedCredential.id) - .send( - ar -> { - if (assertRequestStatus(ar, deleteResponse)) { - deleteResponse.complete(ar.result().bodyAsJsonObject()); - } - }); - - Map nullResult = new HashMap<>(); - nullResult.put("result", null); - JsonObject expectedDeleteResponse = - new JsonObject( - Map.of( - "meta", - Map.of("type", HttpMimeType.JSON.mime(), "status", "OK"), - "data", - nullResult)); - try { - MatcherAssert.assertThat( - deleteResponse.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), - Matchers.equalTo(expectedDeleteResponse)); - } catch (Exception e) { - logger.error( - new ITestCleanupFailedException( - String.format( - "Failed to clean up credential with ID %d", - storedCredential.id), - e)); - } + .extensions() + .delete("/api/v2.2/credentials/" + storedCredential.id, 0) + .bodyAsJsonObject(); } @Test @@ -135,7 +103,6 @@ void shouldBeAbleToTestTargetConnection() .extensions() .post( "/api/v2/targets?dryrun=true", - true, Buffer.buffer( JsonObject.of("connectUrl", SELF_JMX_URL, "alias", "self") .encode()), @@ -149,7 +116,7 @@ void shouldBeAbleToTestTargetConnection() JsonArray list = webClient .extensions() - .get("/api/v3/targets", true, REQUEST_TIMEOUT_SECONDS) + .get("/api/v3/targets", REQUEST_TIMEOUT_SECONDS) .bodyAsJsonArray(); MatcherAssert.assertThat(list, Matchers.notNullValue()); MatcherAssert.assertThat(list.size(), Matchers.equalTo(0)); @@ -207,7 +174,6 @@ void shouldBeAbleToDefineTarget() .extensions() .post( "/api/v2/targets?storeCredentials=true", - true, form, REQUEST_TIMEOUT_SECONDS); MatcherAssert.assertThat(response.statusCode(), Matchers.equalTo(201)); @@ -249,7 +215,7 @@ void shouldBeAbleToDefineTarget() Matchers.equalTo(alias)); HttpResponse listResponse = - webClient.extensions().get("/api/v1/targets", true, REQUEST_TIMEOUT_SECONDS); + webClient.extensions().get("/api/v1/targets", REQUEST_TIMEOUT_SECONDS); MatcherAssert.assertThat(listResponse.statusCode(), Matchers.equalTo(200)); JsonArray list = listResponse.bodyAsJsonArray(); MatcherAssert.assertThat(list, Matchers.notNullValue()); @@ -312,13 +278,12 @@ void shouldBeAbleToDeleteTarget() .extensions() .delete( String.format("/api/v2/targets/%s", JMX_URL_ENCODED), - true, REQUEST_TIMEOUT_SECONDS); latch.await(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); HttpResponse listResponse = - webClient.extensions().get("/api/v1/targets", true, REQUEST_TIMEOUT_SECONDS); + webClient.extensions().get("/api/v1/targets", REQUEST_TIMEOUT_SECONDS); MatcherAssert.assertThat(listResponse.statusCode(), Matchers.equalTo(200)); JsonArray list = listResponse.bodyAsJsonArray(); MatcherAssert.assertThat(list, Matchers.notNullValue()); diff --git a/src/test/java/itest/NonExistentTargetIT.java b/src/test/java/itest/NonExistentTargetIT.java index cf43d91c2..aac11db69 100644 --- a/src/test/java/itest/NonExistentTargetIT.java +++ b/src/test/java/itest/NonExistentTargetIT.java @@ -41,7 +41,6 @@ public void testConnectionFailsAsExpected() throws Exception { CompletableFuture response = new CompletableFuture<>(); webClient .get(String.format("/api/v1/targets/%s/recordings", BAD_TARGET_CONNECT_URL_ENCODED)) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, response)) { diff --git a/src/test/java/itest/NoopAuthV2IT.java b/src/test/java/itest/NoopAuthV2IT.java index 228b9812b..0dc6d8984 100644 --- a/src/test/java/itest/NoopAuthV2IT.java +++ b/src/test/java/itest/NoopAuthV2IT.java @@ -27,9 +27,11 @@ import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @QuarkusIntegrationTest +@Disabled public class NoopAuthV2IT extends StandardSelfTest { HttpRequest req; @@ -42,15 +44,14 @@ void createRequest() { @Test public void shouldRespond200() throws Exception { CompletableFuture future = new CompletableFuture<>(); - req.basicAuthentication("user", "pass") - .send( - ar -> { - if (ar.succeeded()) { - future.complete(ar.result().bodyAsJsonObject()); - } else { - future.completeExceptionally(ar.cause()); - } - }); + req.send( + ar -> { + if (ar.succeeded()) { + future.complete(ar.result().bodyAsJsonObject()); + } else { + future.completeExceptionally(ar.cause()); + } + }); JsonObject response = future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); diff --git a/src/test/java/itest/NotificationsUrlIT.java b/src/test/java/itest/NotificationsUrlIT.java deleted file mode 100644 index ad41e2cb8..000000000 --- a/src/test/java/itest/NotificationsUrlIT.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package itest; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import io.vertx.core.buffer.Buffer; -import io.vertx.ext.web.client.HttpRequest; -import itest.bases.StandardSelfTest; -import itest.util.Utils; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -@QuarkusIntegrationTest -public class NotificationsUrlIT extends StandardSelfTest { - - HttpRequest req; - - @BeforeEach - void createRequest() { - req = webClient.get("/api/v1/notifications_url"); - } - - @Test - public void shouldSucceed() throws Exception { - CompletableFuture future = new CompletableFuture<>(); - req.basicAuthentication("user", "pass") - .send( - ar -> { - if (ar.succeeded()) { - future.complete(ar.result().statusCode()); - } else { - future.completeExceptionally(ar.cause()); - } - }); - MatcherAssert.assertThat( - future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), Matchers.equalTo(200)); - } - - @Test - public void shouldReturnOK() throws Exception { - CompletableFuture future = new CompletableFuture<>(); - req.basicAuthentication("user", "pass") - .send( - ar -> { - if (ar.succeeded()) { - future.complete(ar.result().statusMessage()); - } else { - future.completeExceptionally(ar.cause()); - } - }); - MatcherAssert.assertThat( - future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), Matchers.equalTo("OK")); - } - - @Test - public void shouldReturnContentTypeJson() throws Exception { - CompletableFuture future = new CompletableFuture<>(); - req.basicAuthentication("user", "pass") - .send( - ar -> { - if (ar.succeeded()) { - future.complete(ar.result().getHeader("Content-Type")); - } else { - future.completeExceptionally(ar.cause()); - } - }); - MatcherAssert.assertThat( - future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), - Matchers.equalTo("application/json;charset=UTF-8")); - } - - @Test - public void shouldReturnJsonMessage() throws Exception { - CompletableFuture future = new CompletableFuture<>(); - req.basicAuthentication("user", "pass") - .send( - ar -> { - if (ar.succeeded()) { - future.complete(ar.result().bodyAsString()); - } else { - future.completeExceptionally(ar.cause()); - } - }); - MatcherAssert.assertThat( - future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), - Matchers.equalTo( - String.format( - "{\"notificationsUrl\":\"ws://%s:%d/api/v1/notifications\"}", - "0.0.0.0", Utils.WEB_PORT))); - } -} diff --git a/src/test/java/itest/RecordingWorkflowTest.java b/src/test/java/itest/RecordingWorkflowTest.java index a693da95c..1abafc771 100644 --- a/src/test/java/itest/RecordingWorkflowTest.java +++ b/src/test/java/itest/RecordingWorkflowTest.java @@ -61,7 +61,6 @@ public void testWorkflow() throws Exception { String.format( "/api/v1/targets/%s/recordings", getSelfReferenceConnectUrlEncoded())) - .basicAuthentication("user", "pass") .followRedirects(true) .send( ar -> { @@ -85,7 +84,6 @@ public void testWorkflow() throws Exception { String.format( "/api/v1/targets/%s/recordings", getSelfReferenceConnectUrlEncoded()), - true, form, REQUEST_TIMEOUT_SECONDS); @@ -97,7 +95,6 @@ public void testWorkflow() throws Exception { "/api/v1/targets/%s/recordings", getSelfReferenceConnectUrlEncoded())) .followRedirects(true) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, listRespFuture2)) { @@ -128,7 +125,6 @@ public void testWorkflow() throws Exception { "/api/v1/targets/%s/recordings/%s", getSelfReferenceConnectUrlEncoded(), TEST_RECORDING_NAME), - true, saveHeaders, Buffer.buffer("SAVE"), REQUEST_TIMEOUT_SECONDS) @@ -143,7 +139,6 @@ public void testWorkflow() throws Exception { "/api/v1/targets/%s/recordings", getSelfReferenceConnectUrlEncoded())) .followRedirects(true) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, listRespFuture3)) { @@ -165,7 +160,6 @@ public void testWorkflow() throws Exception { CompletableFuture listRespFuture4 = new CompletableFuture<>(); webClient .get("/api/v1/recordings") - .basicAuthentication("user", "pass") .followRedirects(true) .send( ar -> { @@ -196,7 +190,6 @@ public void testWorkflow() throws Exception { "/api/v1/targets/%s/recordings", getSelfReferenceConnectUrlEncoded())) .followRedirects(true) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, listRespFuture5)) { @@ -240,7 +233,6 @@ public void testWorkflow() throws Exception { HttpResponse reportResponse = webClient .get(reportUrl) - .basicAuthentication("user", "pass") .as(BodyCodec.jsonObject()) .send() .toCompletionStage() @@ -265,7 +257,6 @@ public void testWorkflow() throws Exception { String.format( "/api/v1/targets/%s/recordings/%s", getSelfReferenceConnectUrlEncoded(), TEST_RECORDING_NAME), - true, REQUEST_TIMEOUT_SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new ITestCleanupFailedException( @@ -281,7 +272,6 @@ public void testWorkflow() throws Exception { String.format( "/api/beta/recordings/%s/%s", getSelfReferenceConnectUrlEncoded(), savedRecording), - true, REQUEST_TIMEOUT_SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new ITestCleanupFailedException( diff --git a/src/test/java/itest/RulesPostFormIT.java b/src/test/java/itest/RulesPostFormIT.java index d2f120925..cfa38dfad 100644 --- a/src/test/java/itest/RulesPostFormIT.java +++ b/src/test/java/itest/RulesPostFormIT.java @@ -69,7 +69,6 @@ void testAddRuleThrowsWhenFormAttributesNull() throws Exception { webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.URLENCODED_FORM.mime()) .sendForm( MultiMap.caseInsensitiveMultiMap(), @@ -92,7 +91,6 @@ void testAddRuleThrowsWhenRuleNameAlreadyExists() throws Exception { try { webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader( HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.URLENCODED_FORM.mime()) @@ -120,7 +118,6 @@ void testAddRuleThrowsWhenRuleNameAlreadyExists() throws Exception { CompletableFuture duplicatePostResponse = new CompletableFuture<>(); webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader( HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.URLENCODED_FORM.mime()) @@ -143,7 +140,6 @@ void testAddRuleThrowsWhenRuleNameAlreadyExists() throws Exception { CompletableFuture deleteResponse = new CompletableFuture<>(); webClient .delete(String.format("/api/v2/rules/%s", TEST_RULE_NAME)) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, deleteResponse)) { @@ -180,7 +176,6 @@ void testAddRuleThrowsWhenIntegerAttributesNegative() throws Exception { webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.URLENCODED_FORM.mime()) .sendForm( testRule, diff --git a/src/test/java/itest/RulesPostJsonIT.java b/src/test/java/itest/RulesPostJsonIT.java index 838ff1f6b..b1bc929d1 100644 --- a/src/test/java/itest/RulesPostJsonIT.java +++ b/src/test/java/itest/RulesPostJsonIT.java @@ -68,7 +68,6 @@ void testAddRuleThrowsWhenJsonAttributesNull() throws Exception { webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.JSON.mime()) .sendJsonObject( null, @@ -90,7 +89,6 @@ void testAddRuleThrowsWhenMimeUnsupported() throws Exception { webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), "text/plain") .sendJsonObject( testRule, @@ -113,7 +111,6 @@ void testAddRuleThrowsWhenMimeInvalid() throws Exception { webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), "NOTAMIME") .sendJsonObject( testRule, @@ -136,7 +133,6 @@ void testAddRuleThrowsWhenRuleNameAlreadyExists() throws Exception { try { webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.JSON.mime()) .sendJsonObject( testRule, @@ -162,7 +158,6 @@ void testAddRuleThrowsWhenRuleNameAlreadyExists() throws Exception { CompletableFuture duplicatePostResponse = new CompletableFuture<>(); webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.JSON.mime()) .sendJsonObject( testRule, @@ -183,7 +178,6 @@ void testAddRuleThrowsWhenRuleNameAlreadyExists() throws Exception { CompletableFuture deleteResponse = new CompletableFuture<>(); webClient .delete(String.format("/api/v2/rules/%s", TEST_RULE_NAME)) - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.JSON.mime()) .send( ar -> { @@ -221,7 +215,6 @@ void testAddRuleThrowsWhenIntegerAttributesNegative() throws Exception { try { webClient .post("/api/v2/rules") - .basicAuthentication("user", "pass") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.JSON.mime()) .sendJsonObject( testRule, diff --git a/src/test/java/itest/SnapshotTest.java b/src/test/java/itest/SnapshotTest.java index ece42cdcc..0e31d60e9 100644 --- a/src/test/java/itest/SnapshotTest.java +++ b/src/test/java/itest/SnapshotTest.java @@ -55,7 +55,6 @@ void testPostV1ShouldHandleEmptySnapshot() throws Exception { CompletableFuture preListRespFuture = new CompletableFuture<>(); webClient .get(String.format("%s/recordings", v1RequestUrl())) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, preListRespFuture)) { @@ -69,7 +68,6 @@ void testPostV1ShouldHandleEmptySnapshot() throws Exception { // Create an empty snapshot recording (no active recordings present) webClient .post(String.format("%s/snapshot", v1RequestUrl())) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, result)) { @@ -84,7 +82,6 @@ void testPostV1ShouldHandleEmptySnapshot() throws Exception { CompletableFuture postListRespFuture = new CompletableFuture<>(); webClient .get(String.format("%s/recordings", v1RequestUrl())) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, postListRespFuture)) { @@ -101,7 +98,6 @@ void testPostV2ShouldHandleEmptySnapshot() throws Exception { CompletableFuture preListRespFuture = new CompletableFuture<>(); webClient .get(String.format("%s/recordings", v1RequestUrl())) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, preListRespFuture)) { @@ -115,7 +111,6 @@ void testPostV2ShouldHandleEmptySnapshot() throws Exception { // Create an empty snapshot recording (no active recordings present) webClient .post(String.format("%s/snapshot", v2RequestUrl())) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, result)) { @@ -130,7 +125,6 @@ void testPostV2ShouldHandleEmptySnapshot() throws Exception { CompletableFuture postListRespFuture = new CompletableFuture<>(); webClient .get(String.format("%s/recordings", v1RequestUrl())) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, postListRespFuture)) { @@ -154,14 +148,12 @@ void testPostV1ShouldCreateSnapshot() throws Exception { .extensions() .post( String.format("%s/recordings", v1RequestUrl()), - true, form, REQUEST_TIMEOUT_SECONDS); // Create a snapshot recording of all events at that time webClient .post(String.format("%s/snapshot", v1RequestUrl())) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, snapshotName)) { @@ -183,7 +175,6 @@ void testPostV1ShouldCreateSnapshot() throws Exception { .extensions() .delete( String.format("%s/recordings/%s", v1RequestUrl(), TEST_RECORDING_NAME), - true, REQUEST_TIMEOUT_SECONDS); webClient .extensions() @@ -192,7 +183,6 @@ void testPostV1ShouldCreateSnapshot() throws Exception { "%s/recordings/%s", v1RequestUrl(), snapshotName.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS)), - true, REQUEST_TIMEOUT_SECONDS); } @@ -201,7 +191,6 @@ void testPostV1SnapshotThrowsWithNonExistentTarget() throws Exception { CompletableFuture snapshotResponse = new CompletableFuture<>(); webClient .post("/api/v1/targets/notFound%2F9000/snapshot") - .basicAuthentication("user", "pass") .send( ar -> { assertRequestStatus(ar, snapshotResponse); @@ -228,7 +217,6 @@ void testPostV2ShouldCreateSnapshot() throws Exception { .extensions() .post( String.format("%s/recordings", v1RequestUrl()), - true, form, REQUEST_TIMEOUT_SECONDS); @@ -236,7 +224,6 @@ void testPostV2ShouldCreateSnapshot() throws Exception { CompletableFuture createResponse = new CompletableFuture<>(); webClient .post(String.format("%s/snapshot", v2RequestUrl())) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, createResponse)) { @@ -291,7 +278,6 @@ void testPostV2ShouldCreateSnapshot() throws Exception { .extensions() .delete( String.format("%s/recordings/%s", v1RequestUrl(), TEST_RECORDING_NAME), - true, REQUEST_TIMEOUT_SECONDS); webClient .extensions() @@ -300,7 +286,6 @@ void testPostV2ShouldCreateSnapshot() throws Exception { "%s/recordings/%s", v1RequestUrl(), snapshotName.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS)), - true, REQUEST_TIMEOUT_SECONDS); } @@ -309,7 +294,6 @@ void testPostV2SnapshotThrowsWithNonExistentTarget() throws Exception { CompletableFuture snapshotName = new CompletableFuture<>(); webClient .post("/api/v2/targets/notFound:9000/snapshot") - .basicAuthentication("user", "pass") .send( ar -> { assertRequestStatus(ar, snapshotName); diff --git a/src/test/java/itest/TargetEventsGetTest.java b/src/test/java/itest/TargetEventsGetTest.java index 3007511f8..0323d8d5a 100644 --- a/src/test/java/itest/TargetEventsGetTest.java +++ b/src/test/java/itest/TargetEventsGetTest.java @@ -53,7 +53,6 @@ public void testGetTargetEventsReturnsListOfEvents() throws Exception { CompletableFuture> getResponse = new CompletableFuture<>(); webClient .get(eventReqUrl) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, getResponse)) { @@ -75,7 +74,6 @@ public void testGetTargetEventsV2WithNoQueryReturnsListOfEvents() throws Excepti CompletableFuture> getResponse = new CompletableFuture<>(); webClient .get(searchReqUrl) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, getResponse)) { @@ -100,7 +98,6 @@ public void testGetTargetEventsV2WithQueryReturnsRequestedEvents() throws Except CompletableFuture> getResponse = new CompletableFuture<>(); webClient .get(String.format("%s?q=TargetConnectionOpened", searchReqUrl)) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, getResponse)) { @@ -163,7 +160,6 @@ public void testGetTargetEventsV2WithQueryReturnsEmptyListWhenNoEventsMatch() th CompletableFuture> getResponse = new CompletableFuture<>(); webClient .get(String.format("%s?q=thisEventDoesNotExist", searchReqUrl)) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, getResponse)) { diff --git a/src/test/java/itest/TargetRecordingPatchTest.java b/src/test/java/itest/TargetRecordingPatchTest.java index 130e43657..b6f7e6628 100644 --- a/src/test/java/itest/TargetRecordingPatchTest.java +++ b/src/test/java/itest/TargetRecordingPatchTest.java @@ -57,7 +57,7 @@ void testSaveEmptyRecordingDoesNotArchiveRecordingFile() throws Exception { optionsForm.add("toDisk", "false"); optionsForm.add("maxSize", "0"); HttpResponse optionsResponse = - webClient.extensions().patch(optionsRequestUrl(), true, null, optionsForm, 5); + webClient.extensions().patch(optionsRequestUrl(), null, optionsForm, 5); MatcherAssert.assertThat(optionsResponse.statusCode(), Matchers.equalTo(200)); // Create an empty recording @@ -66,7 +66,7 @@ void testSaveEmptyRecordingDoesNotArchiveRecordingFile() throws Exception { form.add("duration", "5"); form.add("events", "template=ALL"); HttpResponse postResponse = - webClient.extensions().post(recordingRequestUrl(), true, form, 5); + webClient.extensions().post(recordingRequestUrl(), form, 5); MatcherAssert.assertThat(postResponse.statusCode(), Matchers.equalTo(201)); // Attempt to save the recording to archive @@ -76,7 +76,6 @@ void testSaveEmptyRecordingDoesNotArchiveRecordingFile() throws Exception { .patch( String.format( "%s/%s", recordingRequestUrl(), TEST_RECORDING_NAME), - true, null, Buffer.buffer("SAVE"), 5); @@ -87,7 +86,6 @@ void testSaveEmptyRecordingDoesNotArchiveRecordingFile() throws Exception { CompletableFuture listRespFuture1 = new CompletableFuture<>(); webClient .get(archivesRequestUrl()) - .basicAuthentication("user", "pass") .send( ar -> { if (assertRequestStatus(ar, listRespFuture1)) { @@ -105,7 +103,6 @@ void testSaveEmptyRecordingDoesNotArchiveRecordingFile() throws Exception { .delete( String.format( "%s/%s", recordingRequestUrl(), TEST_RECORDING_NAME), - true, 5); if (!HttpStatusCodeIdentifier.isSuccessCode(deleteResponse.statusCode())) { throw new ITestCleanupFailedException(); @@ -115,7 +112,7 @@ void testSaveEmptyRecordingDoesNotArchiveRecordingFile() throws Exception { MultiMap optionsForm = MultiMap.caseInsensitiveMultiMap(); optionsForm.add("toDisk", "unset"); optionsForm.add("maxSize", "unset"); - webClient.extensions().patch(optionsRequestUrl(), true, null, optionsForm, 5); + webClient.extensions().patch(optionsRequestUrl(), null, optionsForm, 5); } } } diff --git a/src/test/java/itest/UploadRecordingTest.java b/src/test/java/itest/UploadRecordingTest.java index 0ef11155b..6c8d16b57 100644 --- a/src/test/java/itest/UploadRecordingTest.java +++ b/src/test/java/itest/UploadRecordingTest.java @@ -67,9 +67,7 @@ public static void createRecording() throws Exception { CREATE_RECORDING_URL = String.format("/api/v1/targets/%s/recordings", getSelfReferenceConnectUrlEncoded()); HttpResponse resp = - webClient - .extensions() - .post(CREATE_RECORDING_URL, true, form, RECORDING_DURATION_SECONDS); + webClient.extensions().post(CREATE_RECORDING_URL, form, RECORDING_DURATION_SECONDS); MatcherAssert.assertThat(resp.statusCode(), Matchers.equalTo(201)); Thread.sleep( Long.valueOf( @@ -86,7 +84,6 @@ public static void deleteRecording() throws Exception { String.format( "/api/v1/targets/%s/recordings/%s", getSelfReferenceConnectUrlEncoded(), RECORDING_NAME), - true, REQUEST_TIMEOUT_SECONDS); MatcherAssert.assertThat(resp.statusCode(), Matchers.equalTo(204)); } catch (InterruptedException | ExecutionException | TimeoutException e) { @@ -107,7 +104,6 @@ public void shouldLoadRecordingToDatasource() throws Exception { String.format( "/api/v1/targets/%s/recordings/%s/upload", getSelfReferenceConnectUrlEncoded(), RECORDING_NAME), - true, (Buffer) null, 0); diff --git a/src/test/java/itest/bases/StandardSelfTest.java b/src/test/java/itest/bases/StandardSelfTest.java index 693f085f1..2575c2db4 100644 --- a/src/test/java/itest/bases/StandardSelfTest.java +++ b/src/test/java/itest/bases/StandardSelfTest.java @@ -24,7 +24,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -88,7 +87,6 @@ public static void assertNoRecordings() throws Exception { String.format( "/api/v1/targets/%s/recordings", getSelfReferenceConnectUrlEncoded()), - true, REQUEST_TIMEOUT_SECONDS) .bodyAsJsonArray(); if (!listResp.isEmpty()) { @@ -105,8 +103,7 @@ public static void deleteSelfCustomTarget() } logger.infov("Deleting self custom target at {0}", selfCustomTargetLocation); String path = URI.create(selfCustomTargetLocation).getPath(); - HttpResponse resp = - webClient.extensions().delete(path, true, REQUEST_TIMEOUT_SECONDS); + HttpResponse resp = webClient.extensions().delete(path, REQUEST_TIMEOUT_SECONDS); logger.infov( "DELETE {0} -> HTTP {1} {2}: [{3}]", path, resp.statusCode(), resp.statusMessage(), resp.headers()); @@ -124,7 +121,6 @@ public static void waitForDiscovery(int otherTargetsCount) { () -> { webClient .get("/api/v3/targets") - .basicAuthentication("user", "pass") .as(BodyCodec.jsonArray()) .timeout(TimeUnit.SECONDS.toMillis(REQUEST_TIMEOUT_SECONDS)) .send( @@ -170,9 +166,7 @@ private static boolean selfCustomTargetExists() { } try { HttpResponse resp = - webClient - .extensions() - .get(selfCustomTargetLocation, true, REQUEST_TIMEOUT_SECONDS); + webClient.extensions().get(selfCustomTargetLocation, REQUEST_TIMEOUT_SECONDS); logger.infov( "POST /api/v2/targets -> HTTP {0} {1}: [{2}]", resp.statusCode(), resp.statusMessage(), resp.headers()); @@ -202,7 +196,6 @@ private static void tryDefineSelfCustomTarget() { .extensions() .post( "/api/v2/targets", - true, Buffer.buffer(self.encode()), REQUEST_TIMEOUT_SECONDS); logger.infov( @@ -222,8 +215,7 @@ public static String getSelfReferenceConnectUrl() { try { tryDefineSelfCustomTarget(); String path = URI.create(selfCustomTargetLocation).getPath(); - HttpResponse resp = - webClient.extensions().get(path, true, REQUEST_TIMEOUT_SECONDS); + HttpResponse resp = webClient.extensions().get(path, REQUEST_TIMEOUT_SECONDS); JsonObject body = resp.bodyAsJsonObject(); logger.infov( "GET {0} -> HTTP {1} {2}: [{3}] = {4}", @@ -254,7 +246,7 @@ public static CompletableFuture expectNotification( var a = new WebSocket[1]; Utils.HTTP_CLIENT.webSocket( - getNotificationsUrl().get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), + "ws://localhost/api/notifications", ar -> { if (ar.failed()) { future.completeExceptionally(ar.cause()); @@ -308,33 +300,6 @@ public static boolean assertRequestStatus( return true; } - private static Future getNotificationsUrl() { - CompletableFuture future = new CompletableFuture<>(); - WORKER.submit( - () -> { - webClient - .get("/api/v1/notifications_url") - .send( - ar -> { - if (ar.succeeded()) { - HttpResponse resp = ar.result(); - logger.infov( - "GET /api/v1/notifications_url -> HTTP {0} {1}:" - + " [{2}]", - resp.statusCode(), - resp.statusMessage(), - resp.headers()); - future.complete( - resp.bodyAsJsonObject() - .getString("notificationsUrl")); - } else { - future.completeExceptionally(ar.cause()); - } - }); - }); - return future; - } - public static CompletableFuture downloadFile(String url, String name, String suffix) { return fireDownloadRequest( webClient.get(url), name, suffix, MultiMap.caseInsensitiveMultiMap()); @@ -361,7 +326,6 @@ private static CompletableFuture fireDownloadRequest( WORKER.submit( () -> { request.putHeaders(headers) - .basicAuthentication("user", "pass") .followRedirects(true) .send( ar -> { diff --git a/src/test/java/itest/util/Utils.java b/src/test/java/itest/util/Utils.java index c74256f22..d8172de2a 100644 --- a/src/test/java/itest/util/Utils.java +++ b/src/test/java/itest/util/Utils.java @@ -83,24 +83,22 @@ public static FileSystem getFileSystem() { } public interface RedirectExtensions { - HttpResponse get(String url, boolean authentication, int timeout) + HttpResponse get(String url, int timeout) throws InterruptedException, ExecutionException, TimeoutException; - HttpResponse post(String url, boolean authentication, Buffer payload, int timeout) + HttpResponse post(String url, Buffer payload, int timeout) throws InterruptedException, ExecutionException, TimeoutException; - HttpResponse post(String url, boolean authentication, MultiMap payload, int timeout) + HttpResponse post(String url, MultiMap payload, int timeout) throws InterruptedException, ExecutionException, TimeoutException; - HttpResponse delete(String url, boolean authentication, int timeout) + HttpResponse delete(String url, int timeout) throws InterruptedException, ExecutionException, TimeoutException; - HttpResponse patch( - String url, boolean authentication, MultiMap headers, Buffer payload, int timeout) + HttpResponse patch(String url, MultiMap headers, Buffer payload, int timeout) throws InterruptedException, ExecutionException, TimeoutException; - HttpResponse patch( - String url, boolean authentication, MultiMap headers, MultiMap payload, int timeout) + HttpResponse patch(String url, MultiMap headers, MultiMap payload, int timeout) throws InterruptedException, ExecutionException, TimeoutException; } @@ -118,14 +116,11 @@ public RedirectExtensions extensions() { } private class RedirectExtensionsImpl implements RedirectExtensions { - public HttpResponse get(String url, boolean authentication, int timeout) + public HttpResponse get(String url, int timeout) throws InterruptedException, ExecutionException, TimeoutException { CompletableFuture> future = new CompletableFuture<>(); RequestOptions options = new RequestOptions().setURI(url); HttpRequest req = TestWebClient.this.request(HttpMethod.GET, options); - if (authentication) { - req.basicAuthentication("user", "pass"); - } req.send( ar -> { if (ar.succeeded()) { @@ -135,20 +130,16 @@ public HttpResponse get(String url, boolean authentication, int timeout) } }); if (future.get().statusCode() == 308) { - return get(future.get().getHeader("Location"), true, timeout); + return get(future.get().getHeader("Location"), timeout); } return future.get(timeout, TimeUnit.SECONDS); } - public HttpResponse post( - String url, boolean authentication, Buffer payload, int timeout) + public HttpResponse post(String url, Buffer payload, int timeout) throws InterruptedException, ExecutionException, TimeoutException { CompletableFuture> future = new CompletableFuture<>(); RequestOptions options = new RequestOptions().setURI(url); HttpRequest req = TestWebClient.this.request(HttpMethod.POST, options); - if (authentication) { - req.basicAuthentication("user", "pass"); - } if (payload != null) { req.sendBuffer( payload, @@ -170,21 +161,16 @@ public HttpResponse post( }); } if (future.get().statusCode() == 308) { - return post( - future.get().getHeader("Location"), authentication, payload, timeout); + return post(future.get().getHeader("Location"), payload, timeout); } return future.get(timeout, TimeUnit.SECONDS); } - public HttpResponse post( - String url, boolean authentication, MultiMap payload, int timeout) + public HttpResponse post(String url, MultiMap payload, int timeout) throws InterruptedException, ExecutionException, TimeoutException { CompletableFuture> future = new CompletableFuture<>(); RequestOptions options = new RequestOptions().setURI(url); HttpRequest req = TestWebClient.this.request(HttpMethod.POST, options); - if (authentication) { - req.basicAuthentication("user", "pass"); - } if (payload != null) { req.sendForm( payload, @@ -206,20 +192,16 @@ public HttpResponse post( }); } if (future.get().statusCode() == 308) { - return post( - future.get().getHeader("Location"), authentication, payload, timeout); + return post(future.get().getHeader("Location"), payload, timeout); } return future.get(timeout, TimeUnit.SECONDS); } - public HttpResponse delete(String url, boolean authentication, int timeout) + public HttpResponse delete(String url, int timeout) throws InterruptedException, ExecutionException, TimeoutException { CompletableFuture> future = new CompletableFuture<>(); RequestOptions options = new RequestOptions().setURI(url); HttpRequest req = TestWebClient.this.request(HttpMethod.DELETE, options); - if (authentication) { - req.basicAuthentication("user", "pass"); - } req.send( ar -> { if (ar.succeeded()) { @@ -229,24 +211,17 @@ public HttpResponse delete(String url, boolean authentication, int timeo } }); if (future.get().statusCode() == 308) { - return delete(future.get().getHeader("Location"), true, timeout); + return delete(future.get().getHeader("Location"), timeout); } return future.get(timeout, TimeUnit.SECONDS); } public HttpResponse patch( - String url, - boolean authentication, - MultiMap headers, - Buffer payload, - int timeout) + String url, MultiMap headers, Buffer payload, int timeout) throws InterruptedException, ExecutionException, TimeoutException { CompletableFuture> future = new CompletableFuture<>(); RequestOptions options = new RequestOptions().setURI(url); HttpRequest req = TestWebClient.this.request(HttpMethod.PATCH, options); - if (authentication) { - req.basicAuthentication("user", "pass"); - } if (headers != null) { req.putHeaders(headers); } @@ -260,25 +235,17 @@ public HttpResponse patch( } }); if (future.get().statusCode() == 308) { - return patch( - future.get().getHeader("Location"), true, headers, payload, timeout); + return patch(future.get().getHeader("Location"), headers, payload, timeout); } return future.get(timeout, TimeUnit.SECONDS); } public HttpResponse patch( - String url, - boolean authentication, - MultiMap headers, - MultiMap payload, - int timeout) + String url, MultiMap headers, MultiMap payload, int timeout) throws InterruptedException, ExecutionException, TimeoutException { CompletableFuture> future = new CompletableFuture<>(); RequestOptions options = new RequestOptions().setURI(url); HttpRequest req = TestWebClient.this.request(HttpMethod.PATCH, options); - if (authentication) { - req.basicAuthentication("user", "pass"); - } if (headers != null) { req.putHeaders(headers); } @@ -292,8 +259,7 @@ public HttpResponse patch( } }); if (future.get().statusCode() == 308) { - return patch( - future.get().getHeader("Location"), true, headers, payload, timeout); + return patch(future.get().getHeader("Location"), headers, payload, timeout); } return future.get(timeout, TimeUnit.SECONDS); } diff --git a/src/test/java/itest/util/http/JvmIdWebRequest.java b/src/test/java/itest/util/http/JvmIdWebRequest.java index f9c8180b7..b601e4824 100644 --- a/src/test/java/itest/util/http/JvmIdWebRequest.java +++ b/src/test/java/itest/util/http/JvmIdWebRequest.java @@ -33,7 +33,6 @@ public static String jvmIdRequest(long id) .extensions() .get( String.format("/api/v3/targets/%d", id), - true, StandardSelfTest.REQUEST_TIMEOUT_SECONDS) .bodyAsJsonObject() .getString("jvmId"); @@ -43,7 +42,7 @@ public static String jvmIdRequest(String connectUrl) throws InterruptedException, ExecutionException, TimeoutException { return webClient .extensions() - .get("/api/v3/targets", true, StandardSelfTest.REQUEST_TIMEOUT_SECONDS) + .get("/api/v3/targets", StandardSelfTest.REQUEST_TIMEOUT_SECONDS) .bodyAsJsonArray() .stream() .map(o -> (JsonObject) o)