From 26fe2ae680fc751c4922471a8ecb02d3bc3a9104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Mon, 13 Mar 2023 09:47:43 +0100 Subject: [PATCH] test/Add tests for endpoint customViewNamesCheck v5.1.0 --- .../code/api/v5_1_0/SystemIntegrityTest.scala | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 obp-api/src/test/scala/code/api/v5_1_0/SystemIntegrityTest.scala diff --git a/obp-api/src/test/scala/code/api/v5_1_0/SystemIntegrityTest.scala b/obp-api/src/test/scala/code/api/v5_1_0/SystemIntegrityTest.scala new file mode 100644 index 000000000..ebb49e801 --- /dev/null +++ b/obp-api/src/test/scala/code/api/v5_1_0/SystemIntegrityTest.scala @@ -0,0 +1,58 @@ +package code.api.v5_1_0 + +import code.api.util.APIUtil.OAuth._ +import code.api.util.ApiRole.CanGetSystemIntegrity +import code.api.util.ErrorMessages.{UserHasMissingRoles, UserNotLoggedIn} +import code.api.v5_1_0.OBPAPI5_1_0.Implementations5_1_0 +import code.entitlement.Entitlement +import com.github.dwickern.macros.NameOf.nameOf +import com.openbankproject.commons.model.ErrorMessage +import com.openbankproject.commons.util.ApiVersion +import org.scalatest.Tag + +class SystemIntegrityTest extends V510ServerSetup { + /** + * Test tags + * Example: To run tests with tag "getPermissions": + * mvn test -D tagsToInclude + * + * This is made possible by the scalatest maven plugin + */ + object VersionOfApi extends Tag(ApiVersion.v5_1_0.toString) + object ApiEndpoint1 extends Tag(nameOf(Implementations5_1_0.customViewNamesCheck)) + + feature(s"test $ApiEndpoint1 version $VersionOfApi - Unauthorized access") { + scenario("We will call the endpoint without user credentials", ApiEndpoint1, VersionOfApi) { + When("We make a request v5.1.0") + val request510 = (v5_1_0_Request / "management" / "system" / "integrity" / "custom-view-names-check").GET + val response510 = makeGetRequest(request510) + Then("We should get a 401") + response510.code should equal(401) + response510.body.extract[ErrorMessage].message should equal(UserNotLoggedIn) + } + } + + feature(s"test $ApiEndpoint1 version $VersionOfApi - Authorized access") { + scenario("We will call the endpoint with user credentials but without a proper entitlement", ApiEndpoint1, VersionOfApi) { + When("We make a request v5.1.0") + val request510 = (v5_1_0_Request / "management" / "system" / "integrity" / "custom-view-names-check").GET <@(user1) + val response510 = makeGetRequest(request510) + Then("error should be " + UserHasMissingRoles + CanGetSystemIntegrity) + response510.code should equal(403) + response510.body.extract[ErrorMessage].message should be (UserHasMissingRoles + CanGetSystemIntegrity) + } + } + + feature(s"test $ApiEndpoint1 version $VersionOfApi - Authorized access") { + scenario("We will call the endpoint with user credentials and a proper entitlement", ApiEndpoint1, VersionOfApi) { + Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, CanGetSystemIntegrity.toString) + When("We make a request v5.1.0") + val request510 = (v5_1_0_Request / "management" / "system" / "integrity" / "custom-view-names-check").GET <@(user1) + val response510 = makeGetRequest(request510) + Then("We get successful response") + response510.code should equal(200) + response510.body.extract[CheckSystemIntegrityJsonV510] + } + } + +}