Skip to content

Commit

Permalink
Merge pull request #725 from bugsnag/empty-repeater-key
Browse files Browse the repository at this point in the history
Ensure an empty string in the repeater key options is interpreted as null
  • Loading branch information
Cawllec authored Feb 20, 2025
2 parents fd8a0cd + bd31171 commit 186df32
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 9.23.2 - 2025/02/20

## Fixes

- Fix an issue with repeater API keys being valid despite being empty strings [725](https://github.com/bugsnag/maze-runner/pull/725)

# 9.23.1 - 2025/02/19

## Fixes
Expand Down
2 changes: 1 addition & 1 deletion lib/maze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# providing an alternative to the proliferation of global variables or singletons.
module Maze

VERSION = '9.23.1'
VERSION = '9.23.2'

class << self
attr_accessor :check, :driver, :internal_hooks, :mode, :start_time, :dynamic_retry, :public_address,
Expand Down
6 changes: 4 additions & 2 deletions lib/maze/option/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def populate(config, options)
config.aws_public_ip = options[Maze::Option::AWS_PUBLIC_IP]
config.enable_retries = options[Maze::Option::RETRIES]
config.enable_bugsnag = options[Maze::Option::BUGSNAG]
config.aspecto_repeater_api_key = options[Maze::Option::ASPECTO_REPEATER_API_KEY]
config.bugsnag_repeater_api_key = options[Maze::Option::BUGSNAG_REPEATER_API_KEY]
aspecto_repeater_api_key = options[Maze::Option::ASPECTO_REPEATER_API_KEY]
config.aspecto_repeater_api_key = aspecto_repeater_api_key unless aspecto_repeater_api_key&.empty?
bugsnag_repeater_api_key = options[Maze::Option::BUGSNAG_REPEATER_API_KEY]
config.bugsnag_repeater_api_key = bugsnag_repeater_api_key unless bugsnag_repeater_api_key&.empty?

# Document server options
config.document_server_root = options[Maze::Option::DS_ROOT]
Expand Down
5 changes: 5 additions & 0 deletions lib/maze/option/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ def validate(options)

# --repeater-api-key
key = options[Option::BUGSNAG_REPEATER_API_KEY]
if key&.empty?
$logger.warn "A repeater-api-key option was provided with an empty string. This won't be used during this test run"
key = nil
end
key_regex = /^[0-9a-fA-F]{32}$/

if key && !key_regex.match?(key)
errors << "--#{Option::BUGSNAG_REPEATER_API_KEY} must be set to a 32-character hex value"
end
Expand Down
37 changes: 37 additions & 0 deletions test/unit/maze/option/processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_default_options
assert_false config.always_log
assert_false config.https
assert_nil config.bugsnag_repeater_api_key
assert_nil config.aspecto_repeater_api_key
end

def test_overriden_defaults
Expand Down Expand Up @@ -140,6 +141,42 @@ def test_filename_options
assert_equal('file-contents', config.app)
end

def test_repeater_key_responses
normal_args = %w[--repeater-api-key=foo --aspecto-repeater-api-key=bar]
normal_options = Maze::Option::Parser.parse normal_args
normal_config = Maze::Configuration.new
Maze::Option::Processor.populate normal_config, normal_options
assert_equal 'foo', normal_config.bugsnag_repeater_api_key
assert_equal 'bar', normal_config.aspecto_repeater_api_key

empty_args = %w[--repeater-api-key= --aspecto-repeater-api-key=]
empty_options = Maze::Option::Parser.parse empty_args
empty_config = Maze::Configuration.new
Maze::Option::Processor.populate empty_config, empty_options
assert_nil empty_config.bugsnag_repeater_api_key
assert_nil empty_config.aspecto_repeater_api_key

ENV['MAZE_ASPECTO_REPEATER_API_KEY'] = 'test_1'
ENV['MAZE_REPEATER_API_KEY'] = 'test_2'
env_options = Maze::Option::Parser.parse []
env_config = Maze::Configuration.new
Maze::Option::Processor.populate env_config, env_options
assert_equal 'test_1', env_config.aspecto_repeater_api_key
assert_equal 'test_2', env_config.bugsnag_repeater_api_key
ENV.delete('MAZE_ASPECTO_REPEATER_API_KEY')
ENV.delete('MAZE_REPEATER_API_KEY')

ENV['MAZE_ASPECTO_REPEATER_API_KEY'] = ''
ENV['MAZE_REPEATER_API_KEY'] = ''
empty_env_options = Maze::Option::Parser.parse []
empty_env_config = Maze::Configuration.new
Maze::Option::Processor.populate empty_env_config, empty_env_options
assert_nil empty_env_config.bugsnag_repeater_api_key
assert_nil empty_env_config.aspecto_repeater_api_key
ENV.delete('MAZE_ASPECTO_REPEATER_API_KEY')
ENV.delete('MAZE_REPEATER_API_KEY')
end

def test_environment_options
ENV['USE_LEGACY_DRIVER'] = '1'

Expand Down
29 changes: 29 additions & 0 deletions test/unit/maze/option/validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,33 @@ def test_invalid_capabilities
assert_equal 1, errors.length
assert_equal '--capabilities must be valid JSON (given {"cap":ability"})', errors[0]
end

def test_api_key_validation
$logger = mock('logger')

normal_args = %w[--repeater-api-key=12312312312312312312312312312312]

normal_options = Maze::Option::Parser.parse normal_args
normal_errors = @validator.validate normal_options
assert_empty normal_errors

$logger.expects(:warn).with("A repeater-api-key option was provided with an empty string. This won't be used during this test run")
empty_args = %w[--repeater-api-key=]
empty_options = Maze::Option::Parser.parse empty_args
empty_errors = @validator.validate empty_options
assert_empty empty_errors

ENV['MAZE_REPEATER_API_KEY'] = '32132132132132132132132132132132'
env_options = Maze::Option::Parser.parse []
env_errors = @validator.validate env_options
assert_empty env_errors
ENV.delete('MAZE_REPEATER_API_KEY')

$logger.expects(:warn).with("A repeater-api-key option was provided with an empty string. This won't be used during this test run")
ENV['MAZE_REPEATER_API_KEY'] = ''
empty_env_options = Maze::Option::Parser.parse []
empty_env_errors = @validator.validate empty_env_options
assert_empty empty_env_errors
ENV.delete('MAZE_REPEATER_API_KEY')
end
end

0 comments on commit 186df32

Please sign in to comment.