logstash-input-http 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 534e946ab5a99a0cea05527407fb947a98cf5954
4
- data.tar.gz: 27a938c700bf26c8974dcce09193bd68e8528073
3
+ metadata.gz: 60c60f0e309dd3a4cf01991820faf682b1d20b60
4
+ data.tar.gz: 8d10272305ecb4fbf7c13eeb527fbfc3a3b15c58
5
5
  SHA512:
6
- metadata.gz: 74be876e68c810ef845ebae2d1ffedb286d1096db92413eeb337cbbfa170cc74f3f8d99f97bc730c57bd0ed2529f6438ff6a3cc1e6c5f53a276c94f6df00e768
7
- data.tar.gz: 3b750c32d76e858e2526da40d8a98dc569eac41d2810f8c8433a8b2eb776b5fd951fc168eef6723491f97f578d3a2c4baa5a8624e92be7bed881e862b10c8c98
6
+ metadata.gz: c0251a7b4d3be7bdd20ab639fbb7c4947ff469cbfcecda0160fdca73dc19c28958f0429d5476e1d1fad697b70179120b73ca363fa86ce22a8de11d4e94b13515
7
+ data.tar.gz: a7110b84f71e5d5ca88e8b8cb5071dacdef98687c6b5d8e74e50180ee50b3c2e0d9b17962d96754a51dda909abdefcd68e3ae56b5dab25fb6c321028e2fa385e
@@ -1,3 +1,5 @@
1
+ ## 3.0.2
2
+ - Use a new class as redefined Puma::Server class as we need to mock one method and only need it for this plugin, but not for all parts using puma in logstash.Fixes https://github.com/logstash-plugins/logstash-input-http/issues/51.
1
3
  ## 3.0.1
2
4
  - Republish all the gems under jruby.
3
5
  ## 3.0.0
@@ -8,7 +8,15 @@ require "puma/minissl"
8
8
  require "base64"
9
9
  require "rack"
10
10
 
11
- class Puma::Server
11
+
12
+ ##
13
+ # We keep the redefined method in a new http server class, this is because
14
+ # in other parts of logstash we might be using puma as webserver, for example
15
+ # in the sinatra part we need this method to actually return the REQUEST_PATH,
16
+ # so it can actually infer the right resource to use.
17
+ # Fixes https://github.com/logstash-plugins/logstash-input-http/issues/51
18
+ ##
19
+ class HTTPInputWebServer < Puma::Server
12
20
  # ensure this method doesn't mess up our vanilla request
13
21
  def normalize_env(env, client); end
14
22
  end
@@ -87,7 +95,7 @@ class LogStash::Inputs::Http < LogStash::Inputs::Base
87
95
  public
88
96
  def register
89
97
  require "logstash/util/http_compressed_requests"
90
- @server = ::Puma::Server.new(nil) # we'll set the rack handler later
98
+ @server = ::HTTPInputWebServer.new(nil) # we'll set the rack handler later
91
99
  if @user && @password then
92
100
  token = Base64.strict_encode64("#{@user}:#{@password.value}")
93
101
  @auth_token = "Basic #{token}"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-http'
3
- s.version = '3.0.1'
3
+ s.version = '3.0.2'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Logstash Input plugin that receives HTTP requests"
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -16,149 +16,179 @@ describe LogStash::Inputs::Http do
16
16
  let(:queue) { Queue.new }
17
17
  let(:port) { rand(5000) + 1025 }
18
18
 
19
- after :each do
20
- subject.stop
21
- end
22
-
23
19
  it_behaves_like "an interruptible input plugin" do
24
20
  let(:config) { { "port" => port } }
25
21
  end
26
22
 
27
- describe "#run" do
23
+ after :each do
24
+ subject.stop
25
+ end
26
+
27
+ describe "request handling" do
28
28
  subject { LogStash::Inputs::Http.new }
29
29
  before :each do
30
30
  subject.register
31
- Thread.new { subject.run(queue) }
31
+ t = Thread.new { subject.run(queue) }
32
+ sleep 0.01 until subject.instance_variable_get(:@server).running == 0
32
33
  end
34
+
33
35
  it "should include remote host in \"host\" property" do
34
36
  agent.post!("http://localhost:8080/meh.json",
35
- :headers => { "content-type" => "text/plain" },
36
- :body => "hello")
37
+ :headers => { "content-type" => "text/plain" },
38
+ :body => "hello")
37
39
  event = queue.pop
