metasploit-credential 0.14.5 → 0.14.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metasploit/credential/exporter/core.rb +2 -2
  3. data/lib/metasploit/credential/exporter/pwdump.rb +2 -2
  4. data/lib/metasploit/credential/migrator.rb +1 -1
  5. data/lib/metasploit/credential/version.rb +1 -3
  6. data/spec/dummy/config/database.yml +13 -11
  7. data/spec/dummy/db/structure.sql +1 -0
  8. data/spec/lib/metasploit/credential/creation_spec.rb +6 -8
  9. data/spec/lib/metasploit/credential/exporter/core_spec.rb +100 -85
  10. data/spec/lib/metasploit/credential/exporter/pwdump_spec.rb +14 -16
  11. data/spec/lib/metasploit/credential/importer/core_spec.rb +10 -12
  12. data/spec/lib/metasploit/credential/importer/multi_spec.rb +4 -6
  13. data/spec/lib/metasploit/credential/importer/pwdump_spec.rb +11 -13
  14. data/spec/lib/metasploit/credential/importer/zip_spec.rb +5 -7
  15. data/spec/lib/metasploit/credential/migrator_spec.rb +13 -13
  16. data/spec/lib/metasploit/credential/version_spec.rb +3 -5
  17. data/spec/lib/metasploit/credential_spec.rb +1 -3
  18. data/spec/models/mdm/service_spec.rb +3 -5
  19. data/spec/models/mdm/session_spec.rb +2 -4
  20. data/spec/models/mdm/task_spec.rb +4 -6
  21. data/spec/models/mdm/user_spec.rb +2 -4
  22. data/spec/models/mdm/workspace_spec.rb +2 -4
  23. data/spec/models/metasploit/credential/blank_username_spec.rb +5 -7
  24. data/spec/models/metasploit/credential/core_spec.rb +43 -45
  25. data/spec/models/metasploit/credential/login/status_spec.rb +19 -21
  26. data/spec/models/metasploit/credential/login_spec.rb +36 -38
  27. data/spec/models/metasploit/credential/nonreplayable_hash_spec.rb +3 -5
  28. data/spec/models/metasploit/credential/ntlm_hash_spec.rb +13 -15
  29. data/spec/models/metasploit/credential/origin/cracked_password_spec.rb +5 -7
  30. data/spec/models/metasploit/credential/origin/import_spec.rb +8 -10
  31. data/spec/models/metasploit/credential/origin/manual_spec.rb +7 -9
  32. data/spec/models/metasploit/credential/origin/service_spec.rb +10 -12
  33. data/spec/models/metasploit/credential/origin/session_spec.rb +11 -13
  34. data/spec/models/metasploit/credential/password_hash_spec.rb +4 -6
  35. data/spec/models/metasploit/credential/password_spec.rb +3 -5
  36. data/spec/models/metasploit/credential/postgres_md5_spec.rb +4 -6
  37. data/spec/models/metasploit/credential/private_spec.rb +8 -10
  38. data/spec/models/metasploit/credential/public_spec.rb +5 -7
  39. data/spec/models/metasploit/credential/realm_spec.rb +14 -16
  40. data/spec/models/metasploit/credential/replayable_hash_spec.rb +3 -5
  41. data/spec/models/metasploit/credential/ssh_key_spec.rb +15 -17
  42. data/spec/models/metasploit/credential/username_spec.rb +6 -8
  43. data/spec/models/metasploit_data_models/search/visitor/relation_spec.rb +1 -3
  44. data/spec/spec_helper.rb +83 -18
  45. data/spec/support/shared/contexts/mdm/workspace.rb +1 -1
  46. data/spec/support/shared/examples/core_validations.rb +117 -42
  47. data/spec/support/shared/examples/single_table_inheritance_database_columns.rb +2 -2
  48. data/spec/support/shared/examples/timestamp_database_column.rb +2 -2
  49. metadata +9 -9
@@ -1,30 +1,28 @@
1
- require 'spec_helper'
2
-
3
- describe Metasploit::Credential::Username do
1
+ RSpec.describe Metasploit::Credential::Username, type: :model do
4
2
  it_should_behave_like 'Metasploit::Concern.run'
5
3
 
6
4
  context 'database' do
7
5
  context 'columns' do
8
6
  it_should_behave_like 'timestamp database columns'
9
7
 
