diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-09 14:01:20 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-09 14:01:20 +0000 |
commit | ad58f04833b6d9f6b0d01c5fc8adc61df6d088cc (patch) | |
tree | f2484838869a97b049adf8b1f487513f5554569c /test/webrick/test_httpauth.rb | |
parent | 0d07bc203c421e9ebda8ef3ae50230f6b1866a71 (diff) |
* test/open-uri: Test server log in server thread.
* test/webrick: Ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/webrick/test_httpauth.rb')
-rw-r--r-- | test/webrick/test_httpauth.rb | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/test/webrick/test_httpauth.rb b/test/webrick/test_httpauth.rb index 051e252fec..27c37f3677 100644 --- a/test/webrick/test_httpauth.rb +++ b/test/webrick/test_httpauth.rb @@ -7,7 +7,11 @@ require_relative "utils" class TestWEBrickHTTPAuth < Test::Unit::TestCase def test_basic_auth - TestWEBrick.start_httpserver{|server, addr, port, log| + log_tester = lambda {|log, access_log| + assert_equal(1, log.length) + assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, log[0]) + } + TestWEBrick.start_httpserver({}, log_tester) {|server, addr, port, log| realm = "WEBrick's realm" path = "/basic_auth" @@ -27,7 +31,19 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase end def test_basic_auth2 - log = TestWEBrick.start_httpserver{|server, addr, port, log| + log_tester = lambda {|log, access_log| + log.reject! {|line| /\A\s*\z/ =~ line } + pats = [ + /ERROR Basic WEBrick's realm: webrick: password unmatch\./, + /ERROR WEBrick::HTTPStatus::Unauthorized/ + ] + pats.each {|pat| + assert(!log.grep(pat).empty?, "webrick log doesn't have expected error: #{pat.inspect}") + log.reject! {|line| pat =~ line } + } + assert_equal([], log) + } + TestWEBrick.start_httpserver({}, log_tester) {|server, addr, port, log| realm = "WEBrick's realm" path = "/basic_auth2" @@ -61,16 +77,6 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase http.request(g){|res| assert_not_equal("hoge", res.body, log.call)} } } - log.reject! {|line| /\A\s*\z/ =~ line } - pats = [ - /ERROR Basic WEBrick's realm: webrick: password unmatch\./, - /ERROR WEBrick::HTTPStatus::Unauthorized/ - ] - pats.each {|pat| - assert(!log.grep(pat).empty?, "webrick log doesn't have expected error: #{pat.inspect}") - log.reject! {|line| pat =~ line } - } - assert_equal([], log) end def test_basic_auth3 @@ -102,7 +108,20 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase )/x def test_digest_auth - log = TestWEBrick.start_httpserver{|server, addr, port, log| + log_tester = lambda {|log, access_log| + log.reject! {|line| /\A\s*\z/ =~ line } + pats = [ + /ERROR Digest WEBrick's realm: no credentials in the request\./, + /ERROR WEBrick::HTTPStatus::Unauthorized/, + /ERROR Digest WEBrick's realm: webrick: digest unmatch\./ + ] + pats.each {|pat| + assert(!log.grep(pat).empty?, "webrick log doesn't have expected error: #{pat.inspect}") + log.reject! {|line| pat =~ line } + } + assert_equal([], log) + } + TestWEBrick.start_httpserver({}, log_tester) {|server, addr, port, log| realm = "WEBrick's realm" path = "/digest_auth" @@ -153,17 +172,6 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase end } } - log.reject! {|line| /\A\s*\z/ =~ line } - pats = [ - /ERROR Digest WEBrick's realm: no credentials in the request\./, - /ERROR WEBrick::HTTPStatus::Unauthorized/, - /ERROR Digest WEBrick's realm: webrick: digest unmatch\./ - ] - pats.each {|pat| - assert(!log.grep(pat).empty?, "webrick log doesn't have expected error: #{pat.inspect}") - log.reject! {|line| pat =~ line } - } - assert_equal([], log) end private |