test/added tests for consumers

This commit is contained in:
hongwei 2024-11-08 12:55:15 +01:00
parent 27eb2ecfa2
commit d330c4061d
4 changed files with 214 additions and 5 deletions

View File

@ -2713,6 +2713,19 @@ object SwaggerDefinitionsJSON {
created = DateWithDayExampleObject,
logo_url = Some("www.openbankproject.com/logo")
)
val createConsumerRequestJsonV510 = CreateConsumerRequestJsonV510(
appNameExample.value,
appTypeExample.value,
descriptionExample.value,
emailExample.value,
companyExample.value,
redirectUrlExample.value,
userIdExample.value,
true,
DateWithMsExampleObject,
clientCertificateExample.value,
Some(logoURLExample.value)
)
val consumersJson = ConsumersJson(
list = List(consumerJSON)

View File

@ -653,7 +653,7 @@ object ExampleValue {
lazy val challengeExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("challenge", challengeExample)
lazy val appNameExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
lazy val appNameExample = ConnectorField("appNameBank",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("app_name", appNameExample)
lazy val executionDateExample = ConnectorField("2020-01-27",NoDescriptionProvided)
@ -1308,7 +1308,7 @@ object ExampleValue {
lazy val inviteesExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("invitees", inviteesExample)
lazy val appTypeExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
lazy val appTypeExample = ConnectorField("Web",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("app_type", appTypeExample)
lazy val productAttributeIdExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
@ -1825,8 +1825,17 @@ object ExampleValue {
lazy val purposeExample = ConnectorField(UserInvitationPurpose.DEVELOPER.toString, NoDescriptionProvided)
glossaryItems += makeGlossaryItem("purpose", purposeExample)
lazy val redirectUrlExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
lazy val redirectUrlExample = ConnectorField("https://apisandbox.openbankproject.com",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("redirect_url", redirectUrlExample)
lazy val logoURLExample = ConnectorField("https://apisandbox.openbankproject.com/logo",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("logo_url", logoURLExample)
lazy val clientCertificateExample = ConnectorField( """-----BEGIN CERTIFICATE-----
|client_certificate_content
|-----END CERTIFICATE-----""".stripMargin,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("client_certificate", clientCertificateExample)
lazy val roleExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("role", roleExample)
@ -2272,7 +2281,7 @@ object ExampleValue {
lazy val indexExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("index", indexExample)
lazy val descriptionExample = ConnectorField(s"This an optional field. Maximum length is ${ApiCollection.Description.maxLen}. It can be any characters here.","The human readable description here.")
lazy val descriptionExample = ConnectorField(s"Description of the object. Maximum length is ${ApiCollection.Description.maxLen}. It can be any characters here.","The human readable description here.")
glossaryItems += makeGlossaryItem("description", descriptionExample)
lazy val paymentServiceExample = ConnectorField("payments", s"The berlin group payment services, eg: payments, periodic-payments and bulk-payments. ")

View File

@ -5257,7 +5257,7 @@ trait APIMethods400 extends MdcLoggable {
|""",
ConsumerPostJSON(
"Test",
"Test",
"Web",
"Description",
"some@email.com",
"redirecturl",

View File

@ -0,0 +1,187 @@
/**
Open Bank Project - API
Copyright (C) 2011-2019, TESOBE GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Email: contact@tesobe.com
TESOBE GmbH
Osloerstrasse 16/17
Berlin 13359, Germany
This product includes software developed at
TESOBE (http://www.tesobe.com/)
*/
package code.api.v5_1_0
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.util.APIUtil.OAuth._
import code.api.util.ApiRole.{canCreateConsumer, canGetConsumers, canUpdateConsumerLogoUrl, canUpdateConsumerRedirectUrl}
import code.api.util.ErrorMessages.{InvalidJsonFormat, 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.util.ApiVersion
import net.liftweb.json.Serialization.write
import org.scalatest.Tag
class ConsumerTest 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.createConsumer))
object ApiEndpoint2 extends Tag(nameOf(Implementations5_1_0.getConsumers))
object ApiEndpoint3 extends Tag(nameOf(Implementations5_1_0.updateConsumerRedirectURL))
object ApiEndpoint4 extends Tag(nameOf(Implementations5_1_0.updateConsumerLogoURL))
feature("Test all error cases ") {
scenario("We test the authentication errors", ApiEndpoint1, ApiEndpoint2, ApiEndpoint3, ApiEndpoint4, VersionOfApi) {
When("We make a request v5.1.0")
lazy val postApiCollectionJson = SwaggerDefinitionsJSON.postApiCollectionJson400
val requestApiEndpoint1 = (v5_1_0_Request / "management" / "consumers").POST
val responseApiEndpoint1 = makePostRequest(requestApiEndpoint1, write(postApiCollectionJson))
val requestApiEndpoint2 = (v5_1_0_Request / "management" / "consumers").GET
val responseApiEndpoint2 = makePostRequest(requestApiEndpoint2, write(postApiCollectionJson))
val requestApiEndpoint3= (v5_1_0_Request / "management" / "consumers" / "CONSUMER_ID" / "consumer" / "redirect_url").PUT
val responseApiEndpoint3 = makePutRequest(requestApiEndpoint3, write(postApiCollectionJson))
val requestApiEndpoint4 = (v5_1_0_Request /"management" / "consumers" / "CONSUMER_ID" / "consumer" / "logo_url").PUT
val responseApiEndpoint4 = makePutRequest(requestApiEndpoint4, write(postApiCollectionJson))
Then(s"we should get the error messages")
responseApiEndpoint1.code should equal(401)
responseApiEndpoint2.code should equal(401)
responseApiEndpoint3.code should equal(401)
responseApiEndpoint4.code should equal(401)
responseApiEndpoint1.body.toString contains(s"$UserNotLoggedIn") should be (true)
responseApiEndpoint2.body.toString contains(s"$UserNotLoggedIn") should be (true)
responseApiEndpoint3.body.toString contains(s"$UserNotLoggedIn") should be (true)
responseApiEndpoint4.body.toString contains(s"$UserNotLoggedIn") should be (true)
}
scenario("We test the missing roles errors", ApiEndpoint1, ApiEndpoint2, ApiEndpoint3, ApiEndpoint4, VersionOfApi) {
When("We make a request v5.1.0")
lazy val wrongJsonForTesting = SwaggerDefinitionsJSON.routing
val requestApiEndpoint1 = (v5_1_0_Request / "management" / "consumers").POST<@ (user1)
val responseApiEndpoint1 = makePostRequest(requestApiEndpoint1, write(wrongJsonForTesting))
val requestApiEndpoint2 = (v5_1_0_Request / "management" / "consumers").GET <@ (user1)
val responseApiEndpoint2 = makeGetRequest(requestApiEndpoint2)
val requestApiEndpoint3= (v5_1_0_Request / "management" / "consumers" / "CONSUMER_ID" / "consumer" / "redirect_url").PUT<@ (user1)
val responseApiEndpoint3 = makePutRequest(requestApiEndpoint3, write(wrongJsonForTesting))
val requestApiEndpoint4 = (v5_1_0_Request /"management" / "consumers" / "CONSUMER_ID" / "consumer" / "logo_url").PUT<@ (user1)
val responseApiEndpoint4 = makePutRequest(requestApiEndpoint4, write(wrongJsonForTesting))
Then(s"we should get the error messages")
responseApiEndpoint1.code should equal(403)
responseApiEndpoint1.body.toString contains(s"$canCreateConsumer") should be (true)
responseApiEndpoint2.code should equal(403)
responseApiEndpoint2.body.toString contains(s"$canGetConsumers") should be (true)
responseApiEndpoint3.code should equal(403)
responseApiEndpoint3.body.toString contains(s"$canUpdateConsumerRedirectUrl") should be (true)
responseApiEndpoint4.code should equal(403)
responseApiEndpoint4.body.toString contains(s"$canUpdateConsumerLogoUrl") should be (true)
}
scenario("We added the proper roles, but wrong json", ApiEndpoint1, ApiEndpoint2, ApiEndpoint3, ApiEndpoint4, VersionOfApi) {
When("we first grant the missing roles:")
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, canCreateConsumer.toString)
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, canUpdateConsumerLogoUrl.toString)
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, canUpdateConsumerRedirectUrl.toString)
When("We make a request v5.1.0")
lazy val wrongJsonForTesting = SwaggerDefinitionsJSON.postApiCollectionJson400
val requestApiEndpoint1 = (v5_1_0_Request / "management" / "consumers").POST<@ (user1)
val responseApiEndpoint1 = makePostRequest(requestApiEndpoint1, write(wrongJsonForTesting))
val requestApiEndpoint3= (v5_1_0_Request / "management" / "consumers" / "CONSUMER_ID" / "consumer" / "redirect_url").PUT<@ (user1)
val responseApiEndpoint3 = makePutRequest(requestApiEndpoint3, write(wrongJsonForTesting))
val requestApiEndpoint4 = (v5_1_0_Request /"management" / "consumers" / "CONSUMER_ID" / "consumer" / "logo_url").PUT<@ (user1)
val responseApiEndpoint4 = makePutRequest(requestApiEndpoint4, write(wrongJsonForTesting))
Then(s"we should get the error messages")
responseApiEndpoint1.code should equal(400)
responseApiEndpoint1.body.toString contains(s"$InvalidJsonFormat") should be (true)
responseApiEndpoint3.code should equal(400)
responseApiEndpoint3.body.toString contains(s"$InvalidJsonFormat") should be (true)
responseApiEndpoint4.code should equal(400)
responseApiEndpoint4.body.toString contains(s"$InvalidJsonFormat") should be (true)
}
}
feature(s"test all successful cases") {
scenario("we create, update and get consumers", ApiEndpoint1, ApiEndpoint2, ApiEndpoint3, ApiEndpoint4, VersionOfApi) {
When("we first grant the missing roles:")
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, canCreateConsumer.toString)
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, canGetConsumers.toString)
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, canUpdateConsumerLogoUrl.toString)
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, canUpdateConsumerRedirectUrl.toString)
lazy val createConsumerRequestJsonV510 = SwaggerDefinitionsJSON.createConsumerRequestJsonV510
lazy val consumerRedirectUrlJSON = SwaggerDefinitionsJSON.consumerRedirectUrlJSON
lazy val consumerLogoUrlJson = SwaggerDefinitionsJSON.consumerLogoUrlJson
val requestApiEndpoint1 = (v5_1_0_Request / "management" / "consumers").POST<@ (user1)
val responseApiEndpoint1 = makePostRequest(requestApiEndpoint1, write(createConsumerRequestJsonV510))
val consumerId = responseApiEndpoint1.body.extract[ConsumerJsonV510].consumer_id
val requestApiEndpoint2 = (v5_1_0_Request / "management" / "consumers").GET <@ (user1)
val responseApiEndpoint2 = makeGetRequest(requestApiEndpoint2)
val requestApiEndpoint3= (v5_1_0_Request / "management" / "consumers" / consumerId / "consumer" / "redirect_url").PUT<@ (user1)
val responseApiEndpoint3 = makePutRequest(requestApiEndpoint3, write(consumerRedirectUrlJSON))
val redirectUrl = responseApiEndpoint3.body.extract[ConsumerJsonV510].redirect_url
redirectUrl shouldBe(consumerRedirectUrlJSON.redirect_url)
val requestApiEndpoint4 = (v5_1_0_Request /"management" / "consumers" / consumerId / "consumer" / "logo_url").PUT<@ (user1)
val responseApiEndpoint4 = makePutRequest(requestApiEndpoint4, write(consumerLogoUrlJson))
val logoUrl = responseApiEndpoint4.body.extract[ConsumerJsonV510].logo_url
logoUrl.head shouldBe(consumerLogoUrlJson.logo_url)
Then(s"we should get the error messages")
responseApiEndpoint1.code should equal(201)
responseApiEndpoint2.code should equal(200)
responseApiEndpoint3.code should equal(200)
responseApiEndpoint4.code should equal(200)
Then("we try to get the consumers and check it ")
{
val requestApiEndpoint2 = (v5_1_0_Request / "management" / "consumers").GET <@ (user1)
val responseApiEndpoint2 = makeGetRequest(requestApiEndpoint2)
val consumers = responseApiEndpoint2.body.extract[ConsumersJsonV510].consumers
consumers.find(_.consumer_id ==consumerId).head.redirect_url shouldBe(consumerRedirectUrlJSON.redirect_url)
consumers.find(_.consumer_id ==consumerId).head.logo_url.head shouldBe(consumerLogoUrlJson.logo_url)
}
}
}
}