Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
flipp-mockserver-client
Advanced tools
A Ruby client for MockServer project. This client follows the Java client's fluent style closely by using Ruby blocks.
Add this line to your application's Gemfile:
gem 'mockserver-client'
Create and install the gem:
gem build [gem_name].gemspec
gem install [gem_name-version].gem
The Ruby code here assumes you have included MockServer
and MockServer::Model::DSL
modules. So these lines should typically be at the top of your code:
include MockServer
include MockServer::Model::DSL
client = MockServerClient.new('localhost', 9999)
expectation = expectation do |expectation|
expectation.request do |request|
request.method = 'POST'
request.path = '/login'
request.query_string_parameters << parameter('returnUrl', '/account')
request.cookies = [cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')]
request.body = exact("{username: 'foo', password: 'bar'}")
end
expectation.response do |response|
response.status_code = 401
response.headers << header('Content-Type', 'application/json; charset=utf-8')
response.headers << header('Cache-Control', 'public, max-age=86400')
response.body = body("{ message: 'incorrect username and password combination' }")
response.delay = delay_by(:SECONDS, 1)
end
end
client.register(expectation)
client.clear(request('POST', '/login'))
client.reset
# Not providing times here because the default is exactly(1) i.e. the second argument to verify method
ProxyClient.new('localhost', 9090).verify(request(:POST, '/login') do |request|
request.body = exact("{username: 'foo', password: 'bar'}")
request.cookies = [cookie("sessionId", ".*")]
end)
# Second argument is true to set output to Java; false to set output to default JSON (default)
ProxyClient.new('localhost', 9090).dump_log(request(:POST, '/login'), false)
The DSL is provided via the MockServer::Model::DSL
module. Include this module in your code to make the DSL available.
Request
request(:POST, '/login') {|r| r.headers << header("Content-Type", "application/json")}
.request
.Body
body("unaccepted")
.STRING
. Example: exact('{"reason": "unauthorized"}')
.REGEX
. Example: regex('username[a-z]{4}')
.XPATH
. Example: xpath("/element[key = 'some_key' and value = 'some_value']")
.PARAMETERS
. Example parameterized(parameter('someValue', 1, 2), parameter('otherValue', 4, 5))
.Parameters
parameter('key', 'value1' , 'value2')
.parameter
above but exists as syntactic sugar). Example: cookie('sessionId', 'sessionid1ldj')
.parameter
above but exists as syntactic sugar). Example: header('Content-Type', 'application/json')
.Forward
forward {|f| f.scheme = 'HTTPS' }
.forward
.Response
response {|r| r.status_code = 201 }
.response
.Delay
delay_by(:MICROSECONDS, 20)
.Times (used in Expectation)
times {|t| t.unlimited = false }
.unlimited()
. (No parameters).once()
. (No parameters).exactly(2)
.at_least(2)
.Expectation (use in register)
expectation {|e| e.request {|r| r.path = "index.html} }
.
Getter methods for request
, response
and forward
methods will optionally accept a block. If block is passed object is configured before it is returned. The attribute times
has conventional getter and setter methods.This gem comes with a command line interface which allow you to run the Mock Server calls from the command line. When this gem is installed, you will have the mockserver
executable on your PATH. Type mockserver --help
and you will get this output:
mockserver --help
Commands:
mockserver clear # Clears all stored mock request/responses from server.
mockserver dump_log # Dumps the matching request to the mock server logs.
mockserver help [COMMAND] # Describe available commands or one specific command
mockserver register # Register an expectation with the mock server.
mockserver reset # Resets the server clearing all data.
mockserver retrieve # Retrieve the list of requests that have been made to the mock/proxy server.
mockserver verify # Verify that a request has been made the specified number of times to the server.
Options:
-h, --host=HOST # The host for the MockServer client.
# Default: localhost
-p, --port=N # The port for the MockServer client.
# Default: 8080
-d, [--data=DATA] # A JSON or YAML file containing the request payload.
To get help for an individual command, e.g. dump_log
, you would do:
mockserver --help dump_log
Usage:
mockserver dump_log
Options:
-j, [--java], [--no-java] # A switch to turn Java format for logs on/off.
-h, --host=HOST # The host for the MockServer client.
# Default: localhost
-p, --port=N # The port for the MockServer client.
# Default: 8080
-d, [--data=DATA] # A JSON or YAML file containing the request payload.
Dumps the matching request to the mock server logs.
Here is an example on how you would run the command:
mockserver dump_log -j true
Running with parameters:
host: localhost
port: 8080
java: true
[2014-06-21 09:23:32] DEBUG [MockServerClient] Sending dump log request to mockserver
[2014-06-21 09:23:32] DEBUG [MockServerClient] URL: /dumpToLog?type=java. Payload: {}
[2014-06-21 09:23:32] DEBUG [MockServerClient] Got dump to log response: 202
FAQs
Unknown package
We found that flipp-mockserver-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.