|
2 | 2 | require 'rex/exploitation/jsobfu'
|
3 | 3 |
|
4 | 4 | describe Rex::Exploitation::JSObfu do
|
| 5 | + TEST_JS = %Q| |
| 6 | + function x() { |
| 7 | + alert('1'); |
| 8 | + }; |
| 9 | +
|
| 10 | + x(); |
| 11 | + | |
5 | 12 |
|
6 | 13 | subject(:jsobfu) do
|
7 |
| - described_class.new("") |
| 14 | + described_class.new(TEST_JS) |
8 | 15 | end
|
9 | 16 |
|
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) |
22 | 21 | end
|
23 | 22 |
|
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 |
34 | 25 | end
|
35 | 26 |
|
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 |
49 | 27 | end
|
50 | 28 |
|
51 | 29 | end
|
0 commit comments