require 'rex/parser/unattend'
require 'rexml/document'
dj = REXML::Document.new('falseFabrikam.comPassword1MyUserName%MACHINENAME%')
lng = REXML::Document.new('falseFabrikam.comPassword1MyUserName%MACHINENAME%')
std = REXML::Document.new(' OnErrorusernameFabrikam.commy_passwordOnErrorWindows Vista with OfficeImageGroup1Install.wim01OnError0false11CNTFStruefalseOnErroren-USen-US ')
unsecure = REXML::Document.new('trueXXXX-XXXX-XXXX-XXXX-XXXX')
b64 = REXML::Document.new(' VABlAG0AcAAxADIAMwBQAGEAcwBzAHcAbwByAGQAfalsetrueAdministrator1powershell.exe -command {Set-ExecutionPolicy Unrestricted}2powershell.exe -file "c:\Windows\System32\sysprep\2K12-1-rename.ps1"truetruetruetruetrueWorktruetrueVABlAG0AcAAxADIAMwBBAGQAbQBpAG4AaQBzAHQAcgBhAHQAbwByAFAAYQBzAHMAdwBvAHIAZAA=false')
comb = REXML::Document.new('OnErrorAdministratorFabrikam.comPassword1Install Imagedefaultx86install.wimOnError01OnError0false11CNTFStruefalseOnErroren-USen-UStruecomputer122falsetrueWork1truetrue3296102460768Password1trueMy Local AccountJohn SmithAdministrators;Power UsersJohnAdministratorAdministrators;Power UsersFabrikam.com')
RSpec.describe Rex::Parser::Unattend do
context "#parse" do
it "returns passwords for b64" do
results = described_class.parse(b64)
expect(results.length).to eq(2)
expect(results[0]['password']).to eq(Rex::Text.to_unicode('Temp123'))
end
it "returns passwords for domain join" do
results = described_class.parse(dj)
expect(results.length).to eq(1)
expect(results[0]['password']).to eq('Password1')
end
pos_xmls = [dj, b64, comb, std, lng]
neg_xmls = [unsecure]
it "returns results for all positive examples" do
pos_xmls.each do |xml|
results = described_class.parse(xml)
expect(results).not_to be_empty
end
end
it "returns no results for negative examples" do
neg_xmls.each do |xml|
results = described_class.parse(xml)
expect(results).to be_empty
end
end
end
end