Add spec to ensure gem loads without error.

bug/bundler_fix
Joe Vennix 2014-09-19 19:49:01 -05:00
parent 0f4be63903
commit df999db547
No known key found for this signature in database
GPG Key ID: 127B05FB3E85A2B0
1 changed files with 14 additions and 36 deletions

View File

@ -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