From 49aec2892935cc0fb84173fd53ef7afa3b7a37da Mon Sep 17 00:00:00 2001 From: Victor Arbues Date: Tue, 7 Jan 2025 09:29:06 +0000 Subject: [PATCH] HIPP-1810: Remove OAS title validation (#501) --- app/connectors/ApplicationsConnector.scala | 3 +-- .../ProduceApiEnterOasController.scala | 2 +- .../ApplicationsConnectorSpec.scala | 26 +++---------------- .../ProduceApiEnterOasControllerSpec.scala | 10 +++---- .../UpdateApiEnterOasControllerSpec.scala | 10 +++---- 5 files changed, 15 insertions(+), 36 deletions(-) diff --git a/app/connectors/ApplicationsConnector.scala b/app/connectors/ApplicationsConnector.scala index 29e92c00..ec1c0b73 100644 --- a/app/connectors/ApplicationsConnector.scala +++ b/app/connectors/ApplicationsConnector.scala @@ -550,9 +550,8 @@ class ApplicationsConnector @Inject()( .execute[ApisInProductionStatistic] } - def validateOAS(oas: String, validateTitle: Boolean = false) + def validateOAS(oas: String) (implicit hc: HeaderCarrier, messagesProvider: MessagesProvider): Future[Either[InvalidOasResponse, Unit]] = httpClient.post(url"$applicationsBaseUrl/api-hub-applications/oas/validate") - .transform(request => request.withQueryStringParameters("validateTitle" -> validateTitle.toString)) .setHeader(ACCEPT -> JSON) .setHeader(CONTENT_TYPE -> "text/plain") .setHeader(AUTHORIZATION -> clientAuthToken) diff --git a/app/controllers/myapis/produce/ProduceApiEnterOasController.scala b/app/controllers/myapis/produce/ProduceApiEnterOasController.scala index b3fadac9..7ed30c1b 100644 --- a/app/controllers/myapis/produce/ProduceApiEnterOasController.scala +++ b/app/controllers/myapis/produce/ProduceApiEnterOasController.scala @@ -108,7 +108,7 @@ class ProduceApiEnterOasController @Inject()( private def validateOAS(oas: String)(implicit messagesProvider: MessagesProvider, hc: HeaderCarrier): Future[Either[String, String]] = { (for { - _ <- EitherT(applicationsConnector.validateOAS(oas, true)).leftMap(error => Json.prettyPrint(Json.toJson(error))) + _ <- EitherT(applicationsConnector.validateOAS(oas)).leftMap(error => Json.prettyPrint(Json.toJson(error))) openApiDoc <- EitherT.fromEither(OpenApiDoc.parse(oas)) apiName <- EitherT.fromOption(openApiDoc.getApiName(), Messages("produceApiEnterOas.error.missingApiName")) } yield apiName).value diff --git a/it/test/connectors/ApplicationsConnectorSpec.scala b/it/test/connectors/ApplicationsConnectorSpec.scala index 8946ca1f..a39da8c0 100644 --- a/it/test/connectors/ApplicationsConnectorSpec.scala +++ b/it/test/connectors/ApplicationsConnectorSpec.scala @@ -1837,10 +1837,9 @@ class ApplicationsConnectorSpec } "validateOas" - { - "must place the correct request and return success and not validate the oas title" in { + "must place the correct request and return success" in { val oas = "some oas" - val validateTitle = false - val value1 = s"/api-hub-applications/oas/validate?validateTitle=$validateTitle" + val value1 = s"/api-hub-applications/oas/validate" Console.println(s"OIYAF! $value1") stubFor( post(urlEqualTo(value1)) @@ -1852,26 +1851,7 @@ class ApplicationsConnectorSpec ) ) - buildConnector(this).validateOAS(oas, validateTitle)(HeaderCarrier()).map { - result => - result.value mustBe() - } - } - - "must place the correct request and return success and validate the oas title" in { - val oas = "some oas" - val validateTitle = true - stubFor( - post(urlEqualTo(s"/api-hub-applications/oas/validate?validateTitle=$validateTitle")) - .withHeader(AUTHORIZATION, equalTo("An authentication token")) - .withHeader(ACCEPT, equalTo("application/json")) - .withRequestBody(equalTo(oas)) - .willReturn( - aResponse() - ) - ) - - buildConnector(this).validateOAS(oas, validateTitle)(HeaderCarrier()).map { + buildConnector(this).validateOAS(oas)(HeaderCarrier()).map { result => result.value mustBe() } diff --git a/test/controllers/myapis/produce/ProduceApiEnterOasControllerSpec.scala b/test/controllers/myapis/produce/ProduceApiEnterOasControllerSpec.scala index 95e21d89..945bda06 100644 --- a/test/controllers/myapis/produce/ProduceApiEnterOasControllerSpec.scala +++ b/test/controllers/myapis/produce/ProduceApiEnterOasControllerSpec.scala @@ -118,7 +118,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar { "must redirect to the next page when valid data is submitted" in { val fixture = buildFixture(userAnswers = Some(emptyUserAnswers)) when(fixture.sessionRepository.set(any())).thenReturn(Future.successful(true)) - when(fixture.applicationsConnector.validateOAS(eqTo(validOAS), eqTo(true))(any, any)) + when(fixture.applicationsConnector.validateOAS(eqTo(validOAS))(any, any)) .thenReturn(Future.successful(Right(()))) running(fixture.application) { @@ -139,7 +139,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar { val errorMessage = "Unable to parse the OAS document, errorMessage" val invalidResponse = InvalidOasResponse(FailuresResponse("400", errorMessage, None)) val fixture = buildFixture(userAnswers = Some(emptyUserAnswers)) - when(fixture.applicationsConnector.validateOAS(eqTo(invalidOAS), eqTo(true))(any, any)) + when(fixture.applicationsConnector.validateOAS(eqTo(invalidOAS))(any, any)) .thenReturn(Future.successful(Left( invalidResponse ))) @@ -196,7 +196,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar { val userAnswers = emptyUserAnswers.set(ProduceApiUploadOasPage, oasModel).success.value val fixture = buildFixture(userAnswers = Some(userAnswers)) - when(fixture.applicationsConnector.validateOAS(eqTo(oasModel.fileContents), eqTo(true))(any, any)) + when(fixture.applicationsConnector.validateOAS(eqTo(oasModel.fileContents))(any, any)) .thenReturn(Future.successful(Right(()))) running(fixture.application) { @@ -220,7 +220,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar { val fixture = buildFixture(userAnswers = Some(userAnswers)) - when(fixture.applicationsConnector.validateOAS(eqTo(validOASEdited), eqTo(true))(any, any)) + when(fixture.applicationsConnector.validateOAS(eqTo(validOASEdited))(any, any)) .thenReturn(Future.successful(Right(()))) running(fixture.application) { @@ -241,7 +241,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar { val fixture = buildFixture(userAnswers = Some(userAnswers)) val invalidResponse = InvalidOasResponse(FailuresResponse("400", "nope", None)) - when(fixture.applicationsConnector.validateOAS(any(), eqTo(true))(any, any)).thenReturn(Future.successful(Left(invalidResponse))) + when(fixture.applicationsConnector.validateOAS(any())(any, any)).thenReturn(Future.successful(Left(invalidResponse))) running(fixture.application) { val request = FakeRequest(GET, controllers.myapis.produce.routes.ProduceApiEnterOasController.onPageLoadWithUploadedOas(NormalMode).url) diff --git a/test/controllers/myapis/update/UpdateApiEnterOasControllerSpec.scala b/test/controllers/myapis/update/UpdateApiEnterOasControllerSpec.scala index a2c6a59c..7416f354 100644 --- a/test/controllers/myapis/update/UpdateApiEnterOasControllerSpec.scala +++ b/test/controllers/myapis/update/UpdateApiEnterOasControllerSpec.scala @@ -120,7 +120,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar { "must redirect to the next page when valid data is submitted" in { val fixture = buildFixture(userAnswers = Some(emptyUserAnswers)) when(fixture.sessionRepository.set(any())).thenReturn(Future.successful(true)) - when(fixture.applicationsConnector.validateOAS(eqTo(validOAS), eqTo(false))(any, any)) + when(fixture.applicationsConnector.validateOAS(eqTo(validOAS))(any, any)) .thenReturn(Future.successful(Right(()))) running(fixture.application) { @@ -141,7 +141,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar { val errorMessage = "Unable to parse the OAS document, errorMessage" val invalidResponse = InvalidOasResponse(FailuresResponse("400", errorMessage, None)) val fixture = buildFixture(userAnswers = Some(emptyUserAnswers)) - when(fixture.applicationsConnector.validateOAS(eqTo(invalidOAS), eqTo(false))(any, any)) + when(fixture.applicationsConnector.validateOAS(eqTo(invalidOAS))(any, any)) .thenReturn(Future.successful(Left( invalidResponse ))) @@ -198,7 +198,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar { val userAnswers = emptyUserAnswers.set(UpdateApiUploadOasPage, oasModel).success.value val fixture = buildFixture(userAnswers = Some(userAnswers)) - when(fixture.applicationsConnector.validateOAS(eqTo(oasModel.fileContents), eqTo(false))(any, any)) + when(fixture.applicationsConnector.validateOAS(eqTo(oasModel.fileContents))(any, any)) .thenReturn(Future.successful(Right(()))) running(fixture.application) { @@ -222,7 +222,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar { val fixture = buildFixture(userAnswers = Some(userAnswers)) - when(fixture.applicationsConnector.validateOAS(eqTo(validOASEdited), eqTo(false))(any, any)) + when(fixture.applicationsConnector.validateOAS(eqTo(validOASEdited))(any, any)) .thenReturn(Future.successful(Right(()))) running(fixture.application) { @@ -243,7 +243,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar { val fixture = buildFixture(userAnswers = Some(userAnswers)) val invalidResponse = InvalidOasResponse(FailuresResponse("400", "nope", None)) - when(fixture.applicationsConnector.validateOAS(any(), any())(any, any)).thenReturn(Future.successful(Left(invalidResponse))) + when(fixture.applicationsConnector.validateOAS(any())(any, any)).thenReturn(Future.successful(Left(invalidResponse))) running(fixture.application) { val request = FakeRequest(GET, controllers.myapis.update.routes.UpdateApiEnterOasController.onPageLoadWithUploadedOas(NormalMode).url)