10
- it { should have_db_column(:username).of_type(:string).with_options(null: false) }
8
+ it { is_expected.to have_db_column(:username).of_type(:string).with_options(null: false) }
11
9
  end
12
10
 
13
11
  context 'indices' do
14
- it { should have_db_index(:username).unique(true) }
12
+ it { is_expected.to have_db_index(:username).unique(true) }
15
13
  end
16
14
  end
17
15
 
18
16
  context 'mass assignment security' do
19
17
  it { should_not allow_mass_assignment_of(:created_at) }
20
18
  it { should_not allow_mass_assignment_of(:updated_at) }
21
- it { should allow_mass_assignment_of(:username) }
19
+ it { is_expected.to allow_mass_assignment_of(:username) }
22
20
  end
23
21
 
24
22
  context 'validations' do
25
23
  context 'username' do
26
- it { should validate_presence_of :username }
27
- it { should validate_uniqueness_of :username }
24
+ it { is_expected.to validate_presence_of :username }
25
+ it { is_expected.to validate_uniqueness_of :username }
28
26
  end
29
27
  end
30
28
 
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe MetasploitDataModels::Search::Visitor::Relation do
1
+ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
4
2
  subject(:visitor) {
5
3
  described_class.new(
6
4
  query: query
data/spec/spec_helper.rb CHANGED
@@ -39,31 +39,96 @@ rooteds.each do |rooted|
39
39
  end
40
40
  end
41
41
 
42
+
43
+ # This file was generated by the `rspec --init` command. Conventionally, all
44
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
45
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
46
+ # this file to always be loaded, without a need to explicitly require it in any
47
+ # files.
48
+ #
49
+ # Given that it is always loaded, you are encouraged to keep this file as
50
+ # light-weight as possible. Requiring heavyweight dependencies from this file
51
+ # will add to the boot time of your test suite on EVERY test run, even for an
52
+ # individual file that may not need all of that loaded. Instead, consider making
53
+ # a separate helper file that requires the additional dependencies and performs
54
+ # the additional setup, and require it from the spec files that actually need
55
+ # it.
56
+ #
57
+ # The `.rspec` file also contains a few flags that are not defaults but that
58
+ # users commonly want.
59
+ #
60
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
42
61
  RSpec.configure do |config|
43
- # ## Mock Framework
44
- #
45
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
46
- #
47
- # config.mock_with :mocha
48
- # config.mock_with :flexmock
49
- # config.mock_with :rr
62
+ # rspec-expectations config goes here. You can use an alternate
63
+ # assertion/expectation library such as wrong or the stdlib/minitest
64
+ # assertions if you prefer.
65
+ config.expect_with :rspec do |expectations|
66
+ # This option will default to `true` in RSpec 4. It makes the `description`
67
+ # and `failure_message` of custom matchers include text for helper methods
68
+ # defined using `chain`, e.g.:
69
+ # be_bigger_than(2).and_smaller_than(4).description
70
+ # # => "be bigger than 2 and smaller than 4"
71
+ # ...rather than:
72
+ # # => "be bigger than 2"
73
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
74
+ end
50
75
 
51
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
52
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
76
+ # rspec-mocks config goes here. You can use an alternate test double
77
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
78
+ config.mock_with :rspec do |mocks|
79
+ # Prevents you from mocking or stubbing a method that does not exist on
80
+ # a real object. This is generally recommended, and will default to
81
+ # `true` in RSpec 4.
82
+ mocks.verify_partial_doubles = true
83
+ end
53
84
 
54
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
55
- # examples within a transaction, remove the following line or assign false
56
- # instead of true.
57
- config.use_transactional_fixtures = true
85
+ # These two settings work together to allow you to limit a spec run
86
+ # to individual examples or groups you care about by tagging them with
87
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
88
+ # get run.
89
+ config.filter_run :focus
90
+ config.run_all_when_everything_filtered = true
58
91
 
59
- # If true, the base class of anonymous controllers will be inferred
60
- # automatically. This will be the default behavior in future versions of
61
- # rspec-rails.
62
- config.infer_base_class_for_anonymous_controllers = false
92
+ # Limits the available syntax to the non-monkey patched syntax that is
93
+ # recommended. For more details, see:
94
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
95
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
96
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
97
+ config.disable_monkey_patching!
98
+
99
+ # This setting enables warnings. It's recommended, but in some cases may
100
+ # be too noisy due to issues in dependencies.
101
+ config.warnings = true
102
+
103
+ # Many RSpec users commonly either run the entire suite or an individual
104
+ # file, and it's useful to allow more verbose output when running an
105
+ # individual spec file.
106
+ if config.files_to_run.one?
107
+ # Use the documentation formatter for detailed output,
108
+ # unless a formatter has already been configured
109
+ # (e.g. via a command-line flag).
110
+ config.default_formatter = 'doc'
111
+ end
112
+
113
+ # Print the 10 slowest examples and example groups at the
114
+ # end of the spec run, to help surface which specs are running
115
+ # particularly slow.
116
+ config.profile_examples = 10
63
117
 
64
118
  # Run specs in random order to surface order dependencies. If you find an
65
119
  # order dependency and want to debug it, you can fix the order by providing
66
120
  # the seed, which is printed after each run.
67
121
  # --seed 1234
68
- config.order = "random"
122
+ config.order = :random
123
+
124
+ # Seed global randomization in this process using the `--seed` CLI option.
125
+ # Setting this allows you to use `--seed` to deterministically reproduce
126
+ # test failures related to randomization by passing the same `--seed` value
127
+ # as the one that triggered the failure.
128
+ Kernel.srand config.seed
129
+
130
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
131
+ # examples within a transaction, remove the following line or assign false
132
+ # instead of true.
133
+ config.use_transactional_fixtures = true
69
134
  end
@@ -1,6 +1,6 @@
1
1
  shared_context 'Mdm::Workspace' do
2
2
  before(:each) do
3
3
  # TODO remove Rex usage from Mdm as it is not a declared dependency
4
- Mdm::Workspace.any_instance.stub(:valid_ip_or_range?).and_return(true)
4
+ allow_any_instance_of(Mdm::Workspace).to receive(:valid_ip_or_range?).and_return(true)
5
5
  end
6
6
  end
@@ -51,18 +51,6 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
51
51
  # lets
52
52
  #
53
53
 
54
- let(:first_private) {
55
- FactoryGirl.create(:metasploit_credential_private)
56
- }
57
-
58
- let(:first_public) {
59
- FactoryGirl.create(:metasploit_credential_username)
60
- }
61
-
62
- let(:first_realm) {
63
- FactoryGirl.create(:metasploit_credential_realm)
64
- }
65
-
66
54
  let(:first_workspace) {
67
55
  FactoryGirl.create(:mdm_workspace)
68
56
  }
@@ -96,27 +84,10 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
96
84
  }
97
85
  }
98
86
 
99
-
100
87
  let(:second_metasploit_credential_core) {
101
88
  FactoryGirl.build( factory_name, second_factory_options)
102
89
  }
103
90
 
104
- let(:second_private) {
105
- FactoryGirl.create(:metasploit_credential_private)
106
- }
107
-
108
- let(:second_public) {
109
- FactoryGirl.create(:metasploit_credential_username)
110
- }
111
-
112
- let(:second_realm) {
113
- FactoryGirl.create(:metasploit_credential_realm)
114
- }
115
-
116
- let(:second_workspace) {
117
- FactoryGirl.create(:mdm_workspace)
118
- }
119
-
120
91
  #
121
92
  # let!s
122
93
  #
@@ -129,6 +100,26 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
129
100
  context 'database' do
130
101
  context 'indices' do
131
102
  context 'foreign keys' do
103
+ let(:first_private) {
104
+ FactoryGirl.create(:metasploit_credential_private)
105
+ }
106
+
107
+ let(:second_public) {
108
+ FactoryGirl.create(:metasploit_credential_username)
109
+ }
110
+
111
+ let(:second_private) {
112
+ FactoryGirl.create(:metasploit_credential_private)
113
+ }
114
+
115
+ let(:second_realm) {
116
+ FactoryGirl.create(:metasploit_credential_realm)
117
+ }
118
+
119
+ let(:second_workspace) {
120
+ FactoryGirl.create(:mdm_workspace)
121
+ }
122
+
132
123
  shared_examples_for 'potential collision' do |options={}|
133
124
  options.assert_valid_keys(:collision, :index)
134
125
 
@@ -198,6 +189,10 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
198
189
  nil
199
190
  }
200
191
 
192
+ let(:first_public) {
193
+ FactoryGirl.create(:metasploit_credential_username)
194
+ }
195
+
201
196
  let(:first_realm) {
202
197
  nil
203
198
  }
@@ -224,6 +219,10 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
224
219
 
225
220
  options.assert_valid_keys(:collision, :private, :public, :workspace)
226
221
 
222
+ let(:first_public) {
223
+ FactoryGirl.create(:metasploit_credential_username)
224
+ }
225
+
227
226
  let(:first_realm) {
228
227
  nil
229
228
  }
@@ -252,6 +251,10 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
252
251
  nil
253
252
  }
254
253
 
254
+ let(:first_realm) {
255
+ FactoryGirl.create(:metasploit_credential_realm)
256
+ }
257
+
255
258
  let(:second_public) {
256
259
  nil
257
260
  }
@@ -276,6 +279,14 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
276
279
  nil
277
280
  }
278
281
 
282
+ let(:first_public) {
283
+ FactoryGirl.create(:metasploit_credential_username)
284
+ }
285
+
286
+ let(:first_realm) {
287
+ FactoryGirl.create(:metasploit_credential_realm)
288
+ }
289
+
279
290
  let(:second_private) {
280
291
  nil
281
292
  }
@@ -296,6 +307,14 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
296
307
 
297
308
  options.assert_valid_keys(:collision, :private, :public, :realm, :workspace)
298
309
 
310
+ let(:first_public) {
311
+ FactoryGirl.create(:metasploit_credential_username)
312
+ }
313
+
314
+ let(:first_realm) {
315
+ FactoryGirl.create(:metasploit_credential_realm)
316
+ }
317
+
299
318
  context_with_correlation(options, :workspace) do
300
319
  context_with_correlation(options, :realm) do
301
320
  context_with_correlation(options, :public) do
@@ -566,9 +585,29 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
566
585
  end
567
586
 
568
587
  context 'validations' do
569
- it { should validate_presence_of :workspace }
588
+ it { is_expected.to validate_presence_of :workspace }
570
589
 
571
590
  context 'of uniqueness' do
591
+ let(:first_private) {
592
+ FactoryGirl.create(:metasploit_credential_private)
593
+ }
594
+
595
+ let(:second_public) {
596
+ FactoryGirl.create(:metasploit_credential_username)
597
+ }
598
+
599
+ let(:second_private) {
600
+ FactoryGirl.create(:metasploit_credential_private)
601
+ }
602
+
603
+ let(:second_realm) {
604
+ FactoryGirl.create(:metasploit_credential_realm)
605
+ }
606
+
607
+ let(:second_workspace) {
608
+ FactoryGirl.create(:mdm_workspace)
609
+ }
610
+
572
611
  shared_examples_for 'potential collision' do |options={}|
573
612
  options.assert_valid_keys(:attribute, :collision, :message)
574
613
 
@@ -590,7 +629,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
590
629
  ).to include options.fetch(:message)
591
630
  end
592
631
  else
593
- it { should be_valid }
632
+ it { is_expected.to be_valid }
594
633
  end
595
634
  end
596
635
 
@@ -642,6 +681,10 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
642
681
  nil
643
682
  }
644
683
 
684
+ let(:first_public) {
685
+ FactoryGirl.create(:metasploit_credential_username)
686
+ }
687
+
645
688
  let(:first_realm) {
646
689
  nil
647
690
  }
@@ -673,6 +716,10 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
673
716
  nil
674
717
  }
675
718
 
719
+ let(:first_public) {
720
+ FactoryGirl.create(:metasploit_credential_username)
721
+ }
722
+
676
723
  let(:second_realm) {
677
724
  nil
678
725
  }
@@ -698,6 +745,10 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
698
745
  nil
699
746
  }
700
747
 
748
+ let(:first_realm) {
749
+ FactoryGirl.create(:metasploit_credential_realm)
750
+ }
751
+
701
752
  let(:second_public) {
702
753
  nil
703
754
  }
@@ -723,6 +774,14 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
723
774
  nil
724
775
  }
725
776
 
777
+ let(:first_public) {
778
+ FactoryGirl.create(:metasploit_credential_username)
779
+ }
780
+
781
+ let(:first_realm) {
782
+ FactoryGirl.create(:metasploit_credential_realm)
783
+ }
784
+
726
785
  let(:second_private) {
727
786
  nil
728
787
  }
@@ -744,6 +803,14 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
744
803
 
