In REST Assured, what does given().relaxedHTTPSValidation() actually switch off?
answer
- two checks, not one
- trust manager plus hostname verifier
- empty checkServerTrusted, allow-all verifier
- protocol defaults to SSL, not TLS
basics
~20 sIt replaces REST Assured's SSL socket factory with one built from a trust-all X509TrustManager and Apache HttpClient's allow-all hostname verifier, so both certificate-chain validation and hostname checking stop. The SSLContext protocol defaults to SSL. Nothing else on the request changes.
solid answer
~40 s`given().relaxedHTTPSValidation()` is a shortcut for `SSLConfig.relaxedHTTPSValidation()`. That method builds an `SSLContext` — protocol `SSL` unless you pass one, as in `relaxedHTTPSValidation("TLS")` — initialises it with an `X509TrustManager` whose `checkServerTrusted` body is empty and whose `getAcceptedIssuers()` returns null, and wraps it in an Apache `SSLSocketFactory` using `ALLOW_ALL_HOSTNAME_VERIFIER`. Those two together are the whole server-identity check, so a call to `https://orders.bakery.test/preorders` will accept a self-signed certificate, an expired one, or one issued for a completely different host. One difference is worth knowing: the static `RestAssured.useRelaxedHTTPSValidation()` rebuilds the SSL config from scratch and discards a key store you set earlier, while the request-level form relaxes the config the request already carries. Treat it as a test-environment tool — it disables a real security control, so scope it to the one host that needs it.
code
java · 13 linesimport static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
given()
.relaxedHTTPSValidation()
.baseUri("https://orders.bakery.test")
.contentType("application/json")
.body("{\"loafType\":\"sourdough\",\"quantity\":2,\"collectionSlot\":\"2026-09-12T07:30\"}")
.when()
.post("/preorders")
.then()
.statusCode(201)
.body("status", equalTo("RESERVED"));go deeper
Know the spelling and where it goes: relaxedHTTPSValidation() on a request, useRelaxedHTTPSValidation() as a static. Be able to say it makes a self-signed certificate stop failing the call.
Explain the mechanics: a trust manager with empty check methods plus an allow-all hostname verifier, wrapped in one SSL socket factory, with SSL as the default context protocol. Name both checks, not just the chain.
Show you treat it as a removed control rather than a fix. Be ready to say which environments may carry it, how you keep it off a shared static, and what you would use in its place where a private authority exists.
Own the policy: where relaxed validation is permitted at all, how that decision is recorded and reviewed, and why a switch that leaves no trace in the response needs a convention rather than trust in individual judgement.
## What the method is a shortcut for `given().relaxedHTTPSValidation()` never touches the socket itself. It reads the `SSLConfig` out of the `RestAssuredConfig` the request is already carrying, calls `SSLConfig.relaxedHTTPSValidation(protocol)` on it, and stores the result back on the request. Everything interesting happens inside that one `SSLConfig` method, and the no-argument DSL form simply passes the literal `"SSL"` into it. That method does four things, in order: 1. Builds an `SSLContext` for the protocol string it was handed. 2. Loads a key store into a `KeyManager` **only if one was already configured**, so a client certificate set earlier on the same config survives the call. 3. Initialises the context with a hand-written `X509TrustManager` whose `checkServerTrusted` and `checkClientTrusted` bodies are **empty** and whose `getAcceptedIssuers()` returns `null`. 4. Wraps that context in an Apache `SSLSocketFactory` created with `ALLOW_ALL_HOSTNAME_VERIFIER` and stores it through `SSLConfig.sslSocketFactory(...)`. ## The two checks it removes An HTTPS client asks two independent questions before it trusts the peer, and relaxed validation answers both with an unconditional yes: - **Is this certificate chain one I trust?** An empty `checkServerTrusted` accepts every chain that arrives — self-signed, expired, or issued by an authority nobody in your organisation knows. - **Was this certificate issued for the host I dialled?** `ALLOW_ALL_HOSTNAME_VERIFIER` accepts a certificate whose subject reads `something-else.example` on a call to `https://orders.bakery.test/preorders`. Those two together *are* the server-identity check. With both switched off, the suite cannot distinguish the real staging bakery pre-order service from anything else able to answer on that address — a stale container, a colleague's laptop, or something interposed on the network. Say that plainly rather than softening it: relaxed validation is not a warning suppressor, it removes a security control, and the only honest reason to reach for it is a disposable test environment whose certificate you genuinely cannot fix. ## What it leaves alone The blast radius stops at the socket factory, and knowing where it stops is half the answer: - Connect and read timeouts belong to the Apache HttpClient and are untouched. - Redirect following, cookie handling, content decoding and body parsing are unchanged. - Whatever authentication scheme the request carries still runs exactly as configured. - Over a plain `http://` URI the SSL config is skipped entirely, so the call is a no-op there. ## The protocol argument `relaxedHTTPSValidation()` delegates to `relaxedHTTPSValidation(String protocol)` with `"SSL"`. That string goes straight into `SSLContext.getInstance(...)`, so it names a JSSE context, not a wire version the server has to speak. The library's own wiki shows `given().relaxedHTTPSValidation("TLS")` as the way to ask for a different one. Handing it an algorithm the runtime does not know rethrows the `NoSuchAlgorithmException` from inside the call. ## Static form versus request form The two spellings are not interchangeable, and the difference bites as soon as a key store is in play: | Call | Starts from | An existing key store | |---|---|---| | `given().relaxedHTTPSValidation()` | the request's current `SSLConfig` | kept, and loaded into a `KeyManager` | | `RestAssured.useRelaxedHTTPSValidation()` | a fresh `SSLConfig.sslConfig()` | discarded | `RestAssured.useRelaxedHTTPSValidation(protocol)` assigns `config().sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation(protocol))` — a brand-new `SSLConfig`. Anything configured on the old one, including `keyStore(...)`, `trustStore(...)` and a chosen `keystoreType`, is gone. The request-level form starts from the config already in hand, so it composes instead of replacing. ## Relaxed validation next to a trust store Setting both is a common half-measure, and it does not do what it looks like. The relaxed call ends by handing its socket factory to `SSLConfig.sslSocketFactory(...)`, whose own documentation is explicit that an assigned socket factory overrides the settings taken from a trust store, a key store and their passwords. That factory already contains the trust-all trust manager, so a `trustStore(...)` sitting beside it in the same config decides nothing at all. The two settings do not compose into something stricter. If you want your own authority honoured, remove the relaxed call rather than adding trust material around it, and reach for `sslConfig().trustStore(...).strictHostnames()` on its own. ## Keeping it contained If you must use it at all, containment is a question of where the call lives: 1. Put `relaxedHTTPSValidation()` on the individual request, or on the one `RequestSpecification` that targets the untrusted host. 2. Avoid the static assignment in a shared base class or suite-wide setup, where every later test inherits it invisibly and nobody reviewing a single file can see it. 3. Where a private authority exists, use it instead — `sslConfig().trustStore(...).strictHostnames()` keeps both checks alive while still trusting your own issuer. 4. Check in review that no production-facing target is reached with relaxed validation on, because nothing in the library will warn you and the call leaves no trace in the response.
- Does relaxed HTTPS validation change anything for a request sent over plain http?No. REST Assured only applies the `SSLConfig` when the target URI's scheme is `https` and the config has been user-configured, so on an `http://` call the relaxed socket factory is never built into the client. The call is inert rather than harmful, but it also gives you no signal that the target was not encrypted.
- You already set a key store for mutual TLS; which relaxed-validation form keeps it?The request-level `given().relaxedHTTPSValidation()`. It relaxes the `SSLConfig` the request already holds, and `SSLConfig.relaxedHTTPSValidation` loads that key store into a `KeyManager`, so the client certificate is still presented. The static `RestAssured.useRelaxedHTTPSValidation()` builds a fresh `SSLConfig` and drops the key store silently.
It is a door policy that checks neither the ID nor the guest list. Anyone who reaches the door is waved through, and the doorman never records that he stopped checking.
saying these in an interview costs you the question
- Thinks it only suppresses the expired-certificate warning
- Says hostname verification still runs after relaxed validation
- Believes it also relaxes timeouts, redirects or parsing
- Assumes it is harmless to leave on for production-facing runs
- Thinks a trust store set alongside it still decides trust