Skip to content

Commit

Permalink
Uses the Default CLI option to manage the UA list
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanlr committed Apr 5, 2019
1 parent 904ccaf commit 759431d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ LineLength:
Max: 120
MethodLength:
Max: 18
Exclude:
- app/controllers/core/cli_options.rb
Lint/UriEscapeUnescape:
Enabled: false
Metrics/AbcSize:
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/core/cli_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def cli_browser_options
OptBoolean.new(['--random-user-agent', '--rua',
'Use a random user-agent for each scan']),
OptFilePath.new(['--user-agents-list FILE-PATH',
'List of agents to use with --random-user-agent'], exists: true, advanced: true),
'List of agents to use with --random-user-agent'],
exists: true,
advanced: true,
default: APP_DIR.join('user_agents.txt')),
OptCredentials.new(['--http-auth login:password']),
OptPositiveInteger.new(['-t', '--max-threads VALUE', 'The max threads to use'],
default: 5),
Expand Down
7 changes: 2 additions & 5 deletions lib/cms_scanner/browser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def user_agents

@user_agents = []

# The user_agents_list is managed by the CLI options, with the default being
# APP_DIR/user_agents.txt
File.open(user_agents_list).each do |line|
next if line == "\n" || line[0, 1] == '#'

Expand All @@ -71,11 +73,6 @@ def user_agents
@user_agents
end

# @return [ String ] The path to the user agents list
def user_agents_list
@user_agents_list ||= File.join(APP_DIR, 'user_agents.txt')
end

# @param [ value ] The throttle time in milliseconds
#
# if value > 0, the max_threads will be set to 1
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
expected = case sym
when :user_agent
browser.default_user_agent
when :user_agents_list
File.join(CMSScanner::APP_DIR, 'user_agents.txt')
when :throttle
0.0
end
Expand Down Expand Up @@ -219,8 +217,11 @@ class Browser
context 'when --random-user-agent' do
let(:options) { super().merge(random_user_agent: true) }

it 'select a random UA in the user_agents' do
it 'selects a random UA in the user_agents' do
expect(browser).to receive(:user_agents_list).and_return(FIXTURES.join('user_agents.txt'))

expect(browser.user_agent).to_not eql browser.default_user_agent

# Should not pick up a random one each time
expect(browser.user_agent).to eql browser.user_agent
end
Expand Down

0 comments on commit 759431d

Please sign in to comment.