-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from julianghionoiu/update-client
Update client
- Loading branch information
Showing
40 changed files
with
1,085 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ Gemfile.lock | |
out | ||
coverage | ||
.DS_Store | ||
challenges |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule broker
updated
5 files
+21 −0 | README.md | |
+0 −78 | activemq-wrapper | |
+0 −13 | activemq-wrapper.properties | |
+186 −0 | activemq-wrapper.py | |
+ − | local-distributions/apache-activemq-5.11.1-bin.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class NoisyImplementationRunner | ||
|
||
def initialize(deploy_message, audit_stream) | ||
@deploy_message = deploy_message | ||
@audit_stream = audit_stream | ||
end | ||
|
||
def run | ||
@audit_stream.write_line(@deploy_message) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class QuietImplementationRunner | ||
def run | ||
# Do nothing. | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class TestAuditStream | ||
def initialize | ||
@total = '' | ||
end | ||
|
||
def write_line(s) | ||
@total += "#{s}\n" | ||
end | ||
|
||
def get_log | ||
puts @total | ||
@total | ||
end | ||
|
||
def clear | ||
@total = '' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'unirest' | ||
|
||
class WiremockProcess | ||
|
||
def initialize(hostname, port) | ||
@base_url = "http://#{hostname}:#{port}" | ||
end | ||
|
||
def create_new_mapping(config) | ||
request_json = { | ||
request: { | ||
urlPattern: config[:endpointMatches], | ||
url: config[:endpointEquals], | ||
method: config[:verb] | ||
}, | ||
response: { | ||
body: config[:responseBody], | ||
statusMessage: config[:statusMessage], | ||
status: config[:status] | ||
} | ||
} | ||
|
||
if config[:acceptHeader] | ||
request_json[:request][:headers] = { | ||
accept: { | ||
contains: config[:acceptHeader] | ||
} | ||
} | ||
end | ||
|
||
response = Unirest.post "#{@base_url}/__admin/mappings/new", | ||
headers: {"Accept" => "application/json"}, | ||
parameters: request_json.to_json | ||
end | ||
|
||
def reset | ||
Unirest.post "#{@base_url}/__admin/reset" | ||
end | ||
|
||
def verify_endpoint_was_hit(endpoint, method_type, body) | ||
count_requests_with_endpoint(endpoint, method_type, body) === 1 | ||
end | ||
|
||
def count_requests_with_endpoint(endpoint, verb, body) | ||
request_json = { | ||
url: endpoint, | ||
method: verb | ||
} | ||
|
||
if body | ||
request_json[:bodyPatterns] = [{equalTo: body}] | ||
end | ||
|
||
response = Unirest.post "#{@base_url}/__admin/requests/count", | ||
headers: {"Accept" => "application/json"}, | ||
parameters: request_json.to_json | ||
|
||
response.body["count"] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
require 'fileutils' | ||
|
||
require_relative './runner/wiremock_process' | ||
require_relative './runner/test_audit_stream' | ||
require_relative './runner/noisy_implementation_runner' | ||
require_relative './runner/quiet_implementation_runner' | ||
|
||
audit_stream = TestAuditStream.new | ||
implementation_runner = QuietImplementationRunner.new | ||
working_directory = './' | ||
|
||
Given(/^There is a challenge server running on "([^"]*)" port (\d+)$/) do |hostname, port| | ||
@challenge_hostname = hostname | ||
@port = port | ||
|
||
@challenge_server_stub = WiremockProcess.new(hostname, port) | ||
@challenge_server_stub.reset | ||
end | ||
|
||
Given(/^There is a recording server running on "([^"]*)" port (\d+)$/) do |hostname, port| | ||
@recording_server_stub = WiremockProcess.new(hostname, port) | ||
@recording_server_stub.reset | ||
end | ||
|
||
Given(/^the challenge server exposes the following endpoints$/) do |table| | ||
table.hashes.each do |config| | ||
@challenge_server_stub.create_new_mapping(config) | ||
end | ||
end | ||
|
||
Given(/^the recording server exposes the following endpoints$/) do |table| | ||
table.hashes.each do |config| | ||
@recording_server_stub.create_new_mapping(config) | ||
end | ||
end | ||
|
||
Given(/^the challenge server returns (\d+) for all requests$/) do |return_code| | ||
#HACK to get the unirest ruby client to NOT follow the redirect | ||
(return_code.to_i.equal? 301) ? _return_code = 306 : _return_code = return_code | ||
|
||
puts ">>>>>>>>>#{_return_code},#{return_code}" | ||
@challenge_server_stub.create_new_mapping({ | ||
endpointMatches: '^(.*)', | ||
status: _return_code, | ||
verb: 'ANY' | ||
}) | ||
end | ||
|
||
Given(/^the challenge server returns (\d+), response body "([^"]*)" for all requests$/) do |return_code, body| | ||
@challenge_server_stub.create_new_mapping({ | ||
endpointMatches: '^(.*)', | ||
status: return_code, | ||
verb: 'ANY', | ||
responseBody: body | ||
}) | ||
end | ||
|
||
Given(/^the challenges folder is empty$/) do | ||
FileUtils.rm_rf(Dir.glob('challenges/*')) | ||
end | ||
|
||
Given(/^the action input comes from a provider returning "([^"]*)"$/) do |s| | ||
@action_provider_callback = ->() {s} | ||
end | ||
|
||
Given(/^there is an implementation runner that prints "([^"]*)"$/) do |s| | ||
@implementation_runner_message = s | ||
implementation_runner = NoisyImplementationRunner.new(s, audit_stream) | ||
end | ||
|
||
Given(/^recording server is returning error/) do | ||
@recording_server_stub.reset | ||
end | ||
|
||
Given(/^journeyId is "([^"]*)"$/) do |journey_id| | ||
@journey_id = journey_id | ||
end | ||
|
||
Given(/^the challenge server is broken$/) do | ||
@challenge_server_stub.reset | ||
end | ||
|
||
When(/^user starts client$/) do | ||
audit_stream.clear | ||
|
||
config = TDL::ChallengeSessionConfig.for_journey_id(@journey_id) | ||
.with_server_hostname(@challenge_hostname) | ||
.with_port(@port) | ||
.with_colours(true) | ||
.with_audit_stream(audit_stream) | ||
.with_recording_system_should_be_on(true) | ||
.with_working_directory(working_directory) | ||
|
||
TDL::ChallengeSession.for_runner(implementation_runner) | ||
.with_config(config) | ||
.with_action_provider(@action_provider_callback) | ||
.start | ||
end | ||
|
||
Then(/^the server interaction should contain the following lines:$/) do |expected_output| | ||
total = audit_stream.get_log.strip | ||
lines = expected_output.split("\n") | ||
lines.each do |line| | ||
line = line.strip | ||
unless line.empty? | ||
assert total.include?(line), 'Expected string is not contained in output' | ||
end | ||
end | ||
end | ||
|
||
Then(/^the server interaction should look like:$$/) do |expected_output| | ||
total = audit_stream.get_log.strip | ||
assert_equal total, expected_output.strip.gsub(/\r/,''), 'Expected string is not contained in output' | ||
end | ||
|
||
Then(/^the recording system should be notified with "([^"]*)"$/) do |expected_output| | ||
audit_stream.get_log | ||
assert @recording_server_stub.verify_endpoint_was_hit('/notify', 'POST', expected_output) | ||
end | ||
|
||
Then(/^the file "([^"]*)" should contain$/) do |file, text| | ||
content = File.read(file) | ||
assert_equal content.strip, text.strip.gsub(/\r/,''), 'Contents of the file is not what is expected' | ||
end | ||
|
||
Then(/^the implementation runner should be run with the provided implementations$/) do | ||
total = audit_stream.get_log | ||
assert total.include?(@implementation_runner_message) | ||
end | ||
|
||
Then(/^the client should not ask the user for input$/) do | ||
total = audit_stream.get_log | ||
assert !total.include?('Selected action is:') | ||
end |
Submodule spec
updated
2 files
+0 −0 | queue/QueueRunner.feature | |
+102 −0 | runner/ChallengeSession.feature |
Oops, something went wrong.