bypass icon indicating copy to clipboard operation
bypass copied to clipboard

Can Bypass be used for API calls that use Digest Auth?

Open ggwc82 opened this issue 5 years ago • 2 comments

I'm trying to use Bypass in my tests to return two different responses in quick succession. The only difference between the two requests is the Authentication headers; I may be wrong, but from reading the docs it doesn't look like Bypass differentiates responses based on this?

The reason for this is because the API I'm trying to test an API that relies on Digest Authentication, where an initial call to the endpoint returns a 401 Unauthorized with a nonce and realm. The second call involves using this nonce and realm, along with credentials to authenticate, after which a 200/201 is returned.

Is this something I can test with Bypass, or should I use something like Mox instead?

ggwc82 avatar Nov 13 '19 11:11 ggwc82

You could let the bypass expect both requests in the same Bypass.expect, and inside the function differentiate based on the header using something like

if Conn.get_req_header( ...) == ....
  resp(200, ...
else
  resp(401, ...
end

VitorTrin avatar Nov 13 '19 14:11 VitorTrin

As this happened to myself as well, I think we should include a proper example in the Readme.

/cc @MSch

ream88 avatar Apr 20 '20 13:04 ream88