1

Use Case :: Trying to mock a destination that would help us connect to a cloud S4 system behind an IDP and requires Oauth2 authentication.

I have been able to mock a local destination to connect to system behind basic authentication. We are trying to understand how to mock the additional components susch as XSUAA service that would require us to generate the token We want to use this destination to enable us to connect to remote systems locally without modifying the code developed for the cloud enviornment.

Anirban Das
  • 107
  • 7
  • Which version of the SDK are you using? Also, do you mean "mocking" in a sense of automated/unit testing? The rest of your description sounds more like you want to define some destination and run your app against it, which wouldn't be mocking (for which you could use our `MockUtil` class and/or WireMock without an actual system behind it). For actual running your application against a "local" destination I don't see a good way. As your endpoint is OAuth2 protected you *need* to have an authentication token provided by a trusted authority, which is exactly what the XSUAA service would do. – Christoph Schubert Oct 10 '19 at 06:27
  • We are currently on sdk version 2.19.1 with plans to move to 3.0. We are exploring both use cases . 1. to enable to connect to remote cloud system from local development environment . 2. For automated test cases(This was already achieved through mockutil .). Regarding our first use case, can we use a XSUAA service in CF to generate our bearer tokens and use the cloud sdk apis to enable developers to connect to remote systems locally. – Anirban Das Oct 10 '19 at 06:33
  • Okay, understood. However, for a Destination without Basic-/No-Authentication we query the destination service for the auth tokens to use. This means for your use case (using OAuth2 destinations) we would need the binding to the destination service. In general this is done via the VCAP_SERVICES environment variable. So you could copy this over locally and work with that. However, I would not advise to do this, as this contains sensitive information (credentials to the service). – Christoph Schubert Oct 10 '19 at 07:10
  • Well, we can create a destination in CF so that the destination service itself can be used . If we have a destination , what changes do you suggest we make to run the application @localhost. – Anirban Das Oct 10 '19 at 07:17
  • As our communication with the the heavily relies on the VCAP_SERVICES variable I don't see any easy way around copying it, which I still wouldn't recommend. If you are able to manually do the flow necessary to retrieve the AuthenticationToken the DestinationService would provide you, you could (in version 3) create your own DestinationLoader implementation which allows you to create your own destinations returning the respective header for the communication. Maybe a better question: Why do you want to run a CF bound application locally? – Christoph Schubert Oct 10 '19 at 07:25
  • I will look into your suggestion for custom DestinationLoader . To answer your question we are developing an application where we are consuming Odata exposed by S/4(also in development) which is only available in S/4 Hana Cloud. We had already used cloud-sdk to consume these sevices . We are trying to setup a local environment to enable better/faster debugging where devs are not overtly blocked due to any CF or webide issues. – Anirban Das Oct 10 '19 at 07:36
  • Okay, understood. Then I would suggest to have a look at this: https://stackoverflow.com/questions/54169124/remote-debugging-in-sap-cloud-foundry/54183553#54183553 There I describe how debugging on CF might work for you. I use Intellij IDEA for this and it worked quite well. – Christoph Schubert Oct 10 '19 at 07:44

1 Answers1

1

To basically recap the discussion in the comments:

It is not easily possible to consume Cloud Foundry services locally. The SDK reads many of the necessary configuration and credentials from the VCAP_SERVICES to communicate with those services. The only option, which is not recommended, is to copy this down locally. However, this poses security risks, as the environment variable contains sensitive information.

If the only reason is easier debugging of your application you could have a look at this answer to see how remote debugging can be set up.

Christoph Schubert
  • 1,089
  • 1
  • 8
  • 16