38
40
  expect(event.get("host")).to eq("127.0.0.1")
39
41
  end
40
- end
41
42
 
42
- context "with default codec" do
43
- subject { LogStash::Inputs::Http.new("port" => port) }
44
- context "when receiving a text/plain request" do
45
- it "should process the request normally" do
46
- subject.register
47
- Thread.new { subject.run(queue) }
48
- agent.post!("http://localhost:#{port}/meh.json",
49
- :headers => { "content-type" => "text/plain" },
50
- :body => "hello")
51
- event = queue.pop
52
- expect(event.get("message")).to eq("hello")
53
- end
54
- end
55
- context "when receiving a deflate compressed text/plain request" do
56
- it "should process the request normally" do
57
- subject.register
58
- Thread.new { subject.run(queue) }
59
- agent.post!("http://localhost:#{port}/meh.json",
60
- :headers => { "content-type" => "text/plain", "content-encoding" => "deflate" },
61
- :body => Zlib::Deflate.deflate("hello"))
62
- event = queue.pop
63
- expect(event.get("message")).to eq("hello")
64
- end
65
- end
66
- context "when receiving a deflate text/plain request that cannot be decompressed" do
67
- let!(:response) do
68
- subject.register
69
- Thread.new { subject.run(queue) }
70
- agent.post!("http://localhost:#{port}/meh.json",
71
- :headers => { "content-type" => "text/plain", "content-encoding" => "deflate" },
72
- :body => "hello")
73
- end
74
- it "should respond with 400" do
75
- expect(response.status).to eq(400)
76
- end
77
- it "should respond with a decompression error" do
78
- expect(response.read_body).to eq("Failed to decompress body")
43
+ context "with default codec" do
44
+ subject { LogStash::Inputs::Http.new("port" => port) }
45
+ context "when receiving a text/plain request" do
46
+ it "should process the request normally" do
47
+ agent.post!("http://localhost:#{port}/meh.json",
48
+ :headers => { "content-type" => "text/plain" },
49
+ :body => "hello")
50
+ event = queue.pop
51
+ expect(event.get("message")).to eq("hello")
52
+ end
53
+ end
54
+ context "when receiving a deflate compressed text/plain request" do
55
+ it "should process the request normally" do
56
+ agent.post!("http://localhost:#{port}/meh.json",
57
+ :headers => { "content-type" => "text/plain", "content-encoding" => "deflate" },
58
+ :body => Zlib::Deflate.deflate("hello"))
59
+ event = queue.pop
60
+ expect(event.get("message")).to eq("hello")
61
+ end
62
+ end
63
+ context "when receiving a deflate text/plain request that cannot be decompressed" do
64
+ it "should respond with 400" do
65
+ response = agent.post!("http://localhost:#{port}/meh.json",
66
+ :headers => { "content-type" => "text/plain", "content-encoding" => "deflate" },
67
+ :body => "hello")
68
+ expect(response.status).to eq(400)
69
+ end
70
+ it "should respond with a decompression error" do
71
+ response = agent.post!("http://localhost:#{port}/meh.json",
72
+ :headers => { "content-type" => "text/plain", "content-encoding" => "deflate" },
73
+ :body => "hello")
74
+ expect(response.read_body).to eq("Failed to decompress body")
75
+ end
76
+ end
77
+ context "when receiving a gzip compressed text/plain request" do
78
+ it "should process the request normally" do
79
+ z = StringIO.new ""
80
+ w = Zlib::GzipWriter.new z
81
+ w.write("hello")
82
+ w.finish
83
+ agent.post!("http://localhost:#{port}/meh.json",
84
+ :headers => { "content-type" => "text/plain", "content-encoding" => "gzip" },
85
+ :body => z.string)
86
+ event = queue.pop
87
+ expect(event.get("message")).to eq("hello")
88
+ end
89
+ end
90
+ context "when receiving a gzip text/plain request that cannot be decompressed" do
91
+ let(:response) do
92
+ agent.post!("http://localhost:#{port}/meh.json",
93
+ :headers => { "content-type" => "text/plain", "content-encoding" => "gzip" },
94
+ :body => "hello")
95
+ end
96
+ it "should respond with 400" do
97
+ expect(response.status).to eq(400)
98
+ end
99
+ it "should respond with a decompression error" do
100
+ expect(response.read_body).to eq("Failed to decompress body")
101
+ end
102
+ end
103
+ context "when receiving an application/json request" do
104
+ it "should parse the json body" do
105
+ agent.post!("http://localhost:#{port}/meh.json",
106
+ :headers => { "content-type" => "application/json" },
107
+ :body => { "message_body" => "Hello" }.to_json)
108
+ event = queue.pop
109
+ expect(event.get("message_body")).to eq("Hello")
110
+ end
79
111
  end
80
112
  end
81
- context "when receiving a gzip compressed text/plain request" do
82
- it "should process the request normally" do
83
- subject.register
84
- Thread.new { subject.run(queue) }
85
- z = StringIO.new ""
86
- w = Zlib::GzipWriter.new z
87
- w.write("hello")
88
- w.finish
89
- agent.post!("http://localhost:#{port}/meh.json",
90
- :headers => { "content-type" => "text/plain", "content-encoding" => "gzip" },
91
- :body => z.string)
113
+ context "with json codec" do
114
+ subject { LogStash::Inputs::Http.new("port" => port, "codec" => "json") }
115
+ it "should parse the json body" do
116
+ agent.post!("http://localhost:#{port}/meh.json", :body => { "message" => "Hello" }.to_json)
92
117
  event = queue.pop
93
- expect(event.get("message")).to eq("hello")
94
- end
95
- end
96
- context "when receiving a gzip text/plain request that cannot be decompressed" do
97
- let!(:response) do
98
- subject.register
99
- Thread.new { subject.run(queue) }
100
- agent.post!("http://localhost:#{port}/meh.json",
101
- :headers => { "content-type" => "text/plain", "content-encoding" => "gzip" },
102
- :body => "hello")
103
- end
104
- it "should respond with 400" do
105
- expect(response.status).to eq(400)
106
- end
107
- it "should respond with a decompression error" do
108
- expect(response.read_body).to eq("Failed to decompress body")
118
+ expect(event.get("message")).to eq("Hello")
109
119
  end
110
120
  end
111
- context "when receiving an application/json request" do
112
- it "should parse the json body" do
113
- subject.register
114
- Thread.new { subject.run(queue) }
121
+
122
+ context "when using a custom codec mapping" do
123
+ subject { LogStash::Inputs::Http.new("port" => port,
124
+ "additional_codecs" => { "application/json" => "plain" }) }
125
+ it "should decode the message accordingly" do
126
+ body = { "message" => "Hello" }.to_json
115
127
  agent.post!("http://localhost:#{port}/meh.json",
116
128
  :headers => { "content-type" => "application/json" },
117
- :body => { "message_body" => "Hello" }.to_json)
129
+ :body => body)
118
130
  event = queue.pop
119
- expect(event.get("message_body")).to eq("Hello")
131
+ expect(event.get("message")).to eq(body)
120
132
  end
121
133
  end
122
- end
123
-
124
- context "with json codec" do
125
- subject { LogStash::Inputs::Http.new("port" => port, "codec" => "json") }
126
- it "should parse the json body" do
127
- subject.register
128
- Thread.new { subject.run(queue) }
129
- agent.post!("http://localhost:#{port}/meh.json", :body => { "message" => "Hello" }.to_json)
130
- event = queue.pop
131
- expect(event.get("message")).to eq("Hello")
132
- end
133
- end
134
-
135
- context "when using a custom codec mapping" do
136
- subject { LogStash::Inputs::Http.new("port" => port,
137
- "additional_codecs" => { "application/json" => "plain" }) }
138
- it "should decode the message accordingly" do
139
- body = { "message" => "Hello" }.to_json
140
- subject.register
141
- Thread.new { subject.run(queue) }
142
- agent.post!("http://localhost:#{port}/meh.json",
143
- :headers => { "content-type" => "application/json" },
144
- :body => body)
145
- event = queue.pop
146
- expect(event.get("message")).to eq(body)
147
- end
148
- end
149
134
 
150
- context "when using custom headers" do
151
- let(:custom_headers) { { 'access-control-allow-origin' => '*' } }
152
- subject { LogStash::Inputs::Http.new("port" => port, "response_headers" => custom_headers) }
135
+ context "when using custom headers" do
136
+ let(:custom_headers) { { 'access-control-allow-origin' => '*' } }
137
+ subject { LogStash::Inputs::Http.new("port" => port, "response_headers" => custom_headers) }
153
138
 
154
- describe "the response" do
155
- it "should include the custom headers" do
156
- subject.register
157
- Thread.new { subject.run(queue) }
158
- response = agent.post!("http://localhost:#{port}/meh", :body => "hello")
159
- expect(response.headers.to_hash).to include(custom_headers)
139
+ describe "the response" do
140
+ it "should include the custom headers" do
141
+ response = agent.post!("http://localhost:#{port}/meh", :body => "hello")
142
+ expect(response.headers.to_hash).to include(custom_headers)
143
+ end
144
+ end
145
+ end
146
+ describe "basic auth" do
147
+ user = "test"; password = "pwd"
148
+ subject { LogStash::Inputs::Http.new("port" => port, "user" => user, "password" => password) }
149
+ let(:auth_token) { Base64.strict_encode64("#{user}:#{password}") }
150
+ context "when client doesn't present auth token" do
151
+ let!(:response) { agent.post!("http://localhost:#{port}/meh", :body => "hi") }
152
+ it "should respond with 401" do
153
+ expect(response.status).to eq(401)
154
+ end
155
+ it "should not generate an event" do
156
+ expect(queue).to be_empty
157
+ end
158
+ end
159
+ context "when client presents incorrect auth token" do
160
+ let!(:response) do
161
+ agent.post!("http://localhost:#{port}/meh",
162
+ :headers => {
163
+ "content-type" => "text/plain",
164
+ "authorization" => "Basic meh"
165
+ },
166
+ :body => "hi")
167
+ end
168
+ it "should respond with 401" do
169
+ expect(response.status).to eq(401)
170
+ end
171
+ it "should not generate an event" do
172
+ expect(queue).to be_empty
173
+ end
174
+ end
175
+ context "when client presents correct auth token" do
176
+ let!(:response) do
177
+ agent.post!("http://localhost:#{port}/meh",
178
+ :headers => {
179
+ "content-type" => "text/plain",
180
+ "authorization" => "Basic #{auth_token}"
181
+ }, :body => "hi")
182
+ end
183
+ it "should respond with 200" do
184
+ expect(response.status).to eq(200)
185
+ end
186
+ it "should generate an event" do
187
+ expect(queue).to_not be_empty
188
+ end
160
189
  end
161
190
  end
191
+
162
192
  end
163
193
 
164
194
  context "with :ssl => false" do
@@ -184,53 +214,4 @@ describe LogStash::Inputs::Http do
184
214
  end
185
215
  end
186
216
  end
187
- describe "basic auth" do
188
- user = "test"; password = "pwd"
189
- subject { LogStash::Inputs::Http.new("port" => port, "user" => user, "password" => password) }
190
- let(:auth_token) { Base64.strict_encode64("#{user}:#{password}") }
191
- before :each do
192
- subject.register
193
- Thread.new { subject.run(queue) }
194
- end
195
- context "when client doesn't present auth token" do
196
- let!(:response) { agent.post!("http://localhost:#{port}/meh", :body => "hi") }
197
- it "should respond with 401" do
198
- expect(response.status).to eq(401)
199
- end
200
- it "should not generate an event" do
201
- expect(queue).to be_empty
202
- end
203
- end
204
- context "when client presents incorrect auth token" do
205
- let!(:response) do
206
- agent.post!("http://localhost:#{port}/meh",
207
- :headers => {
208
- "content-type" => "text/plain",
209
- "authorization" => "Basic meh"
210
- },
211
- :body => "hi")
212
- end
213
- it "should respond with 401" do
214
- expect(response.status).to eq(401)
215
- end
216
- it "should not generate an event" do
217
- expect(queue).to be_empty
218
- end
219
- end
220
- context "when client presents correct auth token" do
221
- let!(:response) do
222
- agent.post!("http://localhost:#{port}/meh",
223
- :headers => {
224
- "content-type" => "text/plain",
225
- "authorization" => "Basic #{auth_token}"
226
- }, :body => "hi")
227
- end
228
- it "should respond with 200" do
229
- expect(response.status).to eq(200)
230
- end
231
- it "should generate an event" do
232
- expect(queue).to_not be_empty
233
- end
234
- end
235
- end
236
217
  end
metadata CHANGED
@@ -1,133 +1,133 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: logstash-core-plugin-api
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
14
20
  requirement: !ruby/object:Gem::Requirement
15
21
  requirements:
16
- - - "~>"
22
+ - - ~>
17
23
  - !ruby/object:Gem::Version
18
24
  version: '2.0'
19
- name: logstash-core-plugin-api
20
25
  prerelease: false
21
26
  type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: logstash-codec-plain
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
- - - "~>"
31
+ - - '>='
25
32
  - !ruby/object:Gem::Version
