aboutsummaryrefslogtreecommitdiffstats
path: root/test/webrick/test_httpauth.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/webrick/test_httpauth.rb')
-rw-r--r--test/webrick/test_httpauth.rb56
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