diff --git a/app/models/agents/trigger_agent.rb b/app/models/agents/trigger_agent.rb index bf6ee7796d..147da166d9 100644 --- a/app/models/agents/trigger_agent.rb +++ b/app/models/agents/trigger_agent.rb @@ -53,8 +53,9 @@ class TriggerAgent < Agent when String true when Hash - rule.values_at('type', 'value', 'path').all?(&:present?) && - VALID_COMPARISON_TYPES.include?(rule['type']) + VALID_COMPARISON_TYPES.include?(rule['type']) && + rule['path'].match?(/\S/) && + rule['value'].is_a?(String) else false end diff --git a/spec/models/agents/trigger_agent_spec.rb b/spec/models/agents/trigger_agent_spec.rb index 637f72b1b5..468fd6098d 100644 --- a/spec/models/agents/trigger_agent_spec.rb +++ b/spec/models/agents/trigger_agent_spec.rb @@ -82,10 +82,12 @@ it "should validate the three fields in each rule" do @checker.options['rules'] << { 'path' => "foo", 'type' => "fake", 'value' => "6" } expect(@checker).not_to be_valid - @checker.options['rules'].last['type'] = "field>=value" + @checker.options['rules'].last['type'] = "field!=value" expect(@checker).to be_valid @checker.options['rules'].last.delete('value') expect(@checker).not_to be_valid + @checker.options['rules'].last['value'] = '' + expect(@checker).to be_valid end it "should validate non-hash rules" do