Separated Selenium driver + BrowserStack code based on hook loadtime
This commit is contained in:
@@ -80,25 +80,48 @@ RSpec.describe 'AutoRunEngine test', :run_on_browserstack => true do
|
||||
http_hook_server.start
|
||||
end
|
||||
|
||||
# Give the server time to start-up
|
||||
sleep 1
|
||||
@caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
|
||||
@caps["name"] = @caps['name'] || ENV['name'] || 'no-name'
|
||||
@enable_local = @caps["browserstack.local"] && @caps["browserstack.local"].to_s == "true"
|
||||
puts "enable_local is #{@enable_local.to_s.upcase}"
|
||||
|
||||
# Authenticate to REST API & pull the token from the response
|
||||
@response = RestClient.post "#{RESTAPI_ADMIN}/login", { 'username': "#{@username}", 'password': "#{@password}" }.to_json, :content_type => :json
|
||||
@token = JSON.parse(@response)['token']
|
||||
# Code to start browserstack local before start of test
|
||||
if @enable_local &&
|
||||
@bs_local = BrowserStack::Local.new
|
||||
bs_local_args = { "key" => CONFIG['key'], "forcelocal" => true }
|
||||
@bs_local.start(bs_local_args)
|
||||
@caps["browserstack.local"] = true
|
||||
@caps['browserstack.localIdentifier'] = ENV['BROWSERSTACK_LOCAL_IDENTIFIER']
|
||||
end
|
||||
|
||||
@driver = Selenium::WebDriver.for(:remote,
|
||||
:url => "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub",
|
||||
:desired_capabilities => @caps)
|
||||
|
||||
# Hook new victim
|
||||
print_info 'Hooking a new victim, waiting a few seconds...'
|
||||
@driver.navigate.to "#{VICTIM_URL}"
|
||||
|
||||
# Give time for browser hook to occur
|
||||
sleep 2
|
||||
|
||||
@hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}")
|
||||
@session = @hooks['hooked-browsers']['online']['0']['session']
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@driver.quit
|
||||
|
||||
# Code to stop browserstack local after end of test
|
||||
@bs_local.stop if @enable_local
|
||||
|
||||
print_info "Shutting down server"
|
||||
Process.kill("KILL",@pid)
|
||||
Process.kill("KILL",@pids)
|
||||
end
|
||||
|
||||
xit 'AutoRunEngine is working' do
|
||||
response = RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}"
|
||||
result_data = JSON.parse(response)
|
||||
|
||||
expect(result_data['hooked-browsers']['online']).not_to be_empty
|
||||
expect(@hooks['hooked-browsers']['online']).not_to be_empty
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -79,25 +79,56 @@ RSpec.describe 'Browser details handler', :run_on_browserstack => true do
|
||||
# Authenticate to REST API & pull the token from the response
|
||||
@response = RestClient.post "#{RESTAPI_ADMIN}/login", { 'username': "#{@username}", 'password': "#{@password}" }.to_json, :content_type => :json
|
||||
@token = JSON.parse(@response)['token']
|
||||
|
||||
@caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
|
||||
@caps["name"] = @caps['name'] || ENV['name'] || 'no-name'
|
||||
@enable_local = @caps["browserstack.local"] && @caps["browserstack.local"].to_s == "true"
|
||||
puts "enable_local is #{@enable_local.to_s.upcase}"
|
||||
|
||||
# Code to start browserstack local before start of test
|
||||
if @enable_local &&
|
||||
@bs_local = BrowserStack::Local.new
|
||||
bs_local_args = { "key" => CONFIG['key'], "forcelocal" => true }
|
||||
@bs_local.start(bs_local_args)
|
||||
@caps["browserstack.local"] = true
|
||||
@caps['browserstack.localIdentifier'] = ENV['BROWSERSTACK_LOCAL_IDENTIFIER']
|
||||
end
|
||||
|
||||
@driver = Selenium::WebDriver.for(:remote,
|
||||
:url => "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub",
|
||||
:desired_capabilities => @caps)
|
||||
|
||||
# Hook new victim
|
||||
print_info 'Hooking a new victim, waiting a few seconds...'
|
||||
@driver.navigate.to "#{VICTIM_URL}"
|
||||
|
||||
# Give time for browser hook to occur
|
||||
sleep 2
|
||||
|
||||
@hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}")
|
||||
@session = @hooks['hooked-browsers']['online']['0']['session']
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@driver.quit
|
||||
|
||||
# Code to stop browserstack local after end of test
|
||||
@bs_local.stop if @enable_local
|
||||
|
||||
print_info "Shutting down server"
|
||||
Process.kill("KILL",@pid)
|
||||
Process.kill("KILL",@pids)
|
||||
end
|
||||
|
||||
xit 'can successfully hook a browser' do
|
||||
expect(JSON.parse(@hooks)['hooked-browsers']['online']).not_to be_empty
|
||||
it 'can successfully hook a browser' do
|
||||
expect(@hooks['hooked-browsers']['online']).not_to be_empty
|
||||
end
|
||||
|
||||
xit 'browser details handler working' do
|
||||
it 'browser details handler working' do
|
||||
print_info "Getting browser details"
|
||||
response = RestClient.get "#{RESTAPI_HOOKS}/#{@session}?token=#{@token}"
|
||||
details = JSON.parse(response.body)
|
||||
|
||||
expect(@driver.browser.to_s.downcase).to eql (details['browser.name.friendly'].downcase)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -52,9 +52,44 @@ RSpec.describe 'BeEF WebSockets enabled', :run_on_browserstack => true do
|
||||
end
|
||||
# wait for server to start
|
||||
sleep 1
|
||||
|
||||
|
||||
# Authenticate to REST API & pull the token from the response
|
||||
@response = RestClient.post "#{RESTAPI_ADMIN}/login", { 'username': "#{@username}", 'password': "#{@password}" }.to_json, :content_type => :json
|
||||
@token = JSON.parse(@response)['token']
|
||||
|
||||
@caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
|
||||
@caps["name"] = @caps['name'] || ENV['name'] || 'no-name'
|
||||
@enable_local = @caps["browserstack.local"] && @caps["browserstack.local"].to_s == "true"
|
||||
puts "enable_local is #{@enable_local.to_s.upcase}"
|
||||
|
||||
# Code to start browserstack local before start of test
|
||||
if @enable_local &&
|
||||
@bs_local = BrowserStack::Local.new
|
||||
bs_local_args = { "key" => CONFIG['key'], "forcelocal" => true }
|
||||
@bs_local.start(bs_local_args)
|
||||
@caps["browserstack.local"] = true
|
||||
@caps['browserstack.localIdentifier'] = ENV['BROWSERSTACK_LOCAL_IDENTIFIER']
|
||||
end
|
||||
|
||||
@driver = Selenium::WebDriver.for(:remote,
|
||||
:url => "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub",
|
||||
:desired_capabilities => @caps)
|
||||
|
||||
# Hook new victim
|
||||
print_info 'Hooking a new victim, waiting a few seconds...'
|
||||
@driver.navigate.to "#{VICTIM_URL}"
|
||||
|
||||
# Give time for browser hook to occur
|
||||
sleep 2
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@driver.quit
|
||||
|
||||
# Code to stop browserstack local after end of test
|
||||
@bs_local.stop if @enable_local
|
||||
|
||||
# cleanup: delete test browser entries and session
|
||||
# kill the server
|
||||
@config.set('beef.http.websocket.enable', false)
|
||||
@@ -63,7 +98,7 @@ RSpec.describe 'BeEF WebSockets enabled', :run_on_browserstack => true do
|
||||
puts "waiting for server to die.."
|
||||
end
|
||||
|
||||
xit 'can hook a browser with websockets' do
|
||||
it 'can hook a browser with websockets' do
|
||||
#prepare for the HTTP model
|
||||
https = BeEF::Core::Models::Http
|
||||
|
||||
|
||||
@@ -17,17 +17,17 @@ RSpec.describe 'BeEF Extension WebSockets' do
|
||||
@config.set('beef.http.websocket.secure', true)
|
||||
end
|
||||
|
||||
xit 'confirms that a websocket server has been started' do
|
||||
it 'confirms that a websocket server has been started' do
|
||||
expect(@ws).to be_a_kind_of(BeEF::Core::Websocket::Websocket)
|
||||
end
|
||||
|
||||
xit 'confirms that a secure websocket server has been started' do
|
||||
it 'confirms that a secure websocket server has been started' do
|
||||
@config.set('beef.http.websocket.secure', true)
|
||||
wss = BeEF::Core::Websocket::Websocket.instance
|
||||
expect(wss).to be_a_kind_of(BeEF::Core::Websocket::Websocket)
|
||||
end
|
||||
|
||||
xit 'confirms that a websocket client can connect to the BeEF Websocket Server' do
|
||||
it 'confirms that a websocket client can connect to the BeEF Websocket Server' do
|
||||
sleep(3)
|
||||
client = WebSocket::Client::Simple.connect "ws://127.0.0.1:#{@port}"
|
||||
sleep(1)
|
||||
|
||||
@@ -80,16 +80,8 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
|
||||
@response = RestClient.post "#{RESTAPI_ADMIN}/login", { 'username': "#{@username}", 'password': "#{@password}" }.to_json, :content_type => :json
|
||||
@token = JSON.parse(@response)['token']
|
||||
|
||||
# Grab Command Module IDs as they can differ from machine to machine
|
||||
@debug_mod_ids = JSON.parse(RestClient.get "#{RESTAPI_MODULES}?token=#{@token}")
|
||||
@debug_mod_names_ids = {}
|
||||
@debug_mods = @debug_mod_ids.to_a.select { |cmd_mod| cmd_mod[1]['category'] == 'Debug' }
|
||||
.map do |debug_mod|
|
||||
@debug_mod_names_ids[debug_mod[1]['class']] = debug_mod[0]
|
||||
end
|
||||
|
||||
@caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
|
||||
@caps["name"] = ENV['name'] || 'no-name'
|
||||
@caps["name"] = @caps['name'] || ENV['name'] || 'no-name'
|
||||
@enable_local = @caps["browserstack.local"] && @caps["browserstack.local"].to_s == "true"
|
||||
puts "enable_local is #{@enable_local.to_s.upcase}"
|
||||
|
||||
@@ -115,6 +107,14 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
|
||||
|
||||
@hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}")
|
||||
@session = @hooks['hooked-browsers']['online']['0']['session']
|
||||
|
||||
# Grab Command Module IDs as they can differ from machine to machine
|
||||
@debug_mod_ids = JSON.parse(RestClient.get "#{RESTAPI_MODULES}?token=#{@token}")
|
||||
@debug_mod_names_ids = {}
|
||||
@debug_mods = @debug_mod_ids.to_a.select { |cmd_mod| cmd_mod[1]['category'] == 'Debug' }
|
||||
.map do |debug_mod|
|
||||
@debug_mod_names_ids[debug_mod[1]['class']] = debug_mod[0]
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
|
||||
Reference in New Issue
Block a user