diff options
author | Steve Kemp <steve@steve.org.uk> | 2017-03-28 13:14:10 +0300 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2017-03-28 13:14:10 +0300 |
commit | e4040942ab55689f88625c8a048d83d84627d6e0 (patch) | |
tree | 32d80ae1de119a951600d819a4e6946f41aef072 /lib/custodian/protocoltest/http.rb | |
parent | f868e25305c9636e8f863002a08770a3bfac6d8c (diff) |
Support HTTP BASIC-AUthentication.
Supply this like so:
http://example.com/ must run http with auth 'username:passw0rd' with status 200 otherwise 'failure'
Diffstat (limited to 'lib/custodian/protocoltest/http.rb')
-rw-r--r-- | lib/custodian/protocoltest/http.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index 89d8f18..34e4b6e 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. @@ -99,6 +104,18 @@ module Custodian # + # Look for username & password + # + if line =~ /with auth '([^']+)'/ + data = $1.dup + @username, @password = data.split( ":" ) + end + if line =~ /with auth "([^"]+)"/ + data = $1.dup + @username, @password = data.split( ":" ) + end + + # # Expected status # if line =~ /with status ([0-9]+)/ @@ -181,6 +198,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 +275,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? |