InspectRequest
This library will provide you with a proxy (Ritm) which make it possible to inspect network going thru it. It similar to what mockserver provide, but much simpler (less feature as well). Under the verification function, you have a copy of the request. And you can inspect it however you want. In the end, you just need to return true/false.
Installation
Add this line to your application's Gemfile:
gem 'inspect_request'
And then execute:
$ bundle
Or install it yourself as:
$ gem install inspect_request
Usage
require 'inspect_request'
require 'rest-client'
foo = InspectRequest::Checker.new
# we can configure our proxy details similar to Ritm
foo.configure do
proxy[:bind_port] = 8080 # default port
end
foo.verify do |req|
req.host == 'example.org'
end
# make sure to go throuh our proxy
RestClient.proxy = 'http://127.0.0.1:8080'
# send a test request
RestClient.get 'http://example.org'
sleep 1
foo.fulfilled? # true
Self-signed Certificate
Use the following command to generate insecure_ca.pem and insecure_ca.key
require 'ritm/certs/ca'
ca = Ritm::CA.create common_name: 'Inspect Request'
File.write('insecure_ca.pem', ca.pem)
File.write('insecure_ca.key', ca.private_key.to_s)
Then we'll need to use it like this:
INSECURE_CA_PEM = './insecure_ca.pem'.freeze
INSECURE_CA_KEY = './insecure_ca.key'.freeze
foo = InspectRequest::Checker.new
foo.configure do
ssl_reverse_proxy.ca[:pem] = INSECURE_CA_PEM
ssl_reverse_proxy.ca[:key] = INSECURE_CA_KEY
end
Finally, you can test it using curl:
curl -k --cacert insecure_ca.pem -x http://localhost:7777 https://httpbin.org/get
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
License
The gem is available as open source under the terms of the MIT License.