diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-12-20 19:05:18 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-12-20 19:05:18 +0000 |
commit | 21d22993c5a922d733d1a948afb8cd486f984c8a (patch) | |
tree | 0b4755bac4fa95b6544d16c13fbbdf70c7f79510 | |
parent | 6ed2740f17a11932f3328242513524bc250a4a4e (diff) |
It is a bug for a test to have a protocol not matching the
scheme of the URL.
e.g. This is wrong:
https://example.com/ must run http ..
("https" != "http").
-rw-r--r-- | lib/custodian/protocoltest/http.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index ed98029..e27b809 100644 --- a/lib/custodian/protocoltest/http.rb +++ b/lib/custodian/protocoltest/http.rb @@ -57,11 +57,42 @@ module Custodian @url = line.split( /\s+/)[0] @host = @url + + # + # Ensure we've got a HTTP/HTTPS url. + # if ( @url !~ /^https?:/ ) - raise ArgumentError, "The target wasn't an URL: #{line}" + raise ArgumentError, "The target wasn't a HTTP/HTTPS URL: #{line}" + end + + + # + # Determine that the protocol of the URL matches the + # protocol-test we're running + # + test_type = nil + + case line + when /\s+must\s(not\s+)?run\s+http(\s+|\.|$)/i + then + test_type = "http" + when /\s+must\s+(not\s+)?run\s+https(\s+|\.|$)/i + then + test_type = "https" + else + raise ArgumentError, "URL has invalid scheme: #{@line}" end # + # Get the schema of the URL + # + u = URI.parse( @url ) + if ( u.scheme != test_type ) + raise ArgumentError, "The test case has a different protocol in the URI than that which we're testing: #{@line} - \"#{test_type} != #{u.scheme}\"" + end + + + # # Is this test inverted? # if ( line =~ /must\s+not\s+run\s+/ ) |