Add spec to ensure gem loads without error.
parent
0f4be63903
commit
df999db547
|
@ -2,50 +2,28 @@ require 'spec_helper'
|
|||
require 'rex/exploitation/jsobfu'
|
||||
|
||||
describe Rex::Exploitation::JSObfu do
|
||||
TEST_JS = %Q|
|
||||
function x() {
|
||||
alert('1');
|
||||
};
|
||||
|
||||
x();
|
||||
|
|
||||
|
||||
subject(:jsobfu) do
|
||||
described_class.new("")
|
||||
described_class.new(TEST_JS)
|
||||
end
|
||||
|
||||
describe '#random_var_name' do
|
||||
subject(:random_var_name) { jsobfu.random_var_name }
|
||||
|
||||
it { should be_a String }
|
||||
it { should_not be_empty }
|
||||
|
||||
it 'is composed of _, $, alphanumeric chars' do
|
||||
20.times { expect(jsobfu.random_var_name).to match(/\A[a-zA-Z0-9$_]+\Z/) }
|
||||
describe '#obfuscate' do
|
||||
|
||||
it 'returns a #to_s object' do
|
||||
expect(jsobfu.obfuscate.to_s).to be_a(String)
|
||||
end
|
||||
|
||||
it 'does not start with a number' do
|
||||
20.times { expect(jsobfu.random_var_name).not_to match(/\A[0-9]/) }
|
||||
it 'returns a non-empty String' do
|
||||
expect(jsobfu.obfuscate.to_s).not_to be_empty
|
||||
end
|
||||
|
||||
context 'when a reserved word is generated' do
|
||||
let(:reserved) { described_class::RESERVED_KEYWORDS.first }
|
||||
let(:random) { 'abcdef' }
|
||||
let(:generated) { [reserved, reserved, reserved, random] }
|
||||
|
||||
before do
|
||||
jsobfu.stub(:random_string) { generated.shift }
|
||||
end
|
||||
|
||||
it { should be random }
|
||||
end
|
||||
|
||||
context 'when a non-unique random var is generated' do
|
||||
let(:preexisting) { 'preexist' }
|
||||
let(:random) { 'abcdef' }
|
||||
let(:vars) { { 'jQuery' => preexisting } }
|
||||
let(:generated) { [preexisting, preexisting, preexisting, random] }
|
||||
|
||||
before do
|
||||
jsobfu.stub(:random_string) { generated.shift }
|
||||
jsobfu.instance_variable_set("@vars", vars)
|
||||
end
|
||||
|
||||
it { should be random }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue