@@ -7,8 +7,6 @@ class HttpPullInputTest < Test::Unit::TestCase
77 @stub_server = nil
88
99 setup do
10- Fluent ::Test . setup
11-
1210 @stub_server = StubServer . new
1311 @stub_server . start
1412 end
@@ -39,6 +37,27 @@ class HttpPullInputTest < Test::Unit::TestCase
3937
4038 assert_equal ( 10 , d . instance . timeout )
4139 end
40+
41+ test 'user' do
42+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
43+ assert_equal ( "test" , d . instance . tag )
44+
45+ assert_equal ( nil , d . instance . user )
46+ end
47+
48+ test 'password' do
49+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
50+ assert_equal ( "test" , d . instance . tag )
51+
52+ assert_equal ( nil , d . instance . password )
53+ end
54+
55+ test 'proxy' do
56+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
57+ assert_equal ( "test" , d . instance . tag )
58+
59+ assert_equal ( nil , d . instance . proxy )
60+ end
4261 end
4362
4463 sub_test_case "success case" do
@@ -245,6 +264,195 @@ class HttpPullInputTest < Test::Unit::TestCase
245264 end
246265 end
247266
267+ sub_test_case "remote is prtected by basic auth" do
268+ TEST_AUTH_SUCCESS_CONFIG = %[
269+ tag test
270+ url http://127.0.0.1:3939/protected
271+ timeout 2s
272+ user HatsuneMiku
273+ password 3939
274+
275+ interval 3s
276+ format json
277+ ]
278+
279+ TEST_AUTH_FAIL_CONFIG = %[
280+ tag test
281+ url http://127.0.0.1:3939/protected
282+ timeout 2s
283+ user HatsuneMiku
284+ password wrong_password
285+
286+ interval 3s
287+ format json
288+ ]
289+
290+ TEST_AUTH_FAIL_NOT_GIVEN_CONFIG = %[
291+ tag test
292+ url http://127.0.0.1:3939/protected
293+ timeout 2s
294+
295+ interval 3s
296+ format json
297+ ]
298+
299+ test 'interval 3 with corrent password' do
300+ d = create_driver TEST_AUTH_SUCCESS_CONFIG
301+ assert_equal ( "test" , d . instance . tag )
302+ assert_equal ( 3 , d . instance . interval )
303+
304+ d . run ( timeout : 8 ) do
305+ sleep 7
306+ end
307+ assert_equal ( 2 , d . events . size )
308+
309+ d . events . each do |tag , time , record |
310+ assert_equal ( "test" , tag )
311+
312+ assert_equal ( { "url" => "http://127.0.0.1:3939/protected" , "status" => 200 , "message" => { "status" => "OK" } } , record )
313+ assert ( time . is_a? ( Fluent ::EventTime ) )
314+ end
315+ end
316+
317+ test 'interval 3 with wrong password' do
318+ d = create_driver TEST_AUTH_FAIL_CONFIG
319+ assert_equal ( "test" , d . instance . tag )
320+ assert_equal ( 3 , d . instance . interval )
321+
322+ d . run ( timeout : 8 ) do
323+ sleep 7
324+ end
325+ assert_equal ( 2 , d . events . size )
326+
327+ d . events . each do |tag , time , record |
328+ assert_equal ( "test" , tag )
329+
330+ assert_equal ( "http://127.0.0.1:3939/protected" , record [ "url" ] )
331+ assert ( time . is_a? ( Fluent ::EventTime ) )
332+
333+ assert_equal ( 401 , record [ "status" ] )
334+ assert_not_nil ( record [ "error" ] )
335+ end
336+ end
337+
338+ test 'interval 3 without auth info' do
339+ d = create_driver TEST_AUTH_FAIL_CONFIG
340+ assert_equal ( "test" , d . instance . tag )
341+ assert_equal ( 3 , d . instance . interval )
342+
343+ d . run ( timeout : 8 ) do
344+ sleep 7
345+ end
346+ assert_equal ( 2 , d . events . size )
347+
348+ d . events . each do |tag , time , record |
349+ assert_equal ( "test" , tag )
350+
351+ assert_equal ( "http://127.0.0.1:3939/protected" , record [ "url" ] )
352+ assert ( time . is_a? ( Fluent ::EventTime ) )
353+
354+ assert_equal ( 401 , record [ "status" ] )
355+ assert_not_nil ( record [ "error" ] )
356+ end
357+ end
358+ end
359+
360+ sub_test_case "success case behind proxy" do
361+ TEST_INTERVAL_3_PROXY_CONFIG = %[
362+ tag test
363+ url http://127.0.0.1:3939
364+ proxy http://127.0.0.1:4040
365+
366+ interval 3s
367+ format none
368+ status_only true
369+ ]
370+
371+ TEST_INTERVAL_3_REDIRECT_PROXY_CONFIG = %[
372+ tag test
373+ url http://127.0.0.1:3939/redirect
374+ proxy http://127.0.0.1:4040
375+
376+ interval 3s
377+ format json
378+ ]
379+
380+ TEST_AUTH_SUCCESS_PROXY_CONFIG = %[
381+ tag test
382+ url http://127.0.0.1:3939/protected
383+ proxy http://127.0.0.1:4040
384+ timeout 2s
385+ user HatsuneMiku
386+ password 3939
387+
388+ interval 3s
389+ format json
390+ ]
391+
392+ setup do
393+ @proxy_server = StubProxy . new
394+ @proxy_server . start
395+ end
396+
397+ teardown do
398+ @proxy_server . shutdown
399+ end
400+
401+ test 'interval 3 with status_only' do
402+ d = create_driver TEST_INTERVAL_3_PROXY_CONFIG
403+ assert_equal ( "test" , d . instance . tag )
404+ assert_equal ( 3 , d . instance . interval )
405+
406+ d . run ( timeout : 8 ) do
407+ sleep 7
408+ end
409+ assert_equal ( 2 , d . events . size )
410+
411+ d . events . each do |tag , time , record |
412+ assert_equal ( "test" , tag )
413+
414+ assert_equal ( { "url" => "http://127.0.0.1:3939" , "status" => 200 } , record )
415+ assert ( time . is_a? ( Fluent ::EventTime ) )
416+ end
417+ end
418+
419+ test 'interval 3 with redirect' do
420+ d = create_driver TEST_INTERVAL_3_REDIRECT_PROXY_CONFIG
421+ assert_equal ( "test" , d . instance . tag )
422+ assert_equal ( 3 , d . instance . interval )
423+
424+ d . run ( timeout : 8 ) do
425+ sleep 7
426+ end
427+ assert_equal ( 2 , d . events . size )
428+
429+ d . events . each do |tag , time , record |
430+ assert_equal ( "test" , tag )
431+
432+ assert_equal ( { "url" => "http://127.0.0.1:3939/redirect" , "status" => 200 , "message" => { "status" => "OK" } } , record )
433+ assert ( time . is_a? ( Fluent ::EventTime ) )
434+ end
435+ end
436+
437+ test 'interval 3 with corrent password' do
438+ d = create_driver TEST_AUTH_SUCCESS_PROXY_CONFIG
439+ assert_equal ( "test" , d . instance . tag )
440+ assert_equal ( 3 , d . instance . interval )
441+
442+ d . run ( timeout : 8 ) do
443+ sleep 7
444+ end
445+ assert_equal ( 2 , d . events . size )
446+
447+ d . events . each do |tag , time , record |
448+ assert_equal ( "test" , tag )
449+
450+ assert_equal ( { "url" => "http://127.0.0.1:3939/protected" , "status" => 200 , "message" => { "status" => "OK" } } , record )
451+ assert ( time . is_a? ( Fluent ::EventTime ) )
452+ end
453+ end
454+ end
455+
248456 private
249457
250458 def create_driver ( conf )
0 commit comments