metasploit_data_models 0.16.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,6 +33,18 @@ class Mdm::Session < ActiveRecord::Base
33
33
  # @return [Mdm::Workspace]
34
34
  has_one :workspace, :through => :host, :class_name => 'Mdm::Workspace'
35
35
 
36
+ # @!attribute [rw] task_sessions
37
+ # Details about sessions this task touched
38
+ #
39
+ # @return [Array<Mdm::TaskSession>]
40
+ has_many :task_sessions, :dependent => :destroy, :class_name => 'Mdm::TaskSession'
41
+
42
+ # @!attribute [rw] task
43
+ # Session this task touched
44
+ #
45
+ # @return [Mdm::Session]
46
+ has_many :tasks, :through => :task_sessions, :class_name => 'Mdm::Task'
47
+
36
48
  #
37
49
  # Attributes
38
50
  #
@@ -24,7 +24,7 @@ class Mdm::Task < ActiveRecord::Base
24
24
  # @!attribute [rw] creds
25
25
  # Creds this task touched
26
26
  #
27
- # @return [Array<Mdm::TaskCred>]
27
+ # @return [Array<Mdm::Cred>]
28
28
  has_many :creds, :through => :task_creds, :class_name => 'Mdm::Cred'
29
29
 
30
30
  # @!attribute [rw] task_hosts
@@ -36,7 +36,7 @@ class Mdm::Task < ActiveRecord::Base
36
36
  # @!attribute [rw] hosts
37
37
  # Hosts this task touched
38
38
  #
39
- # @return [Array<Mdm::TaskHost>
39
+ # @return [Array<Mdm::Host>
40
40
  has_many :hosts, :through => :task_hosts, :class_name => 'Mdm::Host'
41
41
 
42
42
  # @!attribute [rw] task_services
@@ -48,9 +48,22 @@ class Mdm::Task < ActiveRecord::Base
48
48
  # @!attribute [rw] services
49
49
  # Services this task touched
50
50
  #
51
- # @return [Array<Mdm::TaskHost>
51
+ # @return [Array<Mdm::Service>
52
52
  has_many :services, :through => :task_services, :class_name => 'Mdm::Service'
53
53
 
54
+ # @!attribute [rw] task_sessions
55
+ # Details about sessions this task touched
56
+ #
57
+ # @return [Array<Mdm::TaskSession>]
58
+ has_many :task_sessions, :dependent => :destroy, :class_name => 'Mdm::TaskSession'
59
+
60
+ # @!attribute [rw] sessions
61
+ # Session this task touched
62
+ #
63
+ # @return [Array<Mdm::Session>
64
+ has_many :sessions, :through => :task_sessions, :class_name => 'Mdm::Session'
65
+
66
+
54
67
  has_many :reports, :class_name => 'Mdm::Report'
55
68
 
56
69
  #
@@ -0,0 +1,9 @@
1
+ class Mdm::TaskSession < ActiveRecord::Base
2
+ belongs_to :session, :class_name => 'Mdm::Session'
3
+ belongs_to :task, :class_name => 'Mdm::Task'
4
+
5
+ validates :session_id,
6
+ :uniqueness => {
7
+ :scope => :task_id
8
+ }
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTaskSessions < ActiveRecord::Migration
2
+ def change
3
+ create_table :task_sessions do |t|
4
+ t.references :task, :null => false
5
+ t.references :session, :null => false
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -4,5 +4,5 @@ module MetasploitDataModels
4
4
  # metasploit-framework/data/sql/migrate to db/migrate in this project, not all models have specs that verify the
5
5
  # migrations (with have_db_column and have_db_index) and certain models may not be shared between metasploit-framework
6
6
  # and pro, so models may be removed in the future. Because of the unstable API the version should remain below 1.0.0
7
- VERSION = '0.16.0'
7
+ VERSION = '0.16.1'
8
8
  end
@@ -42,11 +42,13 @@ describe Mdm::Session do
42
42
  end
43
43
  end
44
44
 
45
- context 'asscoiations' do
45
+ context 'associations' do
46
46
  it { should belong_to(:host).class_name('Mdm::Host') }
