Class: Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::WinConstManager::UnitTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb

Instance Method Summary collapse

Instance Method Details

#test_add_constObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 40

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_initializationObject



53
54
55
56
57
58
59
60
61
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 53

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_parseableObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 15

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_parseObject



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
88
89
90
91
92
93
94
95
96
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb', line 63

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