summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Hannah <jhannah@bytemark.co.uk>2017-04-10 09:00:57 +0100
committerJames Hannah <jhannah@bytemark.co.uk>2017-04-10 09:00:57 +0100
commit5703a7727fe69c492296f126ce28b06b7a6a11a0 (patch)
tree0eac0050f119673f421143be449f49f9cdf3c2b8
parentf868e25305c9636e8f863002a08770a3bfac6d8c (diff)
parent69ac6cfbdaf9cbb25a0f73561d92a3d69accb434 (diff)
Merge branch '10-support-http-basic-auth' into 'master'
Resolve "We should support HTTP-basic auth for HTTP-based status-checks." Closes #10 See merge request !7
-rw-r--r--lib/custodian/protocoltest/http.rb38
-rwxr-xr-xt/test-custodian-parser.rb40
2 files changed, 78 insertions, 0 deletions
diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb
index 89d8f18..a4c4adb 100644
--- a/lib/custodian/protocoltest/http.rb
+++ b/lib/custodian/protocoltest/http.rb
@@ -63,6 +63,11 @@ module Custodian
#
@redirect = true
+ #
+ # No basic-authentication by default
+ #
+ @username = nil
+ @password = nil
#
# Ensure we've got a HTTP/HTTPS url.
@@ -97,6 +102,12 @@ module Custodian
raise ArgumentError, "The test case has a different protocol in the URI than that which we're testing: #{@line} - \"#{test_type} != #{u.scheme}\""
end
+ #
+ # Save username/password if they were specified
+ #
+ @username = u.user if ( u.user )
+ @password = u.password if ( u.password )
+
#
# Expected status
@@ -181,6 +192,24 @@ module Custodian
end
#
+ # Do we have basic auth?
+ #
+ def basic_auth?
+ ( @username.nil? == false ) && ( @password.nil? == false )
+ end
+
+ #
+ # Get the username/password for basic-auth
+ #
+ def basic_auth_username
+ @username
+ end
+
+ def basic_auth_password
+ @password
+ end
+
+ #
# Allow this test to be serialized.
#
def to_s
@@ -240,6 +269,15 @@ module Custodian
c.resolve_mode = resolve_mode
#
+ # Should we use HTTP basic-auth?
+ #
+ if basic_auth?
+ c.http_auth_types = :basic
+ c.username = basic_auth_username
+ c.password = basic_auth_password
+ end
+
+ #
# Should we follow redirections?
#
if follow_redirects?
diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb
index 1bcf5bc..2239503 100755
--- a/t/test-custodian-parser.rb
+++ b/t/test-custodian-parser.rb
@@ -430,6 +430,46 @@ EOF
end
#
+ # Test that the parser works for basic-auth.
+ #
+ def test_http_user_password
+
+ #
+ # test data
+ #
+ data = {
+ 'http://bob:steve@example must run http.' =>
+ { username: 'bob', password: 'steve'},
+ 'http://stee\':steve@example must run http.' =>
+ { username: 'stee\'', password: 'steve'},
+ 'http://e\'e:pa$$w0rd@example must run http.' =>
+ { username: 'e\'e', password: 'pa$$w0rd'},
+ }
+
+ data.each do |str, hash |
+ assert_nothing_raised do
+
+ #
+ # Create the new parser
+ #
+ obj = Custodian::TestFactory.create(str)
+
+ assert(!obj.nil?)
+ assert(obj.kind_of?(Array))
+ assert(obj.size == 1)
+ assert_equal(obj[0].to_s, str)
+
+ # There should be auth-enabled
+ assert(obj[0].basic_auth?)
+ assert(obj[0].basic_auth_username == hash[:username] )
+ assert(obj[0].basic_auth_password == hash[:password] )
+
+ end
+ end
+ end
+
+
+ #
# HTTP/HTTPS tests might specify custom expiry
#
def test_https_custom_expiry