From 6c6762cc4e99184f8b0903c8db88f81a021479c5 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 20 Dec 2012 19:05:18 +0000 Subject: 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"). --- lib/custodian/protocoltest/http.rb | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'lib/custodian') 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,10 +57,41 @@ 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? # -- cgit v1.2.1