summaryrefslogtreecommitdiff
path: root/t/test-http-vs-https.rb
blob: b320777c4fe1da69149cecac524d8ca567b539cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/ruby -Ilib/ -I../lib/


require 'test/unit'

require 'custodian/protocoltests'



#
# Each of our test-objects implements a single test-type, except for http which implements two.
#
# It can be confusing if a test reports the wrong type though:
#
#    http://example.com/ the https test failed against ..
#
# Or in reverse:
#
#    https://example.com/ the http test failed ...
#
# Test we can get the sanest result here.
#
class TestTestName < Test::Unit::TestCase

  #
  # Create the test suite environment: NOP.
  #
  def setup
  end

  #
  # Destroy the test suite environment: NOP.
  #
  def teardown
  end


  #
  # Get the type of a test, and ensure it is http.
  #
  def test_http_type
    test = nil

    assert_nothing_raised do
     test = Custodian::TestFactory.create( "http://example.com/ must run http." )
    end

    assert( test )
    assert( test.kind_of? Array )
    assert( ! test.empty? )
    assert_equal( test[0].get_type, "http" )
  end


  #
  # Get the type of a test, and ensure it is https.
  #
  def test_https_type
    test = nil

    assert_nothing_raised do
     test = Custodian::TestFactory.create( "https://example.com/ must run https." )
    end

    assert( test )
    assert( test.kind_of? Array )
    assert( ! test.empty? )
    assert_equal( test[0].get_type, "https" )
  end


  #
  # It is a bug to have the protocol-test differ from the URI's protocol.
  #
  def test_protocol_mismatch


    assert_raise ArgumentError do
      Custodian::TestFactory.create( "https://example.com/ must run http." )
    end

    assert_raise ArgumentError do
      Custodian::TestFactory.create( "http://example.com/ must run https." )
    end


    assert_nothing_raised do
      Custodian::TestFactory.create( "http://example.com/ must run http." )
    end
    assert_nothing_raised do
      Custodian::TestFactory.create( "https://example.com/ must run https." )
    end

  end

end