diff options
| -rw-r--r-- | lib/custodian/protocoltest/http.rb | 35 | ||||
| -rwxr-xr-x | t/test-custodian-parser.rb | 37 | 
2 files changed, 68 insertions, 4 deletions
| diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index 11a16d5..0450753 100644 --- a/lib/custodian/protocoltest/http.rb +++ b/lib/custodian/protocoltest/http.rb @@ -59,6 +59,12 @@ module Custodian          # +        # Will we follow redirects? +        # +        @redirect = true + + +        #          #  Ensure we've got a HTTP/HTTPS url.          #          if ( @url !~ /^https?:/ ) @@ -119,12 +125,17 @@ module Custodian            @expected_content = nil          end +        # +        # Do we follow redirects? +        # +        if ( line =~ /not following redirects?/i ) +          @redirect = false +        end        end        # -      #  Get the right type of this object, based on the -      # URL +      #  Get the right type of this object, based on the URL        #        def get_type          if ( @url =~ /^https:/ ) @@ -136,6 +147,15 @@ module Custodian          end        end + +      # +      #  Do we follow redirects? +      # +      def follow_redirects? +        @redirect +      end + +        #        # Allow this test to be serialized.        # @@ -167,8 +187,15 @@ module Custodian            timeout( 20 ) do              begin                c = Curl::Easy.new(@url) -              c.follow_location = true -              c.max_redirects   = 10 + +              # +              # Should we follow redirections? +              # +              if ( follow_redirects? ) +                c.follow_location = true +                c.max_redirects   = 10 +              end +                c.ssl_verify_host = false                c.ssl_verify_peer = false                c.timeout         = 20 diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb index 811cbb5..f982b10 100755 --- a/t/test-custodian-parser.rb +++ b/t/test-custodian-parser.rb @@ -275,6 +275,43 @@ EOF    end +  # +  # Test that the parser works for HTTP-redirection +  # +  def test_http_redirection + +    # +    # test data +    # +    data = { +      "http://example must run http."                         => true, +      "http://example must run http with status 200."         => true, +      "http://example must run http with content 'bar'."      => true, +      "http://example must run http following redirects."     => true, +      "http://example must run http not following redirects." => false, +      "http://example must run http not following redirect."  => false, +    } + +    data.each do |str,follow| +      assert_nothing_raised do + +        # +        # Create the new parser +        # +        obj = Custodian::TestFactory.create( str ) + +        assert(obj) + +        if ( follow ) +          assert( obj.follow_redirects? ) +        else +          assert( ! obj.follow_redirects? ) +        end +      end +    end +  end + +    #    # Test that the text we're going to use in alerters is present. | 