26
- version: '2.0'
27
- - !ruby/object:Gem::Dependency
33
+ version: '0'
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
- - - ">="
36
+ - - '>='
31
37
  - !ruby/object:Gem::Version
32
38
  version: '0'
33
- name: logstash-codec-plain
34
39
  prerelease: false
35
40
  type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: stud
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - ">="
45
+ - - '>='
39
46
  - !ruby/object:Gem::Version
40
47
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
- - - ">="
50
+ - - '>='
45
51
  - !ruby/object:Gem::Version
46
52
  version: '0'
47
- name: stud
48
53
  prerelease: false
49
54
  type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: puma
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ">="
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
61
+ version: '2.16'
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: 2.16.0
56
65
  requirement: !ruby/object:Gem::Requirement
57
66
  requirements:
58
- - - "~>"
67
+ - - ~>
59
68
  - !ruby/object:Gem::Version
60
69
  version: '2.16'
61
- - - ">="
70
+ - - '>='
62
71
  - !ruby/object:Gem::Version
63
72
  version: 2.16.0
64
- name: puma
65
73
  prerelease: false
66
74
  type: :runtime
75
+ - !ruby/object:Gem::Dependency
76
+ name: rack
67
77
  version_requirements: !ruby/object:Gem::Requirement
68
78
  requirements:
69
- - - "~>"
70
- - !ruby/object:Gem::Version
71
- version: '2.16'
72
- - - ">="
79
+ - - ~>
73
80
  - !ruby/object:Gem::Version
74
- version: 2.16.0
75
- - !ruby/object:Gem::Dependency
81
+ version: '1'
76
82
  requirement: !ruby/object:Gem::Requirement
77
83
  requirements:
78
- - - "~>"
84
+ - - ~>
79
85
  - !ruby/object:Gem::Version
80
86
  version: '1'
81
- name: rack
82
87
  prerelease: false
83
88
  type: :runtime
89
+ - !ruby/object:Gem::Dependency
90
+ name: logstash-devutils
84
91
  version_requirements: !ruby/object:Gem::Requirement
85
92
  requirements:
86
- - - "~>"
93
+ - - '>='
87
94
  - !ruby/object:Gem::Version
88
- version: '1'
89
- - !ruby/object:Gem::Dependency
95
+ version: '0'
90
96
  requirement: !ruby/object:Gem::Requirement
91
97
  requirements:
92
- - - ">="
98
+ - - '>='
93
99
  - !ruby/object:Gem::Version
94
100
  version: '0'
95
- name: logstash-devutils
96
101
  prerelease: false
97
102
  type: :development
103
+ - !ruby/object:Gem::Dependency
104
+ name: logstash-codec-json
98
105
  version_requirements: !ruby/object:Gem::Requirement
99
106
  requirements:
100
- - - ">="
107
+ - - '>='
101
108
  - !ruby/object:Gem::Version
102
109
  version: '0'
103
- - !ruby/object:Gem::Dependency
104
110
  requirement: !ruby/object:Gem::Requirement
105
111
  requirements:
106
- - - ">="
112
+ - - '>='
107
113
  - !ruby/object:Gem::Version
108
114
  version: '0'
109
- name: logstash-codec-json
110
115
  prerelease: false
111
116
  type: :development
117
+ - !ruby/object:Gem::Dependency
118
+ name: ftw
112
119
  version_requirements: !ruby/object:Gem::Requirement
113
120
  requirements:
114
- - - ">="
121
+ - - '>='
115
122
  - !ruby/object:Gem::Version
116
123
  version: '0'
117
- - !ruby/object:Gem::Dependency
118
124
  requirement: !ruby/object:Gem::Requirement
119
125
  requirements:
120
- - - ">="
126
+ - - '>='
121
127
  - !ruby/object:Gem::Version
122
128
  version: '0'
123
- name: ftw
124
129
  prerelease: false
125
130
  type: :development
126
- version_requirements: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: '0'
131
131
  description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program
132
132
  email: info@elastic.co
133
133
  executables: []
@@ -156,19 +156,20 @@ require_paths:
156
156
  - lib
157
157
  required_ruby_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - ">="
159
+ - - '>='
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  requirements: []
168
168
  rubyforge_project:
169
- rubygems_version: 2.4.8
169
+ rubygems_version: 2.4.6
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Logstash Input plugin that receives HTTP requests
173
173
  test_files:
174
174
  - spec/inputs/http_spec.rb
175
+ has_rdoc: