Closed dmlond closed 1 year ago
I got this to work, so I closed the issue but this is here for posterity in case someone else encounters this. I had to return a json response, and add 'Content-Type' => 'application/json'
to my stubbed response headers to make it work correctly
stub_request(:get, "https://#{auth_host}/oidc/userinfo")
.with(headers: { 'Authorization' => "Bearer #{auth_access_token}" })
.to_return(status: response_status, body: response_body.to_json, headers: {'Content-Type' => 'application/json'})
I am using rspec and webmock to unit test a class that uses openid_connect to interact with our institutional openid connect system for oauth authentication. I have a test that is failing, and I cannot figure out how to make it pass.
The class constructor takes an access token, and then uses the following code to authenticate the user, and store the userinfo in an accessor attribute on the instance.
Our unit test uses webmock to mock this call with a predictable response body in json format
This fails
I tried changing our response to a ActiveSupport::HashWithIndifferentAccess
This fails too
access_token.rb line 31 wants calls
res.body.with_indifferent_access
, but this method is only available on an ActiveSupport::HashWithIndifferentAccess, which is really only available in rails, and webmock does not allow one to be stubbed as a respone.