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 | 6c6762cc4e99184f8b0903c8db88f81a021479c5 (patch) | |
tree | 8cfd9c0c32fd7a0ad425e4aeeccd653f591b485a /lib/custodian/protocoltest/http.rb | |
parent | 1fb377006f060e896acee531be927d52151ce0fd (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").
Diffstat (limited to 'lib/custodian/protocoltest/http.rb')
-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+/ ) |