File tree Expand file tree Collapse file tree 1 file changed +22
-16
lines changed Expand file tree Collapse file tree 1 file changed +22
-16
lines changed Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
1
3
load Metasploit ::Framework . root . join ( 'tools/jsobfu.rb' ) . to_path
2
4
3
5
require 'stringio'
19
21
end
20
22
21
23
describe '#run' do
22
-
23
- def get_stdout ( &block )
24
- out = $stdout
25
- $stdout = fake = StringIO . new
26
- begin
27
- yield
28
- ensure
29
- $stdout = out
30
- end
31
- fake . string
32
- end
33
-
34
24
let ( :default_opts ) {
35
25
{ :input => fname , :iteration => 1 }
36
26
}
37
27
38
28
before ( :each ) do
39
29
allow ( Jsobfu ::OptsConsole ) . to receive ( :parse ) . with ( any_args ) . and_return ( default_opts )
40
30
allow ( File ) . to receive ( :open ) . with ( fname , 'rb' ) . and_yield ( StringIO . new ( js ) )
31
+ @out = $stdout
32
+ $stdout = StringIO . new
33
+ $stdout. string = ''
34
+ end
35
+
36
+ after ( :each ) do
37
+ $stdout = @out
41
38
end
42
39
43
40
context 'when a javascript file is given' do
44
- it 'returns the obfuscated version of the js code' do
45
- output = get_stdout { subject . run }
46
- expect ( output ) . to include ( 'String.fromCharCode' )
41
+ it 'returns an String' do
42
+ subject . run
43
+ expect ( $stdout. string ) . to be_a ( String )
44
+ end
45
+
46
+ it 'returns a non empty String' do
47
+ subject . run
48
+ expect ( $stdout. string ) . not_to be_empty
47
49
end
48
- end
49
50
51
+ it 'returns an String different than the original' do
52
+ subject . run
53
+ expect ( $stdout. string ) . not_to eq ( js )
54
+ end
55
+ end
50
56
end
51
57
end
52
58
You can’t perform that action at this time.
0 commit comments