Class: TLSPretense::TestHarness::TestManager
- Inherits:
-
Object
- Object
- TLSPretense::TestHarness::TestManager
- Includes:
- PacketThief::Logging
- Defined in:
- lib/tlspretense/test_harness/test_manager.rb
Overview
Tracks testing state and handles reporting for the TestListener.
Instance Attribute Summary collapse
-
#current_test ⇒ Object
Returns the value of attribute current_test.
-
#goodcacert ⇒ Object
Returns the value of attribute goodcacert.
-
#goodcakey ⇒ Object
Returns the value of attribute goodcakey.
-
#listener ⇒ Object
Returns the value of attribute listener.
-
#remaining_tests ⇒ Object
readonly
Returns the value of attribute remaining_tests.
Instance Method Summary collapse
-
#initialize(context, testlist, report) ⇒ TestManager
constructor
A new instance of TestManager.
- #pause ⇒ Object
- #paused? ⇒ Boolean
-
#prepare_next_test(first = false) ⇒ Object
grabs the next test.
- #stop_testing ⇒ Object
-
#test_completed(test, actual_result) ⇒ Object
Called when a test completes or is skipped.
- #testing_method ⇒ Object
- #unpause ⇒ Object
Methods included from PacketThief::Logging
Constructor Details
#initialize(context, testlist, report) ⇒ TestManager
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 15 def initialize(context, testlist, report) @appctx = context @testlist = testlist @report = report @remaining_tests = @testlist.dup @goodcacert = @appctx.cert_manager.get_cert("goodca") @goodcakey = @appctx.cert_manager.get_key("goodca") @pause = false prepare_next_test(true) end |
Instance Attribute Details
#current_test ⇒ Object
Returns the value of attribute current_test.
7 8 9 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 7 def current_test @current_test end |
#goodcacert ⇒ Object
Returns the value of attribute goodcacert.
12 13 14 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 12 def goodcacert @goodcacert end |
#goodcakey ⇒ Object
Returns the value of attribute goodcakey.
13 14 15 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 13 def goodcakey @goodcakey end |
#listener ⇒ Object
Returns the value of attribute listener.
10 11 12 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 10 def listener @listener end |
#remaining_tests ⇒ Object (readonly)
Returns the value of attribute remaining_tests.
8 9 10 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 8 def remaining_tests @remaining_tests end |
Instance Method Details
#pause ⇒ Object
99 100 101 102 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 99 def pause @pause = true loginfo "Press Enter to continue." end |
#paused? ⇒ Boolean
95 96 97 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 95 def paused? @pause end |
#prepare_next_test(first = false) ⇒ Object
grabs the next test. Returns it, or nil if we are out of tests.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 29 def prepare_next_test(first=false) @current_test = @remaining_tests.shift if current_test == nil stop_testing elsif @appctx.config.pause? and not first pause else loginfo "Starting test: #{current_test.id}" end @start_time = Time.now end |
#stop_testing ⇒ Object
89 90 91 92 93 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 89 def stop_testing loginfo "Stopping" @listener.stop_server if @listener EM.stop_event_loop end |
#test_completed(test, actual_result) ⇒ Object
Called when a test completes or is skipped. It adds an SSLTestResult to the report, and it cleans up after itself.
:connected, :rejected, :sentdata
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 47 def test_completed(test, actual_result) logdebug "test_completed", :actual_result => actual_result, :expected_result => test.expected_result, :test => test.id return if actual_result == :running passed = if @appctx.config.testing_method == 'tlshandshake' case test.expected_result.to_s when 'connected', :connected %w{connected sentdata}.include? actual_result.to_s when 'rejected', :rejected actual_result == :rejected else raise "Unknown expected_result: #{test.expected_result}" end else # senddata, which requires data to be sent for it to pass. case test.expected_result when 'connected' actual_result == :sentdata when 'rejected' %w{rejected connected}.include? actual_result.to_s else raise "Unknown expected_result: #{test.expected_result}" end end str = SSLTestResult.new(test.id, passed) str.description = test.description str.expected_result = test.expected_result str.actual_result = actual_result.to_s str.start_time = @start_time str.stop_time = Time.now @report.add_result(str) if actual_result == :skipped loginfo "#{test.id}: Skipping test" else loginfo "#{test.id}: Finished test" end prepare_next_test if current_test == test end |
#testing_method ⇒ Object
111 112 113 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 111 def testing_method @appctx.config.testing_method end |
#unpause ⇒ Object
104 105 106 107 108 109 |
# File 'lib/tlspretense/test_harness/test_manager.rb', line 104 def unpause if paused? loginfo "Starting test: #{current_test.id}" @pause = false end end |