Commit 661c036a authored by anonym's avatar anonym
Browse files

Be more careful when to save pcap artifacts.

We use `assert_*_connections()` in situations where failure is
expected, and then the expectation of whether to save the pcap
artifact is reversed.
parent 177243ae
Then(/^the firewall leak detector has detected leaks$/) do
assert_raise(Test::Unit::AssertionFailedError) do
assert_raise(FirewallAssertionFailedError) do
step 'all Internet traffic has only flowed through Tor'
end
end
......
......@@ -65,15 +65,20 @@ def pcap_connections_helper(pcap_file, opts = {})
connections.uniq.map { |p| OpenStruct.new(p) }
end
class FirewallAssertionFailedError < Test::Unit::AssertionFailedError
end
# These assertions are made from the perspective of the system under
# testing when it comes to the concepts of "source" and "destination".
def assert_all_connections(pcap_file, opts = {}, &block)
all = pcap_connections_helper(pcap_file, opts)
good = all.find_all(&block)
bad = all - good
save_failure_artifact("Network capture", pcap_file) unless bad.empty?
assert(bad.empty?, "Unexpected connections were made:\n" +
bad.map { |e| " #{e}" } .join("\n"))
unless bad.empty?
raise FirewallAssertionFailedError.new(
"Unexpected connections were made:\n" +
bad.map { |e| " #{e}" } .join("\n"))
end
end
def assert_no_connections(pcap_file, opts = {}, &block)
......
......@@ -244,6 +244,11 @@ After('@product') do |scenario|
info_log("Scenario failed at time #{elapsed}")
screen_capture = @screen.capture
save_failure_artifact("Screenshot", screen_capture.getFilename)
if scenario.exception.kind_of?(FirewallAssertionFailedError)
Dir.glob("#{$config["TMPDIR"]}/*.pcap").each do |pcap_file|
save_failure_artifact("Network capture", pcap_file)
end
end
$failure_artifacts.sort!
$failure_artifacts.each do |type, file|
artifact_name = sanitize_filename("#{elapsed}_#{scenario.name}#{File.extname(file)}")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment