Skip to content

Commit df999db

Browse files
committed
Add spec to ensure gem loads without error.
1 parent 0f4be63 commit df999db

File tree

1 file changed

+14
-36
lines changed

1 file changed

+14
-36
lines changed

spec/lib/rex/exploitation/jsobfu_spec.rb

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,28 @@
22
require 'rex/exploitation/jsobfu'
33

44
describe Rex::Exploitation::JSObfu do
5+
TEST_JS = %Q|
6+
function x() {
7+
alert('1');
8+
};
9+
10+
x();
11+
|
512

613
subject(:jsobfu) do
7-
described_class.new("")
14+
described_class.new(TEST_JS)
815
end
916

10-
describe '#random_var_name' do
11-
subject(:random_var_name) { jsobfu.random_var_name }
12-
13-
it { should be_a String }
14-
it { should_not be_empty }
15-
16-
it 'is composed of _, $, alphanumeric chars' do
17-
20.times { expect(jsobfu.random_var_name).to match(/\A[a-zA-Z0-9$_]+\Z/) }
18-
end
19-
20-
it 'does not start with a number' do
21-
20.times { expect(jsobfu.random_var_name).not_to match(/\A[0-9]/) }
17+
describe '#obfuscate' do
18+
19+
it 'returns a #to_s object' do
20+
expect(jsobfu.obfuscate.to_s).to be_a(String)
2221
end
2322

24-
context 'when a reserved word is generated' do
25-
let(:reserved) { described_class::RESERVED_KEYWORDS.first }
26-
let(:random) { 'abcdef' }
27-
let(:generated) { [reserved, reserved, reserved, random] }
28-
29-
before do
30-
jsobfu.stub(:random_string) { generated.shift }
31-
end
32-
33-
it { should be random }
23+
it 'returns a non-empty String' do
24+
expect(jsobfu.obfuscate.to_s).not_to be_empty
3425
end
3526

36-
context 'when a non-unique random var is generated' do
37-
let(:preexisting) { 'preexist' }
38-
let(:random) { 'abcdef' }
39-
let(:vars) { { 'jQuery' => preexisting } }
40-
let(:generated) { [preexisting, preexisting, preexisting, random] }
41-
42-
before do
43-
jsobfu.stub(:random_string) { generated.shift }
44-
jsobfu.instance_variable_set("@vars", vars)
45-
end
46-
47-
it { should be random }
48-
end
4927
end
5028

5129
end

0 commit comments

Comments
 (0)