File tree Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ load Metasploit ::Framework . root . join ( 'tools/jsobfu.rb' ) . to_path
2
+
3
+ require 'stringio'
4
+
5
+ describe Jsobfu do
6
+
7
+ let ( :fname ) {
8
+ 'test.js'
9
+ }
10
+
11
+ let ( :js ) {
12
+ %Q|alert("test");|
13
+ }
14
+
15
+ describe Jsobfu ::Driver do
16
+
17
+ subject do
18
+ Jsobfu ::Driver . new
19
+ end
20
+
21
+ 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
+ let ( :default_opts ) {
35
+ { :input => fname , :iteration => 1 }
36
+ }
37
+
38
+ before ( :each ) do
39
+ allow ( Jsobfu ::OptsConsole ) . to receive ( :parse ) . with ( any_args ) . and_return ( default_opts )
40
+ allow ( File ) . to receive ( :open ) . with ( fname , 'rb' ) . and_yield ( StringIO . new ( js ) )
41
+ end
42
+
43
+ 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' )
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+
54
+ describe Jsobfu ::OptsConsole do
55
+ subject do
56
+ Jsobfu ::OptsConsole
57
+ end
58
+
59
+ context 'when no options are given' do
60
+ it 'raises OptionParser::MissingArgument' do
61
+ expect { subject . parse ( [ ] ) } . to raise_error ( OptionParser ::MissingArgument )
62
+ end
63
+ end
64
+
65
+ context 'when -t isn\'t a number' do
66
+ it 'raises OptionParser::MissingArgument' do
67
+ args = "-i #{ fname } -t NaN" . split
68
+ expect { subject . parse ( args ) } . to raise_error ( OptionParser ::InvalidOption )
69
+ end
70
+ end
71
+ end
72
+
73
+ end
You can’t perform that action at this time.
0 commit comments