~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/cgi/test_cgi_header.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'test/unit'
2
2
require 'cgi'
 
3
require 'time'
3
4
 
4
5
 
5
6
class CGIHeaderTest < Test::Unit::TestCase
130
131
 
131
132
 
132
133
  def test_cgi_header_nph
 
134
    time_start = Time.now.to_i
133
135
    cgi = CGI.new
134
136
    ## 'nph' is true
135
137
    ENV['SERVER_SOFTWARE'] = 'Apache 2.2.0'
136
138
    actual1 = cgi.header('nph'=>true)
137
 
    now = Time.now
138
139
    ## when old IIS, NPH-mode is forced
139
140
    ENV['SERVER_SOFTWARE'] = 'IIS/4.0'
140
141
    actual2 = cgi.header
143
144
    ENV['SERVER_SOFTWARE'] = 'IIS/5.0'
144
145
    actual4 = cgi.header
145
146
    actual5 = cgi.header('status'=>'REDIRECT', 'location'=>'http://www.example.com/')
 
147
    time_end = Time.now.to_i
 
148
    date = /^Date: ([A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d GMT)\r\n/
 
149
    [actual1, actual2, actual3].each do |actual|
 
150
      assert_match(date, actual)
 
151
      assert_includes(time_start..time_end, date =~ actual && Time.parse($1).to_i)
 
152
      actual.sub!(date, "Date: DATE_IS_REMOVED\r\n")
 
153
    end
146
154
    ## assertion
147
155
    expected =  "HTTP/1.1 200 OK\r\n"
148
 
    expected << "Date: #{CGI.rfc1123_date(now)}\r\n"
 
156
    expected << "Date: DATE_IS_REMOVED\r\n"
149
157
    expected << "Server: Apache 2.2.0\r\n"
150
158
    expected << "Connection: close\r\n"
151
159
    expected << "Content-Type: text/html\r\n"