SAP-samples / btp-cap-multitenant-saas

Sample project that demonstrates how to setup a multitenant application for a Software-as-a-Service scenario, leveraging the Kyma and Cloud Foundry Runtimes of the SAP Business Technology Platform. Developers learn how to implement their own CAP (mtxs) based SaaS app including an SaaS API and integration with various essential SAP BTP service of...
Apache License 2.0
75 stars 38 forks source link

Bug in service-manager.js prevents removal of Service Brokers or removes potentially a wrong service broker. #6

Closed michaelwittmann closed 9 months ago

michaelwittmann commented 9 months ago

We encountered this problem testing on a Subaccount where we subscribed this application in one subaccount from multiple provider instances (prod, dev, test).

The current implementation pretends to work if you have only one service broker registered in the subscribing subaccount. The API call in getServiceBroker always returns all service brokers, because the filter condition is not applied. But only the first service broker from the result is returned here (https://github.com/SAP-samples/btp-cap-multitenant-saas/blob/222dcd0d334829011c59fdc3c55eee2604ed23d5/code/srv/srv/utils/service-manager.js#L214C16-L214C16)

As consequence automation.js possibly deletes the wrong service broker https://github.com/SAP-samples/btp-cap-multitenant-saas/blob/222dcd0d334829011c59fdc3c55eee2604ed23d5/code/srv/srv/utils/automator.js#L109

The problem originates in the URLEncoding of the search query.

The final URL results in https://service-manager.cfapps.eu10.hana.ondemand.com/v1/service_brokers?fieldQuery%3Dname%20eq%20%27*-api-sb-test******

The problem is that the URL query's = sign is encoded to %3D; therefore, URL query parameters are not resolved. As a result, the query is not applied, and the API returns all three service broker instances.

image

With the fix in place, the result is as expected. image

cla-assistant[bot] commented 9 months ago

CLA assistant check
All committers have signed the CLA.

alperdedeoglu commented 9 months ago

Hi @michaelwittmann, Thank you very much for your contribution, nice catch really!

Looks good to me.