@@ -39,7 +39,7 @@ module Agents |
||
| 39 | 39 |
|
| 40 | 40 |
def receive_web_request(params, method, format) |
| 41 | 41 |
secret = params.delete('secret')
|
| 42 |
- verbs = (options['verbs'] ? options['verbs'] : 'post').split(';')
|
|
| 42 |
+ verbs = (options['verbs'] ? options['verbs'] : 'post').split(/[,;]/).map { |x| x.strip.downcase }
|
|
| 43 | 43 |
return ["Please use #{verbs.join('/').upcase} requests only", 401] unless verbs.include?(method)
|
| 44 | 44 |
return ["Not Authorized", 401] unless secret == interpolated['secret'] |
| 45 | 45 |
|
@@ -164,6 +164,36 @@ describe Agents::WebhookAgent do |
||
| 164 | 164 |
|
| 165 | 165 |
end |
| 166 | 166 |
|
| 167 |
+ context "flaky content with commas" do |
|
| 168 |
+ |
|
| 169 |
+ before { agent.options['verbs'] = ';; PUT,POST; gEt , ;' }
|
|
| 170 |
+ |
|
| 171 |
+ it "should accept PUT" do |
|
| 172 |
+ out = nil |
|
| 173 |
+ expect {
|
|
| 174 |
+ out = agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload }, "put", "text/html")
|
|
| 175 |
+ }.to change { Event.count }.by(1)
|
|
| 176 |
+ expect(out).to eq(['Event Created', 201]) |
|
| 177 |
+ end |
|
| 178 |
+ |
|
| 179 |
+ it "should accept GET" do |
|
| 180 |
+ out = nil |
|
| 181 |
+ expect {
|
|
| 182 |
+ out = agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload }, "get", "text/html")
|
|
| 183 |
+ }.to change { Event.count }.by(1)
|
|
| 184 |
+ expect(out).to eq(['Event Created', 201]) |
|
| 185 |
+ end |
|
| 186 |
+ |
|
| 187 |
+ it "should accept POST" do |
|
| 188 |
+ out = nil |
|
| 189 |
+ expect {
|
|
| 190 |
+ out = agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload }, "post", "text/html")
|
|
| 191 |
+ }.to change { Event.count }.by(1)
|
|
| 192 |
+ expect(out).to eq(['Event Created', 201]) |
|
| 193 |
+ end |
|
| 194 |
+ |
|
| 195 |
+ end |
|
| 196 |
+ |
|
| 167 | 197 |
end |
| 168 | 198 |
|
| 169 | 199 |
end |