mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
How to handle encrypted payload in requests and responses? #500
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jsyrjala on GitHub (Mar 20, 2023).
I have message format where requests and responses have a JSON body where one of the elements contains
an another JSON element as encrypted.
Both the request and response look essentially like this. All the interesting stuff is inside the
encryptedField.I'd like to decrypt the request, then generate a response based on the decrypted request. And finally I should encrypt the response again before sending it to the client.
I know how to decrypt/encrypt the data but how to plug that into WireMock.Net?
I was hoping that there would be possibility to have functions that convert request bodies at the start of the flow and then convert response bodies at the end of the flow.
@jsyrjala commented on GitHub (Mar 20, 2023):
After some digging, it seems that at least it is possible to implement IResponseProvider, and use that to handle the request and response as you want. However this, makes using for example WireMock's template functionality hard or impossible.
@StefH commented on GitHub (Mar 20, 2023):
Instead of building your complete ResponseProvider, you can also use the following WithBody method:
For a example see
https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithCallbackTests.cs#L89
@StefH commented on GitHub (Mar 20, 2023):
However, if you want to use HandleBars.Net templating, you can use the base64decode Helper, see
https://github.com/Handlebars-Net/Handlebars.Net.Helpers/wiki/String#stringbase64decode
Or you can register you own specific Handlebars.Net.Helper:
Register this with the HandlebarsRegistrationCallback in the settings class.
@StefH commented on GitHub (Apr 9, 2023):
@jsyrjala
Did you manage to get it working.
@jsyrjala commented on GitHub (Apr 9, 2023):
Thanks. It is working now.