@@ -19,10 +19,14 @@ module Agents |
||
| 19 | 19 |
def handle_details_post(params) |
| 20 | 20 |
if params['payload'] |
| 21 | 21 |
json = interpolate_options(JSON.parse(params['payload'])) |
| 22 |
- [json['payloads'] || json].flatten.each do |payload| |
|
| 23 |
- create_event(:payload => payload) |
|
| 22 |
+ if json['payloads'] && (json.keys - ['payloads']).length > 0 |
|
| 23 |
+ { :success => false, :error => "If you provide the 'payloads' key, please do not provide any other keys at the top level." }
|
|
| 24 |
+ else |
|
| 25 |
+ [json['payloads'] || json].flatten.each do |payload| |
|
| 26 |
+ create_event(:payload => payload) |
|
| 27 |
+ end |
|
| 28 |
+ { :success => true }
|
|
| 24 | 29 |
end |
| 25 |
- { :success => true }
|
|
| 26 | 30 |
else |
| 27 | 31 |
{ :success => false, :error => "You must provide a JSON payload" }
|
| 28 | 32 |
end |
@@ -26,6 +26,13 @@ describe Agents::ManualEventAgent do |
||
| 26 | 26 |
expect(events[1].payload).to eq({ 'key' => 'value1' })
|
| 27 | 27 |
end |
| 28 | 28 |
|
| 29 |
+ it "errors when given both payloads and other top-level keys" do |
|
| 30 |
+ expect {
|
|
| 31 |
+ json = { 'key' => 'value2', 'payloads' => [{ 'key' => 'value1' }] }.to_json
|
|
| 32 |
+ expect(@checker.handle_details_post({ 'payload' => json })).to eq({ success: false, error: "If you provide the 'payloads' key, please do not provide any other keys at the top level." })
|
|
| 33 |
+ }.to_not change { @checker.events.count }
|
|
| 34 |
+ end |
|
| 35 |
+ |
|
| 29 | 36 |
it "supports Liquid formatting" do |
| 30 | 37 |
expect {
|
| 31 | 38 |
json = { 'key' => "{{ 'now' | date: '%Y' }}", 'nested' => { 'lowercase' => "{{ 'uppercase' | upcase }}" } }.to_json
|