From 3d89b4393064763c8a37e7742714e1b9b879bf1f Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Thu, 5 Sep 2024 08:52:42 +0100 Subject: [PATCH 01/16] Add crude examples of validation --- features/support/env.rb | 78 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index d806b18..713f5e8 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -5,4 +5,80 @@ steps %( When I configure the base endpoint ) -end \ No newline at end of file +end + +Maze.config.add_validator('error') do |validator| + validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } + validator.validate_header('Content-Type') { |value| value.eql?('application/json') } + validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('4') } + validator.validate_header('Bugsnag-Sent-At') do |value| + begin + Date.iso8601(date) + rescue Date::Error + @success = false + @errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + end + end + + notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') + if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') + @success = false + @errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" + end + + error_elements = ['notifier.url', 'notifier.version', 'events'] + error_elements_present = error_elements.all? do |element_key| + element = Maze::Helper.read_key_path(validator.body, element) + !element.nil? && (!element.is_a?(Array) || !element.empty?) + end + + unless error_elements_present + @success = false + @errors << "Not all of the error payload elements were present" + end + + event_elements = ['severity', 'severityReason.type', 'unhandled', 'exceptions'] + events = Maze::Helper.read_key_path(validator.body, 'events') + event_elements_present = events.all? do |event| + event_elements.all? do |element_key| + element = Maze::Helper.read_key_path(event, element_key) + !element.nil? + end + end + + unless event_elements_present + @success = false + @errors << "Not all of the event elements were present" + end +end + +Maze.config.add_validator('session') do |validator| + validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } + validator.validate_header('Content-Type') { |value| value.eql?('application/json') } + validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('1.0') } + validator.validate_header('Bugsnag-Sent-At') do |value| + begin + Date.iso8601(date) + rescue Date::Error + @success = false + @errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + end + end + + notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') + if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') + @success = false + @errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" + end + + session_elements = ['notifier.url', 'notifier.version', 'events'] + session_elements_present = session_elements.all? do |element_key| + element = Maze::Helper.read_key_path(validator.body, element) + !element.nil? && (!element.is_a?(Array) || !element.empty?) + end + + unless session_elements_present + @success = false + @errors << "Not all of the session payload elements were present" + end +end From 0126addfe6dd4aabc2e9f32d55911b71755d4b36 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Thu, 5 Sep 2024 08:53:23 +0100 Subject: [PATCH 02/16] Remove existing validation --- features/net-http/appversion.feature | 2 -- features/sessioncontext.feature | 3 --- 2 files changed, 5 deletions(-) diff --git a/features/net-http/appversion.feature b/features/net-http/appversion.feature index c2d10ad..95f3c52 100644 --- a/features/net-http/appversion.feature +++ b/features/net-http/appversion.feature @@ -11,7 +11,6 @@ Scenario: A error report contains the configured app type when using a net http And I open the URL "http://localhost:4512/handled" And I wait to receive an error And I should receive no sessions - And the error is valid for the error reporting API version "4" for the "Bugsnag Go" notifier And the event "app.version" equals "3.1.2" Scenario: A session report contains the configured app type when using a net http app @@ -21,5 +20,4 @@ Scenario: A session report contains the configured app type when using a net htt And I wait for the host "localhost" to open port "4512" And I open the URL "http://localhost:4512/session" And I wait to receive a session - And the session is valid for the session reporting API version "1.0" for the "Bugsnag Go" notifier And the session payload field "app.version" equals "3.1.2" diff --git a/features/sessioncontext.feature b/features/sessioncontext.feature index 8cc09a1..a3af0b6 100644 --- a/features/sessioncontext.feature +++ b/features/sessioncontext.feature @@ -6,8 +6,5 @@ Scenario: An error report contains a session count when part of a session Then I wait to receive 1 error # one session is created on start And I wait to receive 2 session - And the error is valid for the error reporting API version "4" for the "Bugsnag Go" notifier - And the session is valid for the session reporting API version "1.0" for the "Bugsnag Go" notifier And I discard the oldest session - And the session is valid for the session reporting API version "1.0" for the "Bugsnag Go" notifier And the session payload has a valid sessions array \ No newline at end of file From c0e27b9e9924c7d795b6969966c4edf8a56e42f3 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Thu, 5 Sep 2024 08:59:49 +0100 Subject: [PATCH 03/16] Update gemfile to use WIP maze --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e20e035..8a58451 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' -gem "bugsnag-maze-runner", "~> 9.0" \ No newline at end of file +gem "bugsnag-maze-runner", git: 'https://github.com/bugsnag/maze-runner', branch: 'dynamic-validation/config-changes' \ No newline at end of file From c9fcbb3004ab249e2796aa0b6d8f6d93e4166c2d Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Thu, 5 Sep 2024 13:49:16 +0100 Subject: [PATCH 04/16] Add some debugging --- features/support/env.rb | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 713f5e8..45fc5b0 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -8,6 +8,7 @@ end Maze.config.add_validator('error') do |validator| + pp "Running error validation" validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } validator.validate_header('Content-Type') { |value| value.eql?('application/json') } validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('4') } @@ -15,15 +16,15 @@ begin Date.iso8601(date) rescue Date::Error - @success = false - @errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + validator.success = false + validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" end end notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') - @success = false - @errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" + validator.success = false + validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" end error_elements = ['notifier.url', 'notifier.version', 'events'] @@ -33,8 +34,8 @@ end unless error_elements_present - @success = false - @errors << "Not all of the error payload elements were present" + validator.success = false + validator.errors << "Not all of the error payload elements were present" end event_elements = ['severity', 'severityReason.type', 'unhandled', 'exceptions'] @@ -47,12 +48,16 @@ end unless event_elements_present - @success = false - @errors << "Not all of the event elements were present" + validator.success = false + validator.errors << "Not all of the event elements were present" end + pp "Error validation complete" + pp validator.success + pp validator.errors end Maze.config.add_validator('session') do |validator| + pp "Running session validation" validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } validator.validate_header('Content-Type') { |value| value.eql?('application/json') } validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('1.0') } @@ -60,15 +65,15 @@ begin Date.iso8601(date) rescue Date::Error - @success = false - @errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + validator.success = false + validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" end end notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') - @success = false - @errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" + validator.success = false + validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" end session_elements = ['notifier.url', 'notifier.version', 'events'] @@ -78,7 +83,11 @@ end unless session_elements_present - @success = false - @errors << "Not all of the session payload elements were present" + validator.success = false + validator.errors << "Not all of the session payload elements were present" end + + pp "Session validation complete" + pp validator.success + pp validator.errors end From 80c05bff193ac050e474912f28ae2098c567d1e6 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Fri, 6 Sep 2024 21:36:49 +0100 Subject: [PATCH 05/16] Debugging --- features/support/env.rb | 130 ++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 45fc5b0..078f970 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -12,82 +12,82 @@ validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } validator.validate_header('Content-Type') { |value| value.eql?('application/json') } validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('4') } - validator.validate_header('Bugsnag-Sent-At') do |value| - begin - Date.iso8601(date) - rescue Date::Error - validator.success = false - validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" - end - end + # validator.validate_header('Bugsnag-Sent-At') do |value| + # begin + # Date.iso8601(date) + # rescue Date::Error + # validator.success = false + # validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + # end + # end - notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') - if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') - validator.success = false - validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" - end + # notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') + # if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') + # validator.success = false + # validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" + # end - error_elements = ['notifier.url', 'notifier.version', 'events'] - error_elements_present = error_elements.all? do |element_key| - element = Maze::Helper.read_key_path(validator.body, element) - !element.nil? && (!element.is_a?(Array) || !element.empty?) - end + # error_elements = ['notifier.url', 'notifier.version', 'events'] + # error_elements_present = error_elements.all? do |element_key| + # element = Maze::Helper.read_key_path(validator.body, element) + # !element.nil? && (!element.is_a?(Array) || !element.empty?) + # end - unless error_elements_present - validator.success = false - validator.errors << "Not all of the error payload elements were present" - end + # unless error_elements_present + # validator.success = false + # validator.errors << "Not all of the error payload elements were present" + # end - event_elements = ['severity', 'severityReason.type', 'unhandled', 'exceptions'] - events = Maze::Helper.read_key_path(validator.body, 'events') - event_elements_present = events.all? do |event| - event_elements.all? do |element_key| - element = Maze::Helper.read_key_path(event, element_key) - !element.nil? - end - end + # event_elements = ['severity', 'severityReason.type', 'unhandled', 'exceptions'] + # events = Maze::Helper.read_key_path(validator.body, 'events') + # event_elements_present = events.all? do |event| + # event_elements.all? do |element_key| + # element = Maze::Helper.read_key_path(event, element_key) + # !element.nil? + # end + # end - unless event_elements_present - validator.success = false - validator.errors << "Not all of the event elements were present" - end + # unless event_elements_present + # validator.success = false + # validator.errors << "Not all of the event elements were present" + # end pp "Error validation complete" pp validator.success pp validator.errors end -Maze.config.add_validator('session') do |validator| - pp "Running session validation" - validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } - validator.validate_header('Content-Type') { |value| value.eql?('application/json') } - validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('1.0') } - validator.validate_header('Bugsnag-Sent-At') do |value| - begin - Date.iso8601(date) - rescue Date::Error - validator.success = false - validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" - end - end +# Maze.config.add_validator('session') do |validator| +# pp "Running session validation" +# validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } +# validator.validate_header('Content-Type') { |value| value.eql?('application/json') } +# validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('1.0') } +# validator.validate_header('Bugsnag-Sent-At') do |value| +# begin +# Date.iso8601(date) +# rescue Date::Error +# validator.success = false +# validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" +# end +# end - notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') - if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') - validator.success = false - validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" - end +# notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') +# if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') +# validator.success = false +# validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" +# end - session_elements = ['notifier.url', 'notifier.version', 'events'] - session_elements_present = session_elements.all? do |element_key| - element = Maze::Helper.read_key_path(validator.body, element) - !element.nil? && (!element.is_a?(Array) || !element.empty?) - end +# session_elements = ['notifier.url', 'notifier.version', 'events'] +# session_elements_present = session_elements.all? do |element_key| +# element = Maze::Helper.read_key_path(validator.body, element) +# !element.nil? && (!element.is_a?(Array) || !element.empty?) +# end - unless session_elements_present - validator.success = false - validator.errors << "Not all of the session payload elements were present" - end +# unless session_elements_present +# validator.success = false +# validator.errors << "Not all of the session payload elements were present" +# end - pp "Session validation complete" - pp validator.success - pp validator.errors -end +# pp "Session validation complete" +# pp validator.success +# pp validator.errors +# end From a7cb5ed35ab87c8a8c17334d5af28e93e25a3cec Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Fri, 6 Sep 2024 21:40:25 +0100 Subject: [PATCH 06/16] Debugging --- features/support/env.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 078f970..f9639b5 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -12,14 +12,14 @@ validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } validator.validate_header('Content-Type') { |value| value.eql?('application/json') } validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('4') } - # validator.validate_header('Bugsnag-Sent-At') do |value| - # begin - # Date.iso8601(date) - # rescue Date::Error - # validator.success = false - # validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" - # end - # end + validator.validate_header('Bugsnag-Sent-At') do |date| + begin + Date.iso8601(date) + rescue Date::Error + validator.success = false + validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + end + end # notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') # if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') From a68f3ce676c4c1d3452ea9ba164c3e8d41420441 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Fri, 6 Sep 2024 22:52:57 +0100 Subject: [PATCH 07/16] Debugging --- features/support/env.rb | 114 ++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index f9639b5..b176b5e 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -21,73 +21,73 @@ end end - # notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') - # if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') - # validator.success = false - # validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" - # end + notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') + if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') + validator.success = false + validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" + end - # error_elements = ['notifier.url', 'notifier.version', 'events'] - # error_elements_present = error_elements.all? do |element_key| - # element = Maze::Helper.read_key_path(validator.body, element) - # !element.nil? && (!element.is_a?(Array) || !element.empty?) - # end + error_elements = ['notifier.url', 'notifier.version', 'events'] + error_elements_present = error_elements.all? do |element_key| + element = Maze::Helper.read_key_path(validator.body, element) + !element.nil? && (!element.is_a?(Array) || !element.empty?) + end - # unless error_elements_present - # validator.success = false - # validator.errors << "Not all of the error payload elements were present" - # end + unless error_elements_present + validator.success = false + validator.errors << "Not all of the error payload elements were present" + end - # event_elements = ['severity', 'severityReason.type', 'unhandled', 'exceptions'] - # events = Maze::Helper.read_key_path(validator.body, 'events') - # event_elements_present = events.all? do |event| - # event_elements.all? do |element_key| - # element = Maze::Helper.read_key_path(event, element_key) - # !element.nil? - # end - # end + event_elements = ['severity', 'severityReason.type', 'unhandled', 'exceptions'] + events = Maze::Helper.read_key_path(validator.body, 'events') + event_elements_present = events.all? do |event| + event_elements.all? do |element_key| + element = Maze::Helper.read_key_path(event, element_key) + !element.nil? + end + end - # unless event_elements_present - # validator.success = false - # validator.errors << "Not all of the event elements were present" - # end + unless event_elements_present + validator.success = false + validator.errors << "Not all of the event elements were present" + end pp "Error validation complete" pp validator.success pp validator.errors end -# Maze.config.add_validator('session') do |validator| -# pp "Running session validation" -# validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } -# validator.validate_header('Content-Type') { |value| value.eql?('application/json') } -# validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('1.0') } -# validator.validate_header('Bugsnag-Sent-At') do |value| -# begin -# Date.iso8601(date) -# rescue Date::Error -# validator.success = false -# validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" -# end -# end +Maze.config.add_validator('session') do |validator| + pp "Running session validation" + validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } + validator.validate_header('Content-Type') { |value| value.eql?('application/json') } + validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('1.0') } + validator.validate_header('Bugsnag-Sent-At') do |value| + begin + Date.iso8601(date) + rescue Date::Error + validator.success = false + validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + end + end -# notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') -# if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') -# validator.success = false -# validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" -# end + notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') + if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') + validator.success = false + validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" + end -# session_elements = ['notifier.url', 'notifier.version', 'events'] -# session_elements_present = session_elements.all? do |element_key| -# element = Maze::Helper.read_key_path(validator.body, element) -# !element.nil? && (!element.is_a?(Array) || !element.empty?) -# end + session_elements = ['notifier.url', 'notifier.version', 'events'] + session_elements_present = session_elements.all? do |element_key| + element = Maze::Helper.read_key_path(validator.body, element) + !element.nil? && (!element.is_a?(Array) || !element.empty?) + end -# unless session_elements_present -# validator.success = false -# validator.errors << "Not all of the session payload elements were present" -# end + unless session_elements_present + validator.success = false + validator.errors << "Not all of the session payload elements were present" + end -# pp "Session validation complete" -# pp validator.success -# pp validator.errors -# end + pp "Session validation complete" + pp validator.success + pp validator.errors +end From a6573d03817485549f77cd5719652f75f4064981 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Mon, 9 Sep 2024 17:33:12 +0100 Subject: [PATCH 08/16] Fix errors --- features/support/env.rb | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index b176b5e..b13ae52 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -8,13 +8,12 @@ end Maze.config.add_validator('error') do |validator| - pp "Running error validation" validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } validator.validate_header('Content-Type') { |value| value.eql?('application/json') } validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('4') } - validator.validate_header('Bugsnag-Sent-At') do |date| + validator.validate_header('Bugsnag-Sent-At') do |value| begin - Date.iso8601(date) + Date.iso8601(value) rescue Date::Error validator.success = false validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" @@ -29,7 +28,7 @@ error_elements = ['notifier.url', 'notifier.version', 'events'] error_elements_present = error_elements.all? do |element_key| - element = Maze::Helper.read_key_path(validator.body, element) + element = Maze::Helper.read_key_path(validator.body, element_key) !element.nil? && (!element.is_a?(Array) || !element.empty?) end @@ -51,19 +50,15 @@ validator.success = false validator.errors << "Not all of the event elements were present" end - pp "Error validation complete" - pp validator.success - pp validator.errors end Maze.config.add_validator('session') do |validator| - pp "Running session validation" validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } validator.validate_header('Content-Type') { |value| value.eql?('application/json') } validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('1.0') } validator.validate_header('Bugsnag-Sent-At') do |value| begin - Date.iso8601(date) + Date.iso8601(value) rescue Date::Error validator.success = false validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" @@ -78,7 +73,7 @@ session_elements = ['notifier.url', 'notifier.version', 'events'] session_elements_present = session_elements.all? do |element_key| - element = Maze::Helper.read_key_path(validator.body, element) + element = Maze::Helper.read_key_path(validator.body, element_key) !element.nil? && (!element.is_a?(Array) || !element.empty?) end @@ -86,8 +81,4 @@ validator.success = false validator.errors << "Not all of the session payload elements were present" end - - pp "Session validation complete" - pp validator.success - pp validator.errors end From 5c9f2594a4c3d348a5cbaac91f084914a6115111 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Mon, 9 Sep 2024 23:42:07 +0100 Subject: [PATCH 09/16] Debugging --- features/support/env.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index b13ae52..d517d85 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -8,6 +8,7 @@ end Maze.config.add_validator('error') do |validator| + pp validator.headers validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } validator.validate_header('Content-Type') { |value| value.eql?('application/json') } validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('4') } @@ -16,7 +17,7 @@ Date.iso8601(value) rescue Date::Error validator.success = false - validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + validator.errors << "bugsnag-sent-at header was expected to be an ISO 8601 date, but was '#{value}'" end end @@ -61,7 +62,7 @@ Date.iso8601(value) rescue Date::Error validator.success = false - validator.errors << "bugsnag-sent-at header was expected to be an IOS 8601 date, but was '#{date}'" + validator.errors << "bugsnag-sent-at header was expected to be an ISO 8601 date, but was '#{value}'" end end From 8380bce32709bf8ac6d8825aef9a13e10ad65ecb Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Mon, 9 Sep 2024 23:49:44 +0100 Subject: [PATCH 10/16] Debugging --- features/support/env.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index d517d85..9991fd6 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -9,10 +9,10 @@ Maze.config.add_validator('error') do |validator| pp validator.headers - validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } - validator.validate_header('Content-Type') { |value| value.eql?('application/json') } - validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('4') } - validator.validate_header('Bugsnag-Sent-At') do |value| + validator.validate_header('bugsnag-api-key') { |value| value.eql?($api_key) } + validator.validate_header('content-type') { |value| value.eql?('application/json') } + validator.validate_header('bugsnag-payload-version') { |value| value.eql?('4') } + validator.validate_header('bugsnag-sent-at') do |value| begin Date.iso8601(value) rescue Date::Error @@ -54,10 +54,10 @@ end Maze.config.add_validator('session') do |validator| - validator.validate_header('Bugsnag-Api-Key') { |value| value.eql?($api_key) } - validator.validate_header('Content-Type') { |value| value.eql?('application/json') } - validator.validate_header('Bugsnag-Payload-Version') { |value| value.eql?('1.0') } - validator.validate_header('Bugsnag-Sent-At') do |value| + validator.validate_header('bugsnag-api-key') { |value| value.eql?($api_key) } + validator.validate_header('content-type') { |value| value.eql?('application/json') } + validator.validate_header('bugsnag-payload-version') { |value| value.eql?('1.0') } + validator.validate_header('bugsnag-sent-at') do |value| begin Date.iso8601(value) rescue Date::Error From efa00c53ffb8fbb6461393f42ca543baed9dbdb3 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Mon, 9 Sep 2024 23:53:20 +0100 Subject: [PATCH 11/16] Remove debugging --- features/support/env.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index 9991fd6..3fa4e65 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -8,7 +8,6 @@ end Maze.config.add_validator('error') do |validator| - pp validator.headers validator.validate_header('bugsnag-api-key') { |value| value.eql?($api_key) } validator.validate_header('content-type') { |value| value.eql?('application/json') } validator.validate_header('bugsnag-payload-version') { |value| value.eql?('4') } From f95e72986c73ec0729774ecaa80c94fee8d029a0 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Tue, 10 Sep 2024 08:31:22 +0100 Subject: [PATCH 12/16] Reduce validator size --- features/support/env.rb | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 3fa4e65..0be2bd4 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -26,30 +26,24 @@ validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" end - error_elements = ['notifier.url', 'notifier.version', 'events'] - error_elements_present = error_elements.all? do |element_key| + ['notifier.url', 'notifier.version', 'events'].each? do |element_key| element = Maze::Helper.read_key_path(validator.body, element_key) - !element.nil? && (!element.is_a?(Array) || !element.empty?) - end - - unless error_elements_present - validator.success = false - validator.errors << "Not all of the error payload elements were present" + if element.nil? || (element.is_a?(Array) && element.empty?) + validator.success = false + validator.errors << "Required error element #{element_key} was not present" + end end - event_elements = ['severity', 'severityReason.type', 'unhandled', 'exceptions'] events = Maze::Helper.read_key_path(validator.body, 'events') - event_elements_present = events.all? do |event| - event_elements.all? do |element_key| + events.each_with_index do |event, index| + ['severity', 'severityReason.type', 'unhandled', 'exceptions'].each do |element_key| element = Maze::Helper.read_key_path(event, element_key) - !element.nil? + if element.nil? || (element.is_a?(Array) && element.empty?) + validator.success = false + validator.errors << "Required event element #{element_key} was not present in event #{index}" + end end end - - unless event_elements_present - validator.success = false - validator.errors << "Not all of the event elements were present" - end end Maze.config.add_validator('session') do |validator| @@ -71,14 +65,11 @@ validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" end - session_elements = ['notifier.url', 'notifier.version', 'events'] - session_elements_present = session_elements.all? do |element_key| + ['notifier.url', 'notifier.version', 'events'].each? do |element_key| element = Maze::Helper.read_key_path(validator.body, element_key) - !element.nil? && (!element.is_a?(Array) || !element.empty?) - end - - unless session_elements_present - validator.success = false - validator.errors << "Not all of the session payload elements were present" + if element.nil? || (element.is_a?(Array) && element.empty?) + validator.success = false + validator.errors << "Required session element #{element_key} was not present" + end end end From f3a0947bf9e02fd65a735399394d63d5a92bbbef Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Tue, 10 Sep 2024 08:33:24 +0100 Subject: [PATCH 13/16] Fix typo --- features/support/env.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 0be2bd4..5fff78a 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -26,7 +26,7 @@ validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" end - ['notifier.url', 'notifier.version', 'events'].each? do |element_key| + ['notifier.url', 'notifier.version', 'events'].each do |element_key| element = Maze::Helper.read_key_path(validator.body, element_key) if element.nil? || (element.is_a?(Array) && element.empty?) validator.success = false @@ -65,7 +65,7 @@ validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" end - ['notifier.url', 'notifier.version', 'events'].each? do |element_key| + ['notifier.url', 'notifier.version', 'events'].each do |element_key| element = Maze::Helper.read_key_path(validator.body, element_key) if element.nil? || (element.is_a?(Array) && element.empty?) validator.success = false From 61ef8f3e4a84485545d836e745d02527a2de8072 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Tue, 10 Sep 2024 08:40:36 +0100 Subject: [PATCH 14/16] Adjust session validation --- features/support/env.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index 5fff78a..110cc01 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -65,7 +65,7 @@ validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" end - ['notifier.url', 'notifier.version', 'events'].each do |element_key| + ['notifier.url', 'notifier.version', 'app', 'device'].each do |element_key| element = Maze::Helper.read_key_path(validator.body, element_key) if element.nil? || (element.is_a?(Array) && element.empty?) validator.success = false From 67304ce8c936880d394dab09577016d43c14614b Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Wed, 18 Sep 2024 16:55:29 +0100 Subject: [PATCH 15/16] Update to use simplified steps --- Gemfile | 2 +- features/support/env.rb | 60 +++++------------------------------------ 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/Gemfile b/Gemfile index 8a58451..9951dc1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' -gem "bugsnag-maze-runner", git: 'https://github.com/bugsnag/maze-runner', branch: 'dynamic-validation/config-changes' \ No newline at end of file +gem "bugsnag-maze-runner", git: 'https://github.com/bugsnag/maze-runner', branch: 'validation/extra-capabilities' \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index 110cc01..3235071 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -11,65 +11,19 @@ validator.validate_header('bugsnag-api-key') { |value| value.eql?($api_key) } validator.validate_header('content-type') { |value| value.eql?('application/json') } validator.validate_header('bugsnag-payload-version') { |value| value.eql?('4') } - validator.validate_header('bugsnag-sent-at') do |value| - begin - Date.iso8601(value) - rescue Date::Error - validator.success = false - validator.errors << "bugsnag-sent-at header was expected to be an ISO 8601 date, but was '#{value}'" - end - end + validator.validate_header('bugsnag-sent-at') { |value| Date.iso8601(value) } - notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') - if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') - validator.success = false - validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" - end - - ['notifier.url', 'notifier.version', 'events'].each do |element_key| - element = Maze::Helper.read_key_path(validator.body, element_key) - if element.nil? || (element.is_a?(Array) && element.empty?) - validator.success = false - validator.errors << "Required error element #{element_key} was not present" - end - end - - events = Maze::Helper.read_key_path(validator.body, 'events') - events.each_with_index do |event, index| - ['severity', 'severityReason.type', 'unhandled', 'exceptions'].each do |element_key| - element = Maze::Helper.read_key_path(event, element_key) - if element.nil? || (element.is_a?(Array) && element.empty?) - validator.success = false - validator.errors << "Required event element #{element_key} was not present in event #{index}" - end - end - end + validator.element_has_value('notifier.name', 'Bugsnag Go') + validator.each_element_exists(['notifier.url', 'notifier.version', 'events']) + validator.each_event_contains_each(['severity', 'severityReason.type', 'unhandled', 'exceptions']) end Maze.config.add_validator('session') do |validator| validator.validate_header('bugsnag-api-key') { |value| value.eql?($api_key) } validator.validate_header('content-type') { |value| value.eql?('application/json') } validator.validate_header('bugsnag-payload-version') { |value| value.eql?('1.0') } - validator.validate_header('bugsnag-sent-at') do |value| - begin - Date.iso8601(value) - rescue Date::Error - validator.success = false - validator.errors << "bugsnag-sent-at header was expected to be an ISO 8601 date, but was '#{value}'" - end - end - - notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name') - if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go') - validator.success = false - validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'" - end + validator.validate_header('bugsnag-sent-at') { |value| Date.iso8601(value) } - ['notifier.url', 'notifier.version', 'app', 'device'].each do |element_key| - element = Maze::Helper.read_key_path(validator.body, element_key) - if element.nil? || (element.is_a?(Array) && element.empty?) - validator.success = false - validator.errors << "Required session element #{element_key} was not present" - end - end + validator.element_has_value('notifier.name', 'Bugsnag Go') + validator.each_element_exists(['notifier.url', 'notifier.version', 'app', 'device']) end From d251a0aab8faa80a943b0005d0142e1ec48e1d53 Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Mon, 23 Sep 2024 17:04:12 +0100 Subject: [PATCH 16/16] Use a released version of maze-runner --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 9951dc1..12edf99 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' -gem "bugsnag-maze-runner", git: 'https://github.com/bugsnag/maze-runner', branch: 'validation/extra-capabilities' \ No newline at end of file +gem "bugsnag-maze-runner", "~> 9.14" \ No newline at end of file