metasploit_data_models 1.0.0.pre.rails.pre.4.0b → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -2
- data/.travis.yml +6 -3
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +10 -52
- data/Gemfile +4 -6
- data/RELEASING.md +88 -0
- data/Rakefile +23 -0
- data/UPGRADING.md +1 -0
- data/app/models/mdm/api_key.rb +41 -1
- data/app/models/mdm/client.rb +41 -1
- data/app/models/mdm/cred.rb +116 -28
- data/app/models/mdm/event.rb +47 -0
- data/app/models/mdm/exploit_attempt.rb +65 -16
- data/app/models/mdm/exploited_host.rb +27 -0
- data/app/models/mdm/host_detail.rb +44 -0
- data/app/models/mdm/host_tag.rb +6 -8
- data/app/models/mdm/listener.rb +52 -0
- data/app/models/mdm/macro.rb +42 -0
- data/app/models/mdm/mod_ref.rb +21 -1
- data/app/models/mdm/module/action.rb +15 -0
- data/app/models/mdm/module/arch.rb +10 -0
- data/app/models/mdm/module/author.rb +17 -1
- data/app/models/mdm/module/mixin.rb +13 -0
- data/app/models/mdm/module/platform.rb +11 -0
- data/app/models/mdm/module/target.rb +18 -0
- data/app/models/mdm/nexpose_console.rb +82 -4
- data/app/models/mdm/profile.rb +36 -0
- data/app/models/mdm/route.rb +16 -4
- data/app/models/mdm/session_event.rb +32 -0
- data/app/models/mdm/tag.rb +48 -9
- data/app/models/mdm/task.rb +85 -46
- data/app/models/mdm/task_cred.rb +29 -0
- data/app/models/mdm/task_host.rb +25 -0
- data/app/models/mdm/task_service.rb +25 -0
- data/app/models/mdm/task_session.rb +25 -0
- data/app/models/mdm/user.rb +192 -6
- data/app/models/mdm/vuln_attempt.rb +37 -12
- data/app/models/mdm/vuln_detail.rb +138 -5
- data/app/models/mdm/vuln_ref.rb +3 -0
- data/app/models/mdm/web_form.rb +34 -0
- data/app/models/mdm/web_page.rb +69 -0
- data/app/models/mdm/web_site.rb +50 -0
- data/app/models/mdm/wmap_request.rb +85 -0
- data/app/models/mdm/wmap_target.rb +40 -0
- data/app/models/mdm/workspace.rb +160 -17
- data/app/models/metasploit_data_models/automatic_exploitation/match.rb +13 -23
- data/app/models/metasploit_data_models/automatic_exploitation/match_result.rb +25 -4
- data/app/models/metasploit_data_models/automatic_exploitation/match_set.rb +15 -4
- data/app/models/metasploit_data_models/automatic_exploitation/run.rb +7 -3
- data/app/models/metasploit_data_models/ip_address/v4/segmented.rb +1 -1
- data/app/models/metasploit_data_models/module_run.rb +1 -1
- data/app/models/metasploit_data_models/search/visitor/where.rb +1 -1
- data/app/validators/ip_format_validator.rb +4 -0
- data/app/validators/parameters_validator.rb +12 -0
- data/app/validators/password_is_strong_validator.rb +10 -1
- data/lib/mdm/host/operating_system_normalization.rb +7 -10
- data/lib/metasploit_data_models.rb +4 -0
- data/lib/metasploit_data_models/automatic_exploitation.rb +25 -0
- data/lib/metasploit_data_models/engine.rb +2 -0
- data/lib/metasploit_data_models/serialized_prefs.rb +6 -0
- data/lib/metasploit_data_models/version.rb +30 -7
- data/metasploit_data_models.gemspec +9 -2
- data/spec/app/models/mdm/api_key_spec.rb +1 -3
- data/spec/app/models/mdm/client_spec.rb +9 -11
- data/spec/app/models/mdm/cred_spec.rb +42 -54
- data/spec/app/models/mdm/event_spec.rb +22 -24
- data/spec/app/models/mdm/exploit_attempt_spec.rb +19 -21
- data/spec/app/models/mdm/exploited_host_spec.rb +11 -13
- data/spec/app/models/mdm/host_detail_spec.rb +15 -17
- data/spec/app/models/mdm/host_spec.rb +262 -260
- data/spec/app/models/mdm/host_tag_spec.rb +6 -8
- data/spec/app/models/mdm/listener_spec.rb +30 -32
- data/spec/app/models/mdm/loot_spec.rb +21 -23
- data/spec/app/models/mdm/macro_spec.rb +1 -3
- data/spec/app/models/mdm/mod_ref_spec.rb +1 -3
- data/spec/app/models/mdm/module/action_spec.rb +8 -10
- data/spec/app/models/mdm/module/arch_spec.rb +8 -10
- data/spec/app/models/mdm/module/author_spec.rb +19 -14
- data/spec/app/models/mdm/module/detail_spec.rb +184 -75
- data/spec/app/models/mdm/module/mixin_spec.rb +8 -10
- data/spec/app/models/mdm/module/platform_spec.rb +8 -10
- data/spec/app/models/mdm/module/ref_spec.rb +8 -10
- data/spec/app/models/mdm/module/target_spec.rb +10 -12
- data/spec/app/models/mdm/nexpose_console_spec.rb +35 -37
- data/spec/app/models/mdm/note_spec.rb +23 -25
- data/spec/app/models/mdm/profile_spec.rb +1 -3
- data/spec/app/models/mdm/ref_spec.rb +9 -12
- data/spec/app/models/mdm/route_spec.rb +6 -8
- data/spec/app/models/mdm/service_spec.rb +38 -40
- data/spec/app/models/mdm/session_event_spec.rb +10 -12
- data/spec/app/models/mdm/session_spec.rb +13 -15
- data/spec/app/models/mdm/tag_spec.rb +29 -30
- data/spec/app/models/mdm/task_cred_spec.rb +9 -11
- data/spec/app/models/mdm/task_host_spec.rb +9 -11
- data/spec/app/models/mdm/task_service_spec.rb +9 -11
- data/spec/app/models/mdm/task_session_spec.rb +7 -9
- data/spec/app/models/mdm/task_spec.rb +27 -29
- data/spec/app/models/mdm/user_spec.rb +17 -19
- data/spec/app/models/mdm/vuln_attempt_spec.rb +14 -16
- data/spec/app/models/mdm/vuln_detail_spec.rb +26 -28
- data/spec/app/models/mdm/vuln_ref_spec.rb +8 -10
- data/spec/app/models/mdm/vuln_spec.rb +24 -26
- data/spec/app/models/mdm/web_form_spec.rb +11 -13
- data/spec/app/models/mdm/web_page_spec.rb +19 -21
- data/spec/app/models/mdm/web_site_spec.rb +21 -23
- data/spec/app/models/mdm/web_vuln_spec.rb +63 -65
- data/spec/app/models/mdm/wmap_request_spec.rb +1 -3
- data/spec/app/models/mdm/wmap_target_spec.rb +1 -3
- data/spec/app/models/mdm/workspace_spec.rb +97 -100
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_result_spec.rb +3 -5
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_set_spec.rb +13 -15
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/automatic_exploitation/run_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/ip_address/v4/cidr_spec.rb +10 -12
- data/spec/app/models/metasploit_data_models/ip_address/v4/nmap_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/ip_address/v4/range_spec.rb +21 -23
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list_spec.rb +9 -11
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range_spec.rb +21 -23
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/segmented_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/single_spec.rb +22 -15
- data/spec/app/models/metasploit_data_models/ip_address/v4/single_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/module_run_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/search/operation/ip_address_spec.rb +18 -20
- data/spec/app/models/metasploit_data_models/search/operation/port/number_spec.rb +6 -8
- data/spec/app/models/metasploit_data_models/search/operation/port/range_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operation/range_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operator/ip_address_spec.rb +2 -4
- data/spec/app/models/metasploit_data_models/search/operator/multitext_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operator/port/list_spec.rb +6 -8
- data/spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb +9 -11
- data/spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb +5 -7
- data/spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb +17 -19
- data/spec/app/models/metasploit_data_models/search/visitor/method_spec.rb +5 -7
- data/spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb +61 -23
- data/spec/app/models/metasploit_data_models/search/visitor/where_spec.rb +8 -10
- data/spec/app/validators/parameters_validator_spec.rb +29 -29
- data/spec/app/validators/password_is_strong_validator_spec.rb +54 -46
- data/spec/lib/base64_serializer_spec.rb +19 -21
- data/spec/lib/ipaddr_spec.rb +1 -3
- data/spec/lib/metasploit_data_models/ip_address/cidr_spec.rb +18 -12
- data/spec/lib/metasploit_data_models/ip_address/range_spec.rb +4 -6
- data/spec/lib/metasploit_data_models/match/child_spec.rb +2 -4
- data/spec/lib/metasploit_data_models/match/parent_spec.rb +4 -6
- data/spec/lib/metasploit_data_models/version_spec.rb +3 -139
- data/spec/lib/metasploit_data_models_spec.rb +4 -0
- data/spec/spec_helper.rb +86 -12
- data/spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb +2 -2
- data/spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb +4 -4
- data/spec/support/shared/examples/metasploit_data_models/search/operation/ipaddress/match.rb +2 -2
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb +5 -5
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb +5 -5
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb +3 -3
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb +7 -6
- metadata +74 -14
- data/app/models/metasploit_data_models/automatic_exploitation.rb +0 -16
- data/lib/tasks/yard.rake +0 -33
@@ -1,16 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Mdm::Route do
|
1
|
+
RSpec.describe Mdm::Route, type: :model do
|
4
2
|
it_should_behave_like 'Metasploit::Concern.run'
|
5
3
|
|
6
4
|
context 'associations' do
|
7
|
-
it {
|
5
|
+
it { is_expected.to belong_to(:session).class_name('Mdm::Session') }
|
8
6
|
end
|
9
7
|
|
10
8
|
context 'factory' do
|
11
9
|
it 'should be valid' do
|
12
10
|
route = FactoryGirl.build(:mdm_route)
|
13
|
-
route.
|
11
|
+
expect(route).to be_valid
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
@@ -28,9 +26,9 @@ describe Mdm::Route do
|
|
28
26
|
|
29
27
|
context 'database' do
|
30
28
|
context 'columns' do
|
31
|
-
it {
|
32
|
-
it {
|
33
|
-
it {
|
29
|
+
it { is_expected.to have_db_column(:session_id).of_type(:integer) }
|
30
|
+
it { is_expected.to have_db_column(:subnet).of_type(:string) }
|
31
|
+
it { is_expected.to have_db_column(:netmask).of_type(:string) }
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Mdm::Service do
|
1
|
+
RSpec.describe Mdm::Service, type: :model do
|
4
2
|
it_should_behave_like 'Metasploit::Concern.run'
|
5
3
|
|
6
4
|
context 'CONSTANTS' do
|
@@ -9,8 +7,8 @@ describe Mdm::Service do
|
|
9
7
|
described_class::PROTOS
|
10
8
|
}
|
11
9
|
|
12
|
-
it {
|
13
|
-
it {
|
10
|
+
it { is_expected.to include 'tcp' }
|
11
|
+
it { is_expected.to include 'udp' }
|
14
12
|
end
|
15
13
|
|
16
14
|
context 'STATES' do
|
@@ -18,40 +16,40 @@ describe Mdm::Service do
|
|
18
16
|
described_class::STATES
|
19
17
|
}
|
20
18
|
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
24
|
-
it {
|
19
|
+
it { is_expected.to include 'closed' }
|
20
|
+
it { is_expected.to include 'filtered' }
|
21
|
+
it { is_expected.to include 'open' }
|
22
|
+
it { is_expected.to include 'unknown' }
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
26
|
context "Associations" do
|
29
27
|
|
30
|
-
it {
|
31
|
-
it {
|
32
|
-
it {
|
33
|
-
it {
|
34
|
-
it {
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
38
|
-
it {
|
39
|
-
it {
|
40
|
-
it {
|
28
|
+
it { is_expected.to have_many(:task_services).class_name('Mdm::TaskService').dependent(:destroy) }
|
29
|
+
it { is_expected.to have_many(:tasks).class_name('Mdm::Task').through(:task_services) }
|
30
|
+
it { is_expected.to have_many(:creds).class_name('Mdm::Cred').dependent(:destroy) }
|
31
|
+
it { is_expected.to have_many(:exploited_hosts).class_name('Mdm::ExploitedHost').dependent(:destroy) }
|
32
|
+
it { is_expected.to have_many(:notes).class_name('Mdm::Note').dependent(:destroy) }
|
33
|
+
it { is_expected.to have_many(:vulns).class_name('Mdm::Vuln').dependent(:destroy) }
|
34
|
+
it { is_expected.to have_many(:web_sites).class_name('Mdm::WebSite').dependent(:destroy) }
|
35
|
+
it { is_expected.to have_many(:web_pages).class_name('Mdm::WebPage').through(:web_sites) }
|
36
|
+
it { is_expected.to have_many(:web_forms).class_name('Mdm::WebForm').through(:web_sites) }
|
37
|
+
it { is_expected.to have_many(:web_vulns).class_name('Mdm::WebVuln').through(:web_sites) }
|
38
|
+
it { is_expected.to belong_to(:host).class_name('Mdm::Host') }
|
41
39
|
end
|
42
40
|
|
43
41
|
context 'scopes' do
|
44
42
|
context "inactive" do
|
45
43
|
it "should exclude open services" do
|
46
44
|
open_service = FactoryGirl.create(:mdm_service, :state => 'open')
|
47
|
-
Mdm::Service.inactive.
|
45
|
+
expect(Mdm::Service.inactive).not_to include(open_service)
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
51
49
|
context "with_state open" do
|
52
50
|
it "should exclude closed services" do
|
53
51
|
closed_service = FactoryGirl.create(:mdm_service, :state => 'closed')
|
54
|
-
Mdm::Service.with_state('open').
|
52
|
+
expect(Mdm::Service.with_state('open')).not_to include(closed_service)
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
@@ -60,8 +58,8 @@ describe Mdm::Service do
|
|
60
58
|
tcp_service = FactoryGirl.create(:mdm_service, proto: 'tcp')
|
61
59
|
udp_service = FactoryGirl.create(:mdm_service, proto: 'udp')
|
62
60
|
search_results = Mdm::Service.search('tcp')
|
63
|
-
search_results.
|
64
|
-
search_results.
|
61
|
+
expect(search_results).to include(tcp_service)
|
62
|
+
expect(search_results).not_to include(udp_service)
|
65
63
|
end
|
66
64
|
end
|
67
65
|
end
|
@@ -70,7 +68,7 @@ describe Mdm::Service do
|
|
70
68
|
context 'after_save' do
|
71
69
|
it 'should call #normalize_host_os' do
|
72
70
|
svc = FactoryGirl.create(:mdm_service)
|
73
|
-
svc.
|
71
|
+
expect(svc).to receive(:normalize_host_os)
|
74
72
|
svc.run_callbacks(:save)
|
75
73
|
end
|
76
74
|
end
|
@@ -79,7 +77,7 @@ describe Mdm::Service do
|
|
79
77
|
context 'factory' do
|
80
78
|
it 'should be valid' do
|
81
79
|
service = FactoryGirl.build(:mdm_service)
|
82
|
-
service.
|
80
|
+
expect(service).to be_valid
|
83
81
|
end
|
84
82
|
end
|
85
83
|
|
@@ -98,24 +96,24 @@ describe Mdm::Service do
|
|
98
96
|
context 'database' do
|
99
97
|
|
100
98
|
context 'timestamps'do
|
101
|
-
it {
|
102
|
-
it {
|
99
|
+
it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
|
100
|
+
it { is_expected.to have_db_column(:updated_at).of_type(:datetime) }
|
103
101
|
end
|
104
102
|
|
105
103
|
context 'columns' do
|
106
|
-
it {
|
107
|
-
it {
|
108
|
-
it {
|
109
|
-
it {
|
110
|
-
it {
|
111
|
-
it {
|
104
|
+
it { is_expected.to have_db_column(:host_id).of_type(:integer) }
|
105
|
+
it { is_expected.to have_db_column(:port).of_type(:integer).with_options(:null => false) }
|
106
|
+
it { is_expected.to have_db_column(:proto).of_type(:string).with_options(:null => false) }
|
107
|
+
it { is_expected.to have_db_column(:state).of_type(:string) }
|
108
|
+
it { is_expected.to have_db_column(:name).of_type(:string) }
|
109
|
+
it { is_expected.to have_db_column(:info).of_type(:text) }
|
112
110
|
end
|
113
111
|
|
114
112
|
context 'indices' do
|
115
|
-
it {
|
116
|
-
it {
|
117
|
-
it {
|
118
|
-
it {
|
113
|
+
it { is_expected.to have_db_index(:name) }
|
114
|
+
it { is_expected.to have_db_index(:port) }
|
115
|
+
it { is_expected.to have_db_index(:proto) }
|
116
|
+
it { is_expected.to have_db_index(:state) }
|
119
117
|
end
|
120
118
|
end
|
121
119
|
|
@@ -151,8 +149,8 @@ describe Mdm::Service do
|
|
151
149
|
FactoryGirl.build(:mdm_service)
|
152
150
|
}
|
153
151
|
|
154
|
-
it {
|
155
|
-
it {
|
152
|
+
it { is_expected.to validate_numericality_of(:port).only_integer }
|
153
|
+
it { is_expected.to validate_inclusion_of(:proto).in_array(described_class::PROTOS) }
|
156
154
|
|
157
155
|
context 'when a duplicate service already exists' do
|
158
156
|
let(:service1) { FactoryGirl.create(:mdm_service)}
|
@@ -1,16 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Mdm::SessionEvent do
|
1
|
+
RSpec.describe Mdm::SessionEvent, type: :model do
|
4
2
|
it_should_behave_like 'Metasploit::Concern.run'
|
5
3
|
|
6
4
|
context 'associations' do
|
7
|
-
it {
|
5
|
+
it { is_expected.to belong_to(:session).class_name('Mdm::Session') }
|
8
6
|
end
|
9
7
|
|
10
8
|
context 'factory' do
|
11
9
|
it 'should be valid' do
|
12
10
|
session_event = FactoryGirl.build(:mdm_session_event)
|
13
|
-
session_event.
|
11
|
+
expect(session_event).to be_valid
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
@@ -28,16 +26,16 @@ describe Mdm::SessionEvent do
|
|
28
26
|
|
29
27
|
context 'database' do
|
30
28
|
context 'timestamps'do
|
31
|
-
it {
|
29
|
+
it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
|
32
30
|
end
|
33
31
|
|
34
32
|
context 'columns' do
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
38
|
-
it {
|
39
|
-
it {
|
40
|
-
it {
|
33
|
+
it { is_expected.to have_db_column(:session_id).of_type(:integer) }
|
34
|
+
it { is_expected.to have_db_column(:etype).of_type(:string) }
|
35
|
+
it { is_expected.to have_db_column(:command).of_type(:binary) }
|
36
|
+
it { is_expected.to have_db_column(:output).of_type(:binary) }
|
37
|
+
it { is_expected.to have_db_column(:remote_path).of_type(:string) }
|
38
|
+
it { is_expected.to have_db_column(:local_path).of_type(:string) }
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
@@ -1,12 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Mdm::Session do
|
1
|
+
RSpec.describe Mdm::Session, type: :model do
|
4
2
|
it_should_behave_like 'Metasploit::Concern.run'
|
5
3
|
|
6
4
|
context 'factory' do
|
7
5
|
it 'should be valid' do
|
8
6
|
session = FactoryGirl.build(:mdm_session)
|
9
|
-
session.
|
7
|
+
expect(session).to be_valid
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
@@ -61,8 +59,8 @@ describe Mdm::Session do
|
|
61
59
|
alive_session = FactoryGirl.create(:mdm_session)
|
62
60
|
dead_session = FactoryGirl.create(:mdm_session, :closed_at => Time.now)
|
63
61
|
alive_set = Mdm::Session.alive
|
64
|
-
alive_set.
|
65
|
-
alive_set.
|
62
|
+
expect(alive_set).to include(alive_session)
|
63
|
+
expect(alive_set).not_to include(dead_session)
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
@@ -71,8 +69,8 @@ describe Mdm::Session do
|
|
71
69
|
alive_session = FactoryGirl.create(:mdm_session)
|
72
70
|
dead_session = FactoryGirl.create(:mdm_session, :closed_at => Time.now)
|
73
71
|
dead_set = Mdm::Session.dead
|
74
|
-
dead_set.
|
75
|
-
dead_set.
|
72
|
+
expect(dead_set).not_to include(alive_session)
|
73
|
+
expect(dead_set).to include(dead_session)
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
@@ -82,9 +80,9 @@ describe Mdm::Session do
|
|
82
80
|
linux_shell = FactoryGirl.create(:mdm_session, :stype => 'shell', :platform => 'Linux')
|
83
81
|
win_meterp = FactoryGirl.create(:mdm_session, :stype => 'meterpreter', :platform => 'Windows')
|
84
82
|
upgrade_set = Mdm::Session.upgradeable
|
85
|
-
upgrade_set.
|
86
|
-
upgrade_set.
|
87
|
-
upgrade_set.
|
83
|
+
expect(upgrade_set).to include(win_shell)
|
84
|
+
expect(upgrade_set).not_to include(linux_shell)
|
85
|
+
expect(upgrade_set).not_to include(win_meterp)
|
88
86
|
end
|
89
87
|
end
|
90
88
|
end
|
@@ -93,7 +91,7 @@ describe Mdm::Session do
|
|
93
91
|
context 'before_destroy' do
|
94
92
|
it 'should call #stop' do
|
95
93
|
mysession = FactoryGirl.create(:mdm_session)
|
96
|
-
mysession.
|
94
|
+
expect(mysession).to receive(:stop)
|
97
95
|
mysession.destroy
|
98
96
|
end
|
99
97
|
end
|
@@ -103,17 +101,17 @@ describe Mdm::Session do
|
|
103
101
|
context '#upgradeable?' do
|
104
102
|
it 'should return true for windows shells' do
|
105
103
|
win_shell = FactoryGirl.create(:mdm_session, :stype => 'shell', :platform => 'Windows')
|
106
|
-
win_shell.upgradeable
|
104
|
+
expect(win_shell.upgradeable?).to eq(true)
|
107
105
|
end
|
108
106
|
|
109
107
|
it 'should return false for non-windows shells' do
|
110
108
|
linux_shell = FactoryGirl.create(:mdm_session, :stype => 'shell', :platform => 'Linux')
|
111
|
-
linux_shell.upgradeable
|
109
|
+
expect(linux_shell.upgradeable?).to eq(false)
|
112
110
|
end
|
113
111
|
|
114
112
|
it 'should return false for Windows Meterpreter Sessions' do
|
115
113
|
win_meterp = FactoryGirl.create(:mdm_session, :stype => 'meterpreter', :platform => 'Windows')
|
116
|
-
win_meterp.upgradeable
|
114
|
+
expect(win_meterp.upgradeable?).to eq(false)
|
117
115
|
end
|
118
116
|
end
|
119
117
|
end
|
@@ -1,29 +1,28 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require 'securerandom'
|
3
2
|
|
4
|
-
describe Mdm::Tag do
|
3
|
+
RSpec.describe Mdm::Tag, type: :model do
|
5
4
|
it_should_behave_like 'Metasploit::Concern.run'
|
6
5
|
|
7
6
|
context 'associations' do
|
8
|
-
it {
|
9
|
-
it {
|
10
|
-
it {
|
7
|
+
it { is_expected.to have_many(:hosts_tags).class_name('Mdm::HostTag') }
|
8
|
+
it { is_expected.to have_many(:hosts).class_name('Mdm::Host').through(:hosts_tags) }
|
9
|
+
it { is_expected.to belong_to(:user).class_name('Mdm::User') }
|
11
10
|
end
|
12
11
|
|
13
12
|
context 'database' do
|
14
13
|
|
15
14
|
context 'timestamps'do
|
16
|
-
it {
|
17
|
-
it {
|
15
|
+
it { is_expected.to have_db_column(:created_at).of_type(:datetime).with_options(:null => false) }
|
16
|
+
it { is_expected.to have_db_column(:updated_at).of_type(:datetime).with_options(:null => false) }
|
18
17
|
end
|
19
18
|
|
20
19
|
context 'columns' do
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
24
|
-
it {
|
25
|
-
it {
|
26
|
-
it {
|
20
|
+
it { is_expected.to have_db_column(:user_id).of_type(:integer) }
|
21
|
+
it { is_expected.to have_db_column(:name).of_type(:string) }
|
22
|
+
it { is_expected.to have_db_column(:desc).of_type(:text) }
|
23
|
+
it { is_expected.to have_db_column(:report_summary).of_type(:boolean).with_options(:null => false, :default =>false) }
|
24
|
+
it { is_expected.to have_db_column(:report_detail).of_type(:boolean).with_options(:null => false, :default =>false) }
|
25
|
+
it { is_expected.to have_db_column(:critical).of_type(:boolean).with_options(:null => false, :default =>false) }
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
@@ -32,37 +31,37 @@ describe Mdm::Tag do
|
|
32
31
|
it 'should not ba valid for a length over 8k' do
|
33
32
|
desc = SecureRandom.hex(9001) #over 9000?!
|
34
33
|
large_tag = FactoryGirl.build(:mdm_tag, :desc => desc)
|
35
|
-
large_tag.
|
36
|
-
large_tag.errors[:desc].
|
34
|
+
expect(large_tag).not_to be_valid
|
35
|
+
expect(large_tag.errors[:desc]).to include('desc must be less than 8k.')
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
39
|
context 'name' do
|
41
40
|
it 'must be present' do
|
42
41
|
nameless_tag = FactoryGirl.build(:mdm_tag, :name => nil)
|
43
|
-
nameless_tag.
|
44
|
-
nameless_tag.errors[:name].
|
42
|
+
expect(nameless_tag).not_to be_valid
|
43
|
+
expect(nameless_tag.errors[:name]).to include("can't be blank")
|
45
44
|
end
|
46
45
|
|
47
46
|
it 'may only contain alphanumerics, dot, dashes, and underscores' do
|
48
47
|
mytag = FactoryGirl.build(:mdm_tag, :name => 'A.1-B_2')
|
49
|
-
mytag.
|
48
|
+
expect(mytag).to be_valid
|
50
49
|
#Test for various bad inputs we should never allow
|
51
50
|
mytag = FactoryGirl.build(:mdm_tag, :name => "A'1")
|
52
|
-
mytag.
|
53
|
-
mytag.errors[:name].
|
51
|
+
expect(mytag).not_to be_valid
|
52
|
+
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
|
54
53
|
mytag = FactoryGirl.build(:mdm_tag, :name => "A;1")
|
55
|
-
mytag.
|
56
|
-
mytag.errors[:name].
|
54
|
+
expect(mytag).not_to be_valid
|
55
|
+
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
|
57
56
|
mytag = FactoryGirl.build(:mdm_tag, :name => "A%1")
|
58
|
-
mytag.
|
59
|
-
mytag.errors[:name].
|
57
|
+
expect(mytag).not_to be_valid
|
58
|
+
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
|
60
59
|
mytag = FactoryGirl.build(:mdm_tag, :name => "A=1")
|
61
|
-
mytag.
|
62
|
-
mytag.errors[:name].
|
60
|
+
expect(mytag).not_to be_valid
|
61
|
+
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
|
63
62
|
mytag = FactoryGirl.build(:mdm_tag, :name => "#A1")
|
64
|
-
mytag.
|
65
|
-
mytag.errors[:name].
|
63
|
+
expect(mytag).not_to be_valid
|
64
|
+
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
|
66
65
|
end
|
67
66
|
end
|
68
67
|
end
|
@@ -71,7 +70,7 @@ describe Mdm::Tag do
|
|
71
70
|
context '#to_s' do
|
72
71
|
it 'should return the name of the tag as a string' do
|
73
72
|
mytag = FactoryGirl.build(:mdm_tag, :name => 'mytag')
|
74
|
-
mytag.to_s.
|
73
|
+
expect(mytag.to_s).to eq('mytag')
|
75
74
|
end
|
76
75
|
end
|
77
76
|
end
|
@@ -82,7 +81,7 @@ describe Mdm::Tag do
|
|
82
81
|
FactoryGirl.build(:mdm_tag)
|
83
82
|
end
|
84
83
|
|
85
|
-
it {
|
84
|
+
it { is_expected.to be_valid }
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
@@ -1,25 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Mdm::TaskCred do
|
1
|
+
RSpec.describe Mdm::TaskCred, type: :model do
|
4
2
|
it_should_behave_like 'Metasploit::Concern.run'
|
5
3
|
|
6
4
|
context 'factory' do
|
7
5
|
it 'should be valid' do
|
8
6
|
task_cred = FactoryGirl.build(:mdm_task_cred)
|
9
|
-
task_cred.
|
7
|
+
expect(task_cred).to be_valid
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
13
11
|
context 'database' do
|
14
12
|
|
15
13
|
context 'timestamps'do
|
16
|
-
it {
|
17
|
-
it {
|
14
|
+
it { is_expected.to have_db_column(:created_at).of_type(:datetime).with_options(:null => false) }
|
15
|
+
it { is_expected.to have_db_column(:updated_at).of_type(:datetime).with_options(:null => false) }
|
18
16
|
end
|
19
17
|
|
20
18
|
context 'columns' do
|
21
|
-
it {
|
22
|
-
it {
|
19
|
+
it { is_expected.to have_db_column(:task_id).of_type(:integer).with_options(:null => false) }
|
20
|
+
it { is_expected.to have_db_column(:cred_id).of_type(:integer).with_options(:null => false) }
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
@@ -36,8 +34,8 @@ describe Mdm::TaskCred do
|
|
36
34
|
end
|
37
35
|
|
38
36
|
context "Associations" do
|
39
|
-
it {
|
40
|
-
it {
|
37
|
+
it { is_expected.to belong_to(:task).class_name('Mdm::Task') }
|
38
|
+
it { is_expected.to belong_to(:cred).class_name('Mdm::Cred') }
|
41
39
|
end
|
42
40
|
|
43
41
|
context "validations" do
|
@@ -46,7 +44,7 @@ describe Mdm::TaskCred do
|
|
46
44
|
cred = FactoryGirl.build(:mdm_cred)
|
47
45
|
FactoryGirl.create(:mdm_task_cred, :task => task, :cred => cred)
|
48
46
|
task_cred2 = FactoryGirl.build(:mdm_task_cred, :task => task, :cred => cred)
|
49
|
-
task_cred2.
|
47
|
+
expect(task_cred2).not_to be_valid
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|