Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: support replacing fields with specified fake values #19

Open
Roger-luo opened this issue May 4, 2021 · 1 comment
Open

Comments

@Roger-luo
Copy link

Thanks for making the package! this makes it a lot easier for testing HTTP requests indeed. But I find that I'm not able to hide credentials that are not inside the header, my use case is the IBMQClient.jl, where I will need to use my user token to get an access token from the REST API, thus the response body will contain this credential, I wish to replace that
with a fake credential so that I can test it in CI, I currently have to do it manually since I didn't find any options to do so.

I tried to implement it myself, but due to my limited knowledge of the implementation, I didn't have any luck. it would be nice if this package could support this.

@christopher-dG
Copy link
Member

I think we could do this in a nice way with a post-response recording hook, basically letting you pass in a mutating function where you could modify the response to your liking before it gets persisted to disk in recording mode.

Actually, that combined with a pre-request playback hook (modifying request parameters before comparing to the saved request) could replace the current ignore_query and ignore_headers for a more unified API.

For your use cases the hook might look like this:

function transform_before_save(r)
    body = JSON.parse(String(r.body))
    body["access_token"] = "<redacted>"
    r.body = Vector{UInt8}(json(body))
end

I'll have to do some more thinking about how to make this all work nicely, but it's definitely a use case that we should support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants