@@ -20,7 +20,7 @@ class Metasploit3
20
20
21
21
let ( :module_content ) do
22
22
<<-EOS
23
- class Metasploit3 < Msf::Auxiliary
23
+ class Metasploit3 < Msf::Auxiliary
24
24
# fully-qualified name is Msf::GoodRanking, so this will failing if lexical scope is not captured
25
25
Rank = GoodRanking
26
26
end
@@ -106,10 +106,10 @@ class Metasploit3 < Msf::Auxiliary
106
106
let ( :namespace_module ) do
107
107
Object . module_eval (
108
108
<<-EOS
109
- module #{ namespace_module_names [ 0 ] }
109
+ module #{ namespace_module_names [ 0 ] }
110
110
module #{ namespace_module_names [ 1 ] }
111
111
module #{ namespace_module_names [ 2 ] }
112
- #{ described_class ::NAMESPACE_MODULE_CONTENT }
112
+ #{ described_class ::NAMESPACE_MODULE_CONTENT }
113
113
end
114
114
end
115
115
end
@@ -255,18 +255,27 @@ module #{namespace_module_names[2]}
255
255
subject . stub ( :module_path => module_path )
256
256
end
257
257
258
- it 'should return false if :force is false and the file has not been changed' do
259
- module_manager . stub ( :file_changed? => false )
260
-
261
- subject . load_module ( parent_path , type , module_reference_name , :force => false ) . should be_false
262
- end
263
-
264
258
it 'should call file_changed? with the module_path' do
265
259
module_manager . should_receive ( :file_changed? ) . with ( module_path ) . and_return ( false )
266
260
267
261
subject . load_module ( parent_path , type , module_reference_name , :force => false )
268
262
end
269
263
264
+ context 'without file changed' do
265
+ before ( :each ) do
266
+ module_manager . stub ( :file_changed? => false )
267
+ end
268
+
269
+ it 'should return false if :force is false' do
270
+ subject . load_module ( parent_path , type , module_reference_name , :force => false ) . should be_false
271
+ end
272
+
273
+ it 'should not call #read_module_content' do
274
+ subject . should_not_receive ( :read_module_content )
275
+ subject . load_module ( parent_path , type , module_reference_name )
276
+ end
277
+ end
278
+
270
279
context 'with file changed' do
271
280
let ( :module_full_name ) do
272
281
File . join ( 'auxiliary' , module_reference_name )
@@ -355,7 +364,7 @@ class Metasploit3 < Msf::Auxiliary
355
364
end
356
365
357
366
it 'should not attempt to make a new namespace_module' do
358
- subject . should_not_receive ( :namespace_module_transaction )
367
+ subject . should_not_receive ( :namespace_module_transaction )
359
368
subject . load_module ( parent_path , type , module_reference_name ) . should be_false
360
369
end
361
370
end
@@ -384,7 +393,7 @@ class Metasploit3 < Msf::Auxiliary
384
393
let ( :backtrace ) do
385
394
[
386
395
'Backtrace Line 1' ,
387
- 'Backtrace Line 2'
396
+ 'Backtrace Line 2'
388
397
]
389
398
end
390
399
@@ -424,9 +433,9 @@ class Metasploit3 < Msf::Auxiliary
424
433
let ( :version_compatibility_error ) do
425
434
Msf ::Modules ::VersionCompatibilityError . new (
426
435
:module_path => module_path ,
427
- :module_reference_name => module_reference_name ,
428
- :minimum_api_version => infinity ,
429
- :minimum_core_version => infinity
436
+ :module_reference_name => module_reference_name ,
437
+ :minimum_api_version => infinity ,
438
+ :minimum_core_version => infinity
430
439
)
431
440
end
432
441
@@ -509,7 +518,7 @@ class Metasploit3 < Msf::Auxiliary
509
518
end
510
519
511
520
it 'should record the load error' do
512
- subject . should_receive ( :load_error ) . with ( module_path , version_compatibility_error )
521
+ subject . should_receive ( :load_error ) . with ( module_path , version_compatibility_error )
513
522
subject . load_module ( parent_path , type , module_reference_name ) . should be_false
514
523
end
515
524
@@ -621,87 +630,6 @@ class Metasploit3 < Msf::Auxiliary
621
630
subject . load_module ( parent_path , type , module_reference_name ) . should be_true
622
631
end
623
632
624
- context 'with module_reference_name already in module_manager' do
625
- let ( :framework ) do
626
- framework = mock ( 'Framework' , :datastore => { } )
627
- framework . stub_chain ( :events , :on_module_load )
628
-
629
- framework
630
- end
631
-
632
- let ( :metasploit_class ) do
633
- @original_namespace_module ::Metasploit3
634
- end
635
-
636
- let ( :module_manager ) do
637
- Msf ::ModuleManager . new ( framework )
638
- end
639
-
640
- before ( :each ) do
641
- # remove the stub from before(:each) in context 'with version compatibility'
642
- module_manager . unstub ( :on_module_load )
643
-
644
- # remove the stubs from before(:each) in context 'with file changed'
645
- module_manager . unstub ( :delete )
646
- module_manager . unstub ( :module_set )
647
- end
648
-
649
- it 'should not cause an ambiguous module_reference_name in the module_manager' do
650
- module_manager [ module_reference_name ] = metasploit_class
651
-
652
- subject . load_module ( parent_path , type , module_reference_name ) . should be_true
653
- module_manager . send ( :ambiguous_module_reference_name_set ) . should be_empty
654
- end
655
-
656
- it 'should not cause an ambiguous module_reference_name in the type module_set' do
657
- module_set = module_manager . module_set ( type )
658
- module_set [ module_reference_name ] = metasploit_class
659
-
660
- subject . load_module ( parent_path , type , module_reference_name ) . should be_true
661
- module_set . send ( :ambiguous_module_reference_name_set ) . should be_empty
662
- end
663
-
664
- context 'without file changed' do
665
- before ( :each ) do
666
- module_manager . stub ( :file_changed => false )
667
- end
668
-
669
- context 'with :force => true' do
670
- it 'should not cause an ambiguous module_reference_name in the module_manager' do
671
- module_manager [ module_reference_name ] = metasploit_class
672
-
673
- subject . load_module ( parent_path , type , module_reference_name , :force => true ) . should be_true
674
- module_manager . send ( :ambiguous_module_reference_name_set ) . should be_empty
675
- end
676
-
677
- it 'should not cause an ambiguous module_reference_name in the type module_set' do
678
- module_set = module_manager . module_set ( type )
679
- module_set [ module_reference_name ] = metasploit_class
680
-
681
- subject . load_module ( parent_path , type , module_reference_name , :force => true ) . should be_true
682
- module_set . send ( :ambiguous_module_reference_name_set ) . should be_empty
683
- end
684
- end
685
-
686
- context 'with :reload => true' do
687
- it 'should not cause an ambiguous module_reference_name in the module_manager' do
688
- module_manager [ module_reference_name ] = metasploit_class
689
-
690
- subject . load_module ( parent_path , type , module_reference_name , :reload => true ) . should be_true
691
- module_manager . send ( :ambiguous_module_reference_name_set ) . should be_empty
692
- end
693
-
694
- it 'should not cause an ambiguous module_reference_name in the type module_set' do
695
- module_set = module_manager . module_set ( type )
696
- module_set [ module_reference_name ] = metasploit_class
697
-
698
- subject . load_module ( parent_path , type , module_reference_name , :reload => true ) . should be_true
699
- module_set . send ( :ambiguous_module_reference_name_set ) . should be_empty
700
- end
701
- end
702
- end
703
- end
704
-
705
633
it 'should call module_manager.on_module_load' do
706
634
module_manager . should_receive ( :on_module_load )
707
635
subject . load_module ( parent_path , type , module_reference_name ) . should be_true
@@ -728,9 +656,9 @@ class Metasploit3 < Msf::Auxiliary
728
656
count_by_type . has_key? ( type ) . should be_false
729
657
subject . load_module (
730
658
parent_path ,
731
- type ,
732
- module_reference_name ,
733
- :count_by_type => count_by_type
659
+ type ,
660
+ module_reference_name ,
661
+ :count_by_type => count_by_type
734
662
) . should be_true
735
663
count_by_type [ type ] . should == 1
736
664
end
@@ -743,9 +671,9 @@ class Metasploit3 < Msf::Auxiliary
743
671
744
672
subject . load_module (
745
673
parent_path ,
746
- type ,
747
- module_reference_name ,
748
- :count_by_type => count_by_type
674
+ type ,
675
+ module_reference_name ,
676
+ :count_by_type => count_by_type
749
677
) . should be_true
750
678
751
679
incremented_count = original_count + 1
@@ -763,8 +691,8 @@ class Metasploit3 < Msf::Auxiliary
763
691
let ( :namespace_module_names ) do
764
692
[
765
693
'Msf' ,
766
- 'Modules' ,
767
- relative_name
694
+ 'Modules' ,
695
+ relative_name
768
696
]
769
697
end
770
698
@@ -794,8 +722,8 @@ class Metasploit3 < Msf::Auxiliary
794
722
"end\n " \
795
723
"end\n " \
796
724
"end" ,
797
- anything ,
798
- anything
725
+ anything ,
726
+ anything
799
727
)
800
728
801
729
namespace_module = mock ( 'Namespace Module' )
@@ -810,8 +738,8 @@ class Metasploit3 < Msf::Auxiliary
810
738
:module_eval
811
739
) . with (
812
740
anything ,
813
- described_class_pathname . to_s ,
814
- anything
741
+ described_class_pathname . to_s ,
742
+ anything
815
743
)
816
744
817
745
namespace_module = mock ( 'Namespace Module' )
@@ -826,8 +754,8 @@ class Metasploit3 < Msf::Auxiliary
826
754
:module_eval
827
755
) . with (
828
756
anything ,
829
- anything ,
830
- described_class ::NAMESPACE_MODULE_LINE - namespace_module_names . length
757
+ anything ,
758
+ described_class ::NAMESPACE_MODULE_LINE - namespace_module_names . length
831
759
)
832
760
833
761
namespace_module = mock ( 'Namespace Module' )
@@ -861,7 +789,7 @@ class Metasploit3 < Msf::Auxiliary
861
789
'Mod0'
862
790
end
863
791
864
- before ( :each ) do
792
+ before ( :each ) do
865
793
# copy to local variable so it is accessible in instance_eval
866
794
relative_name = self . relative_name
867
795
@@ -870,7 +798,7 @@ class Metasploit3 < Msf::Auxiliary
870
798
remove_const relative_name
871
799
end
872
800
end
873
- end
801
+ end
874
802
875
803
it 'should return nil if the module is not defined' do
876
804
Msf ::Modules . const_defined? ( relative_name ) . should be_false
@@ -1019,7 +947,7 @@ class Metasploit3
1019
947
end
1020
948
1021
949
it 'should remove the pre-existing namespace module' do
1022
- Msf ::Modules . should_receive ( :remove_const ) . with ( relative_name )
950
+ Msf ::Modules . should_receive ( :remove_const ) . with ( relative_name )
1023
951
1024
952
subject . send ( :namespace_module_transaction , module_full_name ) do |namespace_module |
1025
953
true
@@ -1129,13 +1057,13 @@ class Metasploit3
1129
1057
end
1130
1058
1131
1059
it 'should create a new namespace module' do
1132
- expect {
1133
- Msf ::Modules . const_get ( relative_name )
1134
- } . to raise_error ( NameError )
1060
+ expect {
1061
+ Msf ::Modules . const_get ( relative_name )
1062
+ } . to raise_error ( NameError )
1135
1063
1136
- subject . send ( :namespace_module_transaction , module_full_name ) do |namespace_module |
1137
- Msf ::Modules . const_get ( relative_name ) . should == namespace_module
1138
- end
1064
+ subject . send ( :namespace_module_transaction , module_full_name ) do |namespace_module |
1065
+ Msf ::Modules . const_get ( relative_name ) . should == namespace_module
1066
+ end
1139
1067
end
1140
1068
1141
1069
context 'with an Exception from the block' do
@@ -1200,7 +1128,7 @@ class Metasploit3
1200
1128
subject . send ( :namespace_module_transaction , module_full_name ) do |namespace_module |
1201
1129
Msf ::Modules . const_defined? ( relative_name ) . should be_true
1202
1130
1203
- created_namespace_module = namespace_module
1131
+ created_namespace_module = namespace_module
1204
1132
1205
1133
true
1206
1134
end
@@ -1344,7 +1272,7 @@ class Metasploit2
1344
1272
1345
1273
subject . send ( :restore_namespace_module , parent_module , relative_name , @original_namespace_module )
1346
1274
1347
- parent_module . const_defined? ( relative_name ) . should be_true
1275
+ parent_module . const_defined? ( relative_name ) . should be_true
1348
1276
parent_module . const_get ( relative_name ) . should == @original_namespace_module
1349
1277
end
1350
1278
end
@@ -1353,10 +1281,10 @@ class Metasploit2
1353
1281
1354
1282
context '#typed_path' do
1355
1283
it 'should delegate to the class method' do
1356
- type = Msf ::MODULE_EXPLOIT
1284
+ type = Msf ::MODULE_EXPLOIT
1357
1285
1358
- described_class . should_receive ( :typed_path ) . with ( type , module_reference_name )
1359
- subject . send ( :typed_path , type , module_reference_name )
1286
+ described_class . should_receive ( :typed_path ) . with ( type , module_reference_name )
1287
+ subject . send ( :typed_path , type , module_reference_name )
1360
1288
end
1361
1289
end
1362
1290
@@ -1405,4 +1333,4 @@ class Metasploit2
1405
1333
end
1406
1334
end
1407
1335
end
1408
- end
1336
+ end
0 commit comments