CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/test/lib/msf_matchers.rb
Views: 1904
1
$:.unshift(File.join((File.dirname(__FILE__))))
2
require 'regexr'
3
4
module MsfTest
5
module MsfMatchers
6
class ContainACompleteTest
7
8
def initialize()
9
@r = Regexr.new(true)
10
end
11
12
def matches?(data)
13
@data = data
14
return @r.verify_start_and_end(@data, "meterpreter_functional_test_start", "meterpreter_functional_test_end")
15
end
16
17
def failure_message
18
"Beginning or end was incorrect."
19
end
20
21
def negative_failure_message
22
"Expected to find a no beginning or end, but it matched."
23
end
24
25
end
26
27
def contain_a_complete_test
28
ContainACompleteTest.new
29
end
30
31
class ContainAllSuccesses
32
33
def initialize(successes = [])
34
@successes = successes
35
@r = Regexr.new(true)
36
end
37
38
def matches?(data)
39
@data = data
40
@string = @r.find_strings_that_dont_exist_in_data(@data, @successes)
41
return true if !@string
42
43
nil
44
end
45
46
def failure_message
47
"expected all successes, but didn't find '#{@string}'"
48
end
49
50
def negative_failure_message
51
"expected to miss successes but found'm all :("
52
end
53
54
# alias :have_all_successes :contain_all_successes
55
end
56
57
def contain_all_successes(successes = [])
58
ContainAllSuccesses.new(successes)
59
end
60
61
class ContainNoFailuresExcept
62
63
def initialize(failures = [], exceptions = [])
64
@failures = failures
65
@exceptions = exceptions
66
@r = Regexr.new(true)
67
end
68
69
def matches?(data)
70
@data = data
71
@string = @r.find_strings_that_exist_in_data_except(@data, @failures, @exceptions)
72
return true if !@string
73
74
nil
75
end
76
77
def failure_message
78
"expected no failure to be found, but found this: '#{@string}'"
79
end
80
81
def negative_falure_message
82
"expected to find failures, but didn't find any :("
83
end
84
85
# alias :have_no_failures :contain_no_failures
86
end
87
88
def contain_no_failures_except(failures = [], exceptions = [])
89
ContainNoFailuresExcept.new(failures, exceptions)
90
end
91
end
92
end
93
94