745
804
  options.assert_valid_keys(:collision, :private, :public, :realm, :workspace)
746
805
 
806
+ let(:first_public) {
807
+ FactoryGirl.create(:metasploit_credential_username)
808
+ }
809
+
810
+ let(:first_realm) {
811
+ FactoryGirl.create(:metasploit_credential_realm)
812
+ }
813
+
747
814
  context_with_correlation(options, :workspace) do
748
815
  context_with_correlation(options, :realm) do
749
816
  context_with_correlation(options, :public) do
@@ -1027,6 +1094,14 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1027
1094
  second_metasploit_credential_core
1028
1095
  }
1029
1096
 
1097
+ let(:first_public) {
1098
+ FactoryGirl.create(:metasploit_credential_username)
1099
+ }
1100
+
1101
+ let(:first_realm) {
1102
+ FactoryGirl.create(:metasploit_credential_realm)
1103
+ }
1104
+
1030
1105
  let(:second_private) {
1031
1106
  first_private
1032
1107
  }
@@ -1053,7 +1128,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1053
1128
  nil
1054
1129
  }
1055
1130
 
1056
- it { should be_valid }
1131
+ it { is_expected.to be_valid }
1057
1132
  end
1058
1133
 
1059
1134
  context 'with same workspace without realm with same public without private' do
@@ -1065,7 +1140,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1065
1140
  nil
1066
1141
  }
1067
1142
 
1068
- it { should be_valid }
1143
+ it { is_expected.to be_valid }
1069
1144
  end
1070
1145
 
1071
1146
  context 'with same workspace with same realm without public with same private' do
@@ -1073,7 +1148,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1073
1148
  nil
1074
1149
  }
1075
1150
 
1076
- it { should be_valid }
1151
+ it { is_expected.to be_valid }
1077
1152
  end
1078
1153
 
1079
1154
  context 'with same workspace with same realm with same public without private' do
@@ -1085,7 +1160,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1085
1160
  nil
1086
1161
  }
1087
1162
 
1088
- it { should be_valid }
1163
+ it { is_expected.to be_valid }
1089
1164
  end
1090
1165
  end
1091
1166
 
@@ -1107,7 +1182,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1107
1182
  nil
1108
1183
  }
1109
1184
 
1110
- it { should be_valid }
1185
+ it { is_expected.to be_valid }
1111
1186
  end
1112
1187
 
1113
1188
  context 'with same workspace without realm with public with same private' do
@@ -1115,7 +1190,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1115
1190
  FactoryGirl.create(:metasploit_credential_public)
1116
1191
  }
1117
1192
 
1118
- it { should be_valid }
1193
+ it { is_expected.to be_valid }
1119
1194
  end
1120
1195
 
1121
1196
  context 'with same workspace with realm without public with same private' do
@@ -1123,7 +1198,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1123
1198
  FactoryGirl.create(:metasploit_credential_realm)
1124
1199
  }
1125
1200
 
1126
- it { should be_valid }
1201
+ it { is_expected.to be_valid }
1127
1202
  end
1128
1203
  end
1129
1204
 
@@ -1141,7 +1216,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1141
1216
  FactoryGirl.create(:metasploit_credential_private)
1142
1217
  }
1143
1218
 
1144
- it { should be_valid }
1219
+ it { is_expected.to be_valid }
1145
1220
  end
1146
1221
 
1147
1222
  context 'with workspace with realm without public with private' do
@@ -1153,7 +1228,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1153
1228
  FactoryGirl.create(:metasploit_credential_realm)
1154
1229
  }
1155
1230
 
1156
- it { should be_valid}
1231
+ it { is_expected.to be_valid}
1157
1232
  end
1158
1233
  end
1159
1234
 
@@ -1171,7 +1246,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1171
1246
  FactoryGirl.create(:metasploit_credential_realm)
1172
1247
  }
1173
1248
 
1174
- it { should be_valid }
1249
+ it { is_expected.to be_valid }
1175
1250
  end
1176
1251
  end
1177
1252
 
@@ -1189,7 +1264,7 @@ shared_examples_for 'Metasploit::Credential::CoreValidations' do
1189
1264
  FactoryGirl.create(:metasploit_credential_public)
1190
1265
  }
1191
1266
 
1192
- it { should be_valid }
1267
+ it { is_expected.to be_valid }
1193
1268
  end
1194
1269
  end
1195
1270
  end