From 3f9e3ee7979134675830eb308699458797f501b9 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Thu, 21 Dec 2023 10:53:36 +0100 Subject: [PATCH 1/2] Fallback to https port --- .../main/scala/org/scalatestplus/play/ServerProvider.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/src/main/scala/org/scalatestplus/play/ServerProvider.scala b/module/src/main/scala/org/scalatestplus/play/ServerProvider.scala index 676dedb0..2b8a960b 100644 --- a/module/src/main/scala/org/scalatestplus/play/ServerProvider.scala +++ b/module/src/main/scala/org/scalatestplus/play/ServerProvider.scala @@ -55,9 +55,9 @@ trait ServerProvider { * @return the configured port number, wrapped in a `PortNumber` */ implicit def portNumber: PortNumber = { - val httpEndpoint = runningServer.endpoints.httpEndpoint - val port = httpEndpoint - .fold(throw new IllegalStateException("No HTTP port available for test server"))(_.port) + val port = runningServer.endpoints.httpEndpoint + .orElse(runningServer.endpoints.httpsEndpoint) + .fold(throw new IllegalStateException("Nor HTTP or HTTPS port available for test server"))(_.port) PortNumber(port) } } From 63226789c6c262d6d39921a7aee62b7c61e4cecc Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Thu, 21 Dec 2023 10:55:07 +0100 Subject: [PATCH 2/2] Support https urls --- .../scalatestplus/play/WsScalaTestClient.scala | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/module/src/main/scala/org/scalatestplus/play/WsScalaTestClient.scala b/module/src/main/scala/org/scalatestplus/play/WsScalaTestClient.scala index a09b350a..d0f00ebe 100644 --- a/module/src/main/scala/org/scalatestplus/play/WsScalaTestClient.scala +++ b/module/src/main/scala/org/scalatestplus/play/WsScalaTestClient.scala @@ -50,7 +50,18 @@ trait WsScalaTestClient { def wsUrl(url: String)(implicit portNumber: PortNumber, wsClient: WSClient): WSRequest = doCall(url, wsClient, portNumber) - private def doCall(url: String, wsClient: WSClient, portNumber: PortNumber) = { - wsClient.url("http://localhost:" + portNumber.value + url) + /** + * Construct a WS request for the given relative URL. + * + * @param url the URL of the request + * @param secure if the request should be send via https + * @param portNumber the port number of the `TestServer` + * @param wsClient the implicit WSClient + */ + def wsUrl(url: String, secure: Boolean)(implicit portNumber: PortNumber, wsClient: WSClient): WSRequest = + doCall(url, wsClient, portNumber, secure) + + private def doCall(url: String, wsClient: WSClient, portNumber: PortNumber, secure: Boolean = false) = { + wsClient.url((if (secure) "https" else "http") + "://localhost:" + portNumber.value + url) } }