Class: Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::WinConstManager::UnitTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::WinConstManager::UnitTest
- Defined in:
- lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb
Instance Method Summary collapse
- #test_add_const ⇒ Object
- #test_initialization ⇒ Object
- #test_is_parseable ⇒ Object
- #test_parse ⇒ Object
- #test_select_const_names ⇒ Object
Instance Method Details
#test_add_const ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 61 def test_add_const target_key = 'VALID_KEY' target_value = 23 const_manager = WinConstManager.new const_manager.add_const(target_key, target_value) assert_equal(target_value, const_manager.parse(target_key), "add_const should add a constant/value pair that can be trieved with parse") end |
#test_initialization ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 74 def test_initialization target_key = 'VALID_KEY' target_value = 23 const_manager = WinConstManager.new(target_key => target_value) assert_equal(target_value, const_manager.parse(target_key), "upon initialization, should add any provided constants.") end |
#test_is_parseable ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 36 def test_is_parseable const_manager = WinConstManager.new first_key = 'SOME_NUMBER' second_key = 'SOME_OTHER_NUMBER' boolean_logic = first_key + ' | ' + second_key # XXX: Should check (un)parseability before adding constants too? const_manager.add_const(first_key, 43123) const_manager.add_const(second_key, 234) assert(const_manager.is_parseable(boolean_logic), "is_parseable should consider boolean logic statements parseable") assert(const_manager.is_parseable(first_key), "is_parseable should consider constants parseable") assert(! const_manager.is_parseable(5), "is_parseable should not consider non-string keys as parseable") assert(! const_manager.is_parseable('| FOO |'), "is_parseable should not consider malformed boolean expressions parseable") end |
#test_parse ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 84 def test_parse target_key = 'VALID_KEY' target_value = 23 invalid_key = 8 const_manager = WinConstManager.new const_manager.add_const(target_key, target_value) assert_equal(target_value, const_manager.parse(target_key), "parse should retrieve the corresponding value when a key is provided") # From API: "should not throw an exception given an invalid key" assert_nothing_thrown do const_manager.parse(invalid_key) end assert_equal(nil, const_manager.parse(invalid_key), "parse should return nil when an invalid key is provided") x_key = 'X' x_value = 228 y_key = 'Y' y_value = 15 boolean_logic = x_key + ' | ' + y_key target_boolean_logic_result = x_value | y_value const_manager.add_const(x_key, x_value) const_manager.add_const(y_key, y_value) assert_equal(target_boolean_logic_result, const_manager.parse(boolean_logic), "parse should evaluate boolean expressions consisting of OR") end |
#test_select_const_names ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 17 def test_select_const_names const_manager = WinConstManager.new names = %w(W WW WWW) names.each do |name| const_manager.add_const(name, 23) end assert(const_manager.select_const_names(23).sort == names, 'select_const_names should return all names for given value') const_manager.add_const('Skidoo!', 23) assert(const_manager.select_const_names(23, /^\w{1,3}$/).sort == names, 'select_const_names should filter names with provided regex') end |