From 5c1154b537f32631d689b446c824951cb29a2e13 Mon Sep 17 00:00:00 2001 From: David An Date: Sat, 2 Dec 2023 13:58:51 -0500 Subject: [PATCH] update workbench-libs and mockserver --- project/Dependencies.scala | 10 +++++----- .../dsde/firecloud/mock/MockWorkspaceServer.scala | 7 ++++--- .../firecloud/mock/ValidEntityCopyCallback.scala | 4 ++-- .../firecloud/mock/ValidEntityDeleteCallback.scala | 10 ++++++---- .../firecloud/mock/ValidSubmissionCallback.scala | 4 ++-- .../service/PassthroughDirectivesSpec.scala | 2 +- .../service/PassthroughDirectivesSpecSupport.scala | 13 +++++++------ .../firecloud/webservice/EntityApiServiceSpec.scala | 4 ++-- .../webservice/MethodsApiServiceSpec.scala | 8 ++++---- .../webservice/WorkspaceApiServiceSpec.scala | 9 +++++++-- 10 files changed, 40 insertions(+), 31 deletions(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 6cc93301b..bfca6ca1c 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -6,7 +6,7 @@ object Dependencies { val jacksonV = "2.13.4" val jacksonHotfixV = "2.13.4.2" // for when only some of the Jackson libs have hotfix releases val nettyV = "4.1.101.Final" - val workbenchLibsHash = "084d25b" + val workbenchLibsHash = "8ccaa6d" def excludeGuava(m: ModuleID): ModuleID = m.exclude("com.google.guava", "guava") val excludeAkkaActor = ExclusionRule(organization = "com.typesafe.akka", name = "akka-actor_2.13") @@ -53,10 +53,10 @@ object Dependencies { exclude("bio.terra", "workspace-manager-client") excludeAll(excludeAkkaHttp, excludeSprayJson), excludeGuava("org.broadinstitute.dsde.workbench" %% "workbench-util" % "0.10-128901e"), - "org.broadinstitute.dsde.workbench" %% "workbench-google2" % s"0.25-$workbenchLibsHash", - "org.broadinstitute.dsde.workbench" %% "workbench-oauth2" % s"0.2-$workbenchLibsHash", + "org.broadinstitute.dsde.workbench" %% "workbench-google2" % s"0.35-$workbenchLibsHash", + "org.broadinstitute.dsde.workbench" %% "workbench-oauth2" % s"0.5-$workbenchLibsHash", "org.broadinstitute.dsde.workbench" %% "sam-client" % "0.1-ef83073", - "org.broadinstitute.dsde.workbench" %% "workbench-notifications" %s"0.3-$workbenchLibsHash", + "org.broadinstitute.dsde.workbench" %% "workbench-notifications" %s"0.6-$workbenchLibsHash", "com.typesafe.akka" %% "akka-actor" % akkaV, "com.typesafe.akka" %% "akka-slf4j" % akkaV, @@ -95,7 +95,7 @@ object Dependencies { "com.github.pathikrit" %% "better-files" % "3.9.2", "org.scalatest" %% "scalatest" % "3.2.17" % "test", - "org.mock-server" % "mockserver-netty" % "3.11" % "test", // TODO: upgrading higher causes failures, need to investigate + "org.mock-server" % "mockserver-netty" % "5.15.0" % "test", // jaxb-api needed by WorkspaceApiServiceSpec.bagitService() method "javax.xml.bind" % "jaxb-api" % "2.3.1" % "test", // provides testing mocks diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/mock/MockWorkspaceServer.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/mock/MockWorkspaceServer.scala index 28662a7da..e93599299 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/mock/MockWorkspaceServer.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/mock/MockWorkspaceServer.scala @@ -12,6 +12,7 @@ import org.mockserver.model.HttpClassCallback.callback import org.mockserver.model.HttpRequest._ import org.mockserver.model.HttpResponse._ import akka.http.scaladsl.model.StatusCodes._ +import com.google.common.net.UrlEscapers import spray.json._ /** @@ -152,7 +153,7 @@ object MockWorkspaceServer { .withHeader(authHeader) .withPath(s"${workspaceBasePath}/%s/%s/submissions" .format(mockValidWorkspace.namespace, mockValidWorkspace.name))) - .callback( + .respond( callback(). withCallbackClass("org.broadinstitute.dsde.firecloud.mock.ValidSubmissionCallback") ) @@ -163,7 +164,7 @@ object MockWorkspaceServer { .withMethod("POST") .withPath(s"${workspaceBasePath}/%s/%s/submissions/validate" .format(mockValidWorkspace.namespace, mockValidWorkspace.name))) - .callback( + .respond( callback(). withCallbackClass("org.broadinstitute.dsde.firecloud.mock.ValidSubmissionCallback") ) @@ -276,7 +277,7 @@ object MockWorkspaceServer { request() .withMethod("GET") .withPath(s"${workspaceBasePath}/%s/%s/submissions/%s/workflows/%s" - .format(mockSpacedWorkspace.namespace, mockSpacedWorkspace.name, mockValidId, mockValidId))) + .format(mockSpacedWorkspace.namespace, UrlEscapers.urlPathSegmentEscaper().escape(mockSpacedWorkspace.name), mockValidId, mockValidId))) .respond( response() .withHeaders(header) diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidEntityCopyCallback.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidEntityCopyCallback.scala index 248d2a393..61bdf8c00 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidEntityCopyCallback.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidEntityCopyCallback.scala @@ -3,13 +3,13 @@ package org.broadinstitute.dsde.firecloud.mock import org.broadinstitute.dsde.firecloud.mock.MockUtils._ import org.broadinstitute.dsde.firecloud.model.ModelJsonProtocol._ import org.broadinstitute.dsde.rawls.model.EntityCopyDefinition -import org.mockserver.mock.action.ExpectationCallback +import org.mockserver.mock.action.ExpectationResponseCallback import org.mockserver.model.HttpResponse._ import org.mockserver.model.{HttpRequest, HttpResponse} import akka.http.scaladsl.model.StatusCodes._ import spray.json._ -class ValidEntityCopyCallback extends ExpectationCallback { +class ValidEntityCopyCallback extends ExpectationResponseCallback { override def handle(httpRequest: HttpRequest): HttpResponse = { diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidEntityDeleteCallback.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidEntityDeleteCallback.scala index 3656ef34e..979200739 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidEntityDeleteCallback.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidEntityDeleteCallback.scala @@ -4,20 +4,22 @@ import org.broadinstitute.dsde.firecloud.mock.MockUtils._ import org.broadinstitute.dsde.firecloud.model.EntityId import org.broadinstitute.dsde.firecloud.model.ModelJsonProtocol._ import spray.json.DefaultJsonProtocol._ -import org.mockserver.mock.action.ExpectationCallback +import org.mockserver.mock.action.ExpectationResponseCallback import org.mockserver.model.HttpResponse._ import org.mockserver.model.{HttpRequest, HttpResponse} import akka.http.scaladsl.model.StatusCodes._ import spray.json._ -class ValidEntityDeleteCallback extends ExpectationCallback { +import scala.util.Try + +class ValidEntityDeleteCallback extends ExpectationResponseCallback { val validEntities = Set(EntityId("sample", "id"), EntityId("sample", "bar")) override def handle(httpRequest: HttpRequest): HttpResponse = { - val deleteRequest = httpRequest.getBodyAsString.parseJson.convertTo[Set[EntityId]] + val deleteRequest = Try(httpRequest.getBodyAsString.parseJson.convertTo[Set[EntityId]]) - if (deleteRequest.subsetOf(validEntities)) { + if (deleteRequest.isSuccess && deleteRequest.get.subsetOf(validEntities)) { response() .withHeaders(header) .withStatusCode(NoContent.intValue) diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidSubmissionCallback.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidSubmissionCallback.scala index 555faee96..570282151 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidSubmissionCallback.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/mock/ValidSubmissionCallback.scala @@ -3,13 +3,13 @@ package org.broadinstitute.dsde.firecloud.mock import org.broadinstitute.dsde.firecloud.mock.MockUtils._ import org.broadinstitute.dsde.firecloud.model.ModelJsonProtocol._ import org.broadinstitute.dsde.firecloud.model.OrchSubmissionRequest -import org.mockserver.mock.action.ExpectationCallback +import org.mockserver.mock.action.ExpectationResponseCallback import org.mockserver.model.HttpResponse._ import org.mockserver.model.{HttpRequest, HttpResponse} import akka.http.scaladsl.model.StatusCodes._ import spray.json._ -class ValidSubmissionCallback extends ExpectationCallback { +class ValidSubmissionCallback extends ExpectationResponseCallback { override def handle(httpRequest: HttpRequest): HttpResponse = { diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/service/PassthroughDirectivesSpec.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/service/PassthroughDirectivesSpec.scala index 4aa482452..f06a8f303 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/service/PassthroughDirectivesSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/service/PassthroughDirectivesSpec.scala @@ -28,7 +28,7 @@ final class PassthroughDirectivesSpec extends BaseServiceSpec with FireCloudDire override def beforeAll() = { echoServer = startClientAndServer(echoPort) echoServer.when(request()) - .callback( + .respond( callback(). withCallbackClass("org.broadinstitute.dsde.firecloud.service.EchoCallback")) } diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/service/PassthroughDirectivesSpecSupport.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/service/PassthroughDirectivesSpecSupport.scala index 0c9af4285..63c341f30 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/service/PassthroughDirectivesSpecSupport.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/service/PassthroughDirectivesSpecSupport.scala @@ -3,7 +3,7 @@ package org.broadinstitute.dsde.firecloud.service import org.broadinstitute.dsde.firecloud.mock.MockUtils import org.broadinstitute.dsde.firecloud.service.PassthroughDirectivesSpec._ import org.broadinstitute.dsde.firecloud.service.PassthroughDirectivesSpecSupport._ -import org.mockserver.mock.action.ExpectationCallback +import org.mockserver.mock.action.ExpectationResponseCallback import org.mockserver.model.{HttpRequest, HttpResponse} import akka.http.scaladsl.model.StatusCodes.OK import akka.http.scaladsl.model.Uri @@ -12,16 +12,17 @@ import spray.json.DefaultJsonProtocol._ import scala.jdk.CollectionConverters._ -class EchoCallback extends ExpectationCallback { +class EchoCallback extends ExpectationResponseCallback { override def handle(httpRequest: HttpRequest): HttpResponse = { // translate the mockserver request to a spray Uri - val sprayparams = httpRequest.getQueryStringParameters.asScala.map{p => - assert(p.getValues.size() <= 1) - p.getName.getValue -> p.getValues.asScala.head.getValue}.toMap + val query: Query = Option(httpRequest.getQueryStringParameters) match { + case None => Query.Empty + case Some(params) => Query(params.getRawParameterString) + } val sprayuri = Uri(echoUrl) .withPath(Path(httpRequest.getPath.getValue)) - .withQuery(Query(sprayparams)) + .withQuery(query) val requestInfo = RequestInfo( httpRequest.getMethod.getValue, diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/EntityApiServiceSpec.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/EntityApiServiceSpec.scala index db53fdd85..5b2a214aa 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/EntityApiServiceSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/EntityApiServiceSpec.scala @@ -103,7 +103,7 @@ class EntityApiServiceSpec extends BaseServiceSpec with EntityApiService with Sp request() .withMethod("POST") .withPath(FireCloudConfig.Rawls.authPrefix + FireCloudConfig.Rawls.workspacesEntitiesCopyPath)) - .callback( + .respond( callback(). withCallbackClass("org.broadinstitute.dsde.firecloud.mock.ValidEntityCopyCallback") ) @@ -138,7 +138,7 @@ class EntityApiServiceSpec extends BaseServiceSpec with EntityApiService with Sp request() .withMethod("POST") .withPath(FireCloudConfig.Rawls.authPrefix + FireCloudConfig.Rawls.entitiesPath.format("broad-dsde-dev", "valid") + "/delete")) - .callback( + .respond( callback(). withCallbackClass("org.broadinstitute.dsde.firecloud.mock.ValidEntityDeleteCallback") ) diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/MethodsApiServiceSpec.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/MethodsApiServiceSpec.scala index 331203748..d3a5b8d46 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/MethodsApiServiceSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/MethodsApiServiceSpec.scala @@ -8,7 +8,7 @@ import org.broadinstitute.dsde.firecloud.mock.MockUtils import org.broadinstitute.dsde.firecloud.service.{AgoraPermissionService, BaseServiceSpec, ServiceSpec} import org.mockserver.integration.ClientAndServer import org.mockserver.integration.ClientAndServer._ -import org.mockserver.mock.action.ExpectationCallback +import org.mockserver.mock.action.ExpectationResponseCallback import org.mockserver.model.HttpClassCallback.callback import org.mockserver.model.HttpRequest._ import org.mockserver.model.HttpResponse.response @@ -81,7 +81,7 @@ final class MethodsApiServiceSpec extends BaseServiceSpec with ServiceSpec with testCases foreach { api => methodsServer .when(request().withMethod(api.verb.name).withPath(api.remotePath)) - .callback(callback().withCallbackClass("org.broadinstitute.dsde.firecloud.webservice.MethodsApiServiceSpecCallback")) + .respond(callback().withCallbackClass("org.broadinstitute.dsde.firecloud.webservice.MethodsApiServiceSpecCallback")) } } @@ -128,11 +128,11 @@ final class MethodsApiServiceSpec extends BaseServiceSpec with ServiceSpec with } } -final class MethodsApiServiceSpecCallback extends ExpectationCallback { +final class MethodsApiServiceSpecCallback extends ExpectationResponseCallback { override def handle(httpRequest: HttpRequest): HttpResponse = { val method:String = httpRequest.getMethod.getValue val path:String = httpRequest.getPath.getValue - val hasParams:Boolean = !httpRequest.getQueryStringParameters.isEmpty + val hasParams:Boolean = !httpRequest.getQueryStringParameterList.isEmpty val content = s"$method $path $hasParams" diff --git a/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/WorkspaceApiServiceSpec.scala b/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/WorkspaceApiServiceSpec.scala index c05a1b50c..1afe14f35 100644 --- a/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/WorkspaceApiServiceSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/firecloud/webservice/WorkspaceApiServiceSpec.scala @@ -20,11 +20,14 @@ import org.broadinstitute.dsde.firecloud.{EntityService, FireCloudConfig} import org.broadinstitute.dsde.rawls.model.WorkspaceACLJsonSupport._ import org.broadinstitute.dsde.rawls.model._ import org.joda.time.DateTime +import org.mockserver.configuration.Configuration import org.mockserver.integration.ClientAndServer import org.mockserver.integration.ClientAndServer._ +import org.mockserver.logging.MockServerLogger import org.mockserver.model.HttpRequest._ import org.mockserver.model.Parameter -import org.mockserver.socket.KeyStoreFactory +import org.mockserver.socket.tls.KeyStoreFactory +//import org.mockserver.socket.KeyStoreFactory import org.scalatest.BeforeAndAfterEach import spray.json.DefaultJsonProtocol._ import spray.json._ @@ -299,7 +302,9 @@ class WorkspaceApiServiceSpec extends BaseServiceSpec with WorkspaceApiService w ) // bagit import requires https urls; set up SSL - HttpsURLConnection.setDefaultSSLSocketFactory(KeyStoreFactory.keyStoreFactory().sslContext().getSocketFactory()) + HttpsURLConnection.setDefaultSSLSocketFactory(new KeyStoreFactory( + Configuration.configuration(), + new MockServerLogger()).sslContext().getSocketFactory) // set up mockserver for all paths defined above mappings.foreach { entry =>