47
47
  it { should have_many(:events).class_name('Mdm::SessionEvent').dependent(:delete_all) }
48
48
  it { should have_many(:routes).class_name('Mdm::Route').dependent(:delete_all) }
49
49
  it { should have_one(:workspace).class_name('Mdm::Workspace').through(:host) }
50
+ it { should have_many(:task_sessions).class_name('Mdm::TaskSession').dependent(:destroy)}
51
+ it { should have_many(:tasks).class_name('Mdm::Task').through(:task_sessions)}
50
52
  end
51
53
 
52
54
  context 'scopes' do
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::TaskSession do
4
+
5
+ context 'factory' do
6
+ it 'should be valid' do
7
+ task_session = FactoryGirl.build(:mdm_task_session)
8
+ task_session.should be_valid
9
+ end
10
+ end
11
+
12
+ context 'database' do
13
+
14
+ context 'timestamps'do
15
+ it { should have_db_column(:created_at).of_type(:datetime).with_options(:null => false) }
16
+ it { should have_db_column(:updated_at).of_type(:datetime).with_options(:null => false) }
17
+ end
18
+
19
+ context 'columns' do
20
+ it { should have_db_column(:task_id).of_type(:integer).with_options(:null => false) }
21
+ it { should have_db_column(:session_id).of_type(:integer).with_options(:null => false) }
22
+ end
23
+ end
24
+
25
+ context '#destroy' do
26
+ it 'should successfully destroy the object' do
27
+ task_session = FactoryGirl.create(:mdm_task_session)
28
+ expect {
29
+ task_session.destroy
30
+ }.to_not raise_error
31
+ expect {
32
+ task_session.reload
33
+ }.to raise_error(ActiveRecord::RecordNotFound)
34
+ end
35
+ end
36
+
37
+ context "validations" do
38
+ it "should not allow duplicate associations" do
39
+ task = FactoryGirl.build(:mdm_task)
40
+ session = FactoryGirl.build(:mdm_session)
41
+ FactoryGirl.create(:mdm_task_session, :task => task, :session => session)
42
+ task_session2 = FactoryGirl.build(:mdm_task_session, :task => task, :session => session)
43
+ task_session2.should_not be_valid
44
+ end
45
+ end
46
+
47
+ end
@@ -48,12 +48,15 @@ describe Mdm::Task do
48
48
  context "Associations" do
49
49
  it { should have_many(:task_creds).class_name('Mdm::TaskCred').dependent(:destroy) }
50
50
  it { should have_many(:creds).class_name('Mdm::Cred').through(:task_creds) }
51
+ it { should have_many(:task_sessions).class_name('Mdm::TaskSession').dependent(:destroy) }
52
+ it { should have_many(:sessions).class_name('Mdm::Session').through(:task_sessions) }
51
53
  it { should have_many(:task_hosts).class_name('Mdm::TaskHost').dependent(:destroy) }
52
54
  it { should have_many(:hosts).class_name('Mdm::Host').through(:task_hosts) }
53
55
  it { should have_many(:task_services).class_name('Mdm::TaskService').dependent(:destroy) }
54
56
  it { should have_many(:services).class_name('Mdm::Service').through(:task_services) }
55
57
  it { should belong_to(:workspace).class_name('Mdm::Workspace') }
56
58
  it { should have_many(:reports).class_name('Mdm::Report')}
59
+
57
60
  end
58
61
 
59
62
  context 'scopes' do
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20130531144949) do
14
+ ActiveRecord::Schema.define(:version => 20130604145732) do
15
15
 
16
16
  create_table "api_keys", :force => true do |t|
17
17
  t.text "token"
@@ -440,6 +440,13 @@ ActiveRecord::Schema.define(:version => 20130531144949) do
440
440
  t.datetime "updated_at", :null => false
441
441
  end
442
442
 
443
+ create_table "task_sessions", :force => true do |t|
444
+ t.integer "task_id", :null => false
445
+ t.integer "session_id", :null => false
446
+ t.datetime "created_at", :null => false
447
+ t.datetime "updated_at", :null => false
448
+ end
449
+
443
450
  create_table "tasks", :force => true do |t|
444
451
  t.integer "workspace_id", :default => 1, :null => false
445
452
  t.string "created_by"
@@ -0,0 +1,8 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :mdm_task_session, :class => 'Mdm::TaskSession' do
5
+ association :task, :factory => :mdm_task
6
+ association :session, :factory => :mdm_session
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metasploit_data_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.16.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -183,6 +183,7 @@ files:
183
183
  - app/models/mdm/task_cred.rb
184
184
  - app/models/mdm/task_host.rb
185
185
  - app/models/mdm/task_service.rb
186
+ - app/models/mdm/task_session.rb
186
187
  - app/models/mdm/user.rb
187
188
  - app/models/mdm/vuln.rb
188
189
  - app/models/mdm/vuln_attempt.rb
@@ -304,6 +305,7 @@ files:
304
305
  - db/migrate/20130525015035_remove_campaign_id_from_clients.rb
305
306
  - db/migrate/20130525212420_drop_table_imported_creds.rb
306
307
  - db/migrate/20130531144949_making_host_tags_a_real_ar_model.rb
308
+ - db/migrate/20130604145732_create_task_sessions.rb
307
309
  - lib/mdm.rb
308
310
  - lib/mdm/host/operating_system_normalization.rb
309
311
  - lib/mdm/module.rb
@@ -349,6 +351,7 @@ files:
349
351
  - spec/app/models/mdm/task_creds_spec.rb
350
352
  - spec/app/models/mdm/task_host_spec.rb
351
353
  - spec/app/models/mdm/task_service_spec.rb
354
+ - spec/app/models/mdm/task_sessions_spec.rb
352
355
  - spec/app/models/mdm/task_spec.rb
353
356
  - spec/app/models/mdm/user_spec.rb
354
357
  - spec/app/models/mdm/vuln_attempt_spec.rb
@@ -431,6 +434,7 @@ files:
431
434
  - spec/factories/mdm/task_creds.rb
432
435
  - spec/factories/mdm/task_hosts.rb
433
436
  - spec/factories/mdm/task_services.rb
437
+ - spec/factories/mdm/task_sessions.rb
434
438
  - spec/factories/mdm/users.rb
435
439
  - spec/factories/mdm/vuln_attempts.rb
436
440
  - spec/factories/mdm/vuln_details.rb
@@ -459,7 +463,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
459
463
  version: '0'
460
464
  segments:
461
465
  - 0
462
- hash: -101221162605948507
466
+ hash: 2477374481960221523
463
467
  required_rubygems_version: !ruby/object:Gem::Requirement
464
468
  none: false
465
469
  requirements:
@@ -468,7 +472,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
468
472
  version: '0'
469
473
  segments:
470
474
  - 0
471
- hash: -101221162605948507
475
+ hash: 2477374481960221523
472
476
  requirements: []
473
477
  rubyforge_project:
474
478
  rubygems_version: 1.8.25
@@ -507,6 +511,7 @@ test_files:
507
511
  - spec/app/models/mdm/task_creds_spec.rb
508
512
  - spec/app/models/mdm/task_host_spec.rb
509
513
  - spec/app/models/mdm/task_service_spec.rb
514
+ - spec/app/models/mdm/task_sessions_spec.rb
510
515
  - spec/app/models/mdm/task_spec.rb
511
516
  - spec/app/models/mdm/user_spec.rb
512
517
  - spec/app/models/mdm/vuln_attempt_spec.rb
@@ -589,6 +594,7 @@ test_files:
589
594
  - spec/factories/mdm/task_creds.rb
590
595
  - spec/factories/mdm/task_hosts.rb
591
596
  - spec/factories/mdm/task_services.rb
597
+ - spec/factories/mdm/task_sessions.rb
592
598
  - spec/factories/mdm/users.rb
593
599
  - spec/factories/mdm/vuln_attempts.rb
594
600
  - spec/factories/mdm/vuln_details.rb