git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about mod_header and 'echo'


Hi all,

I plan to add some tests to hearders.t in order to increase our test-coverage of this module (some header xxx directives are not tested, the regex functionalities neither).
Up to now, only 'add', 'set', 'unset' and 'append' are tested.

The attached patch.txt adds some code in order to easily add new test-cases:
   - defined the content of the .htaccess file
   - define the header that should be sent to the server
   - define some headers that are expected in the answer

With the 2 new test-cases added, I tried to test the 'echo' functionality.

However, the results are surprising to me and I wonder if it comes from my limited perl knowledge, misunderstanding of mod_header and of the 'Header echo' directive or issue in the module itself.

If s.o. could give it a look, I would appreciate.

Basically, what I try to do is:
   - write several 'Header echo' directives in an .htaccess file
   - send a request with some known header fields
   - parse the answer for some expected header fields.

I run it with:
   t/TEST t/modules/headers --verbose

As annotated in the res.txt, the behavior looks strange to me.

Any opinion?

CJ

Index: t/modules/headers.t
===================================================================
--- t/modules/headers.t	(révision 1844433)
+++ t/modules/headers.t	(copie de travail)
@@ -2,6 +2,7 @@
 use warnings FATAL => 'all';
 
 use Apache::Test;
+use Apache::TestUtil;
 use Apache::TestRequest;
 
 ## 
@@ -11,11 +12,28 @@
 my $htdocs = Apache::Test::vars('documentroot');
 my $htaccess = "$htdocs/modules/headers/htaccess/.htaccess";
 my @header_types = ('set', 'append', 'add', 'unset');
-    
+
+my @testcases = (
+    ## htaccess
+    ## Header to set in the request
+    ## Expected result
+    [
+       "Header echo Test-Header\nHeader echo a\nHeader echo aa",
+       [ 'Test-Header' => 'value', 'a' => 'b' , 'aa' => 'bb' ],
+       [ 'Test-Header' => 'value', 'a' => 'b' , 'aa' => 'bb' ],
+    ],
+    [
+       "Header echo Test-Header\nHeader echo XXX\nHeader echo aa",
+       [ 'Test-Header' => 'value', 'a' => 'b', 'aa' => 'bb' ],
+       [ 'Test-Header' => 'value', 'aa' => 'bb' ],
+    ],
+);
+   
 plan tests => 
-    @header_types**4 + @header_types**3 + @header_types**2 + @header_types**1,
+    @header_types**4 + @header_types**3 + @header_types**2 + @header_types**1 + scalar @testcases * 2,
     have_module 'headers';
 
+# Test various configurations
 foreach my $header1 (@header_types) {
 
     ok test_header($header1);
@@ -37,6 +55,14 @@
 
 }
 
+# Test some other Header directives, including regex
+my $ua = LWP::UserAgent->new();
+my $hostport = Apache::TestRequest::hostport();
+foreach my $t (@testcases) {
+    test_header2($t);
+}
+
+
 ## clean up ##
 unlink $htaccess;
 
@@ -157,3 +183,40 @@
 
     }
 }
+
+sub test_header2 {
+    my @test = @_;
+    my $h = HTTP::Headers->new;
+    
+    for (my $i = 0; $i < scalar @{$test[0][1]}; $i += 2) {
+        print "Header sent n°" . $i/2 . ":\n";
+        print "  header: " . $test[0][1][$i] . "\n";
+        print "  value:  " . $test[0][1][$i+1] . "\n";
+        $h->header($test[0][1][$i] => $test[0][1][$i+1]);
+    }
+    
+    open (HT, ">$htaccess");
+    print HT $test[0][0];
+    close(HT);
+
+    ## 
+    my $r = HTTP::Request->new('GET', "http://$hostport/modules/headers/htaccess/";, $h);
+    my $res = $ua->request($r);
+    ok t_cmp($res->code, 200, "Checking return code is '200'");
+    
+    my $isok = 1;
+    for (my $i = 0; $i < scalar @{$test[0][2]}; $i += 2) {
+        print "Header received n°" . $i/2 . ":\n";
+        print "  header:   " . $test[0][2][$i] . "\n";
+        print "  expected: " . $test[0][2][$i+1] . "\n";
+        if ($res->header($test[0][2][$i])) {
+            print "  received: " . $res->header($test[0][2][$i]) . "\n";
+        } else {
+            print "  received: <undefined>\n";
+        }
+        $isok = $isok && $res->header($test[0][2][$i]) && $test[0][2][$i+1] eq $res->header($test[0][2][$i]);
+    }
+    ok $isok;
+
+    print $res->as_string;
+}
ok 331
ok 332
ok 333
ok 334
ok 335
ok 336
ok 337
ok 338
ok 339
ok 340
Header sent n°0:
  header: Test-Header
  value:  value
Header sent n°1:
  header: a
  value:  b
Header sent n°2:
  header: aa
  value:  bb
# testing : Checking return code is '200'
# expected: 200
# received: '200'
ok 341
Header received n°0:
  header:   Test-Header
  expected: value
  received: value, value		<--- Why twice?
Header received n°1:
  header:   a
  expected: b
  received: <undefined>			<--- Why header 'a' is missing...
Header received n°2:
  header:   aa
  expected: bb
  received: bb				<--- ...and header 'aa' is correct?
not ok 342
HTTP/1.1 200 OK
Connection: close
Date: Sun, 09 Dec 2018 08:33:30 GMT
Accept-Ranges: bytes
ETag: "0-52169385a8a8a"
Server: Apache/2.4.38-dev (Unix) OpenSSL/1.1.1
Vary: In-If1
Content-Length: 0
Content-Type: text/html
Last-Modified: Tue, 06 Oct 2015 05:51:24 GMT
Aa: bb
Client-Date: Sun, 09 Dec 2018 08:33:30 GMT
Client-Peer: 127.0.0.1:8529
Client-Response-Num: 1
DMMATCH1: 1
Test-Header: value
Test-Header: value

Header sent n°0:
  header: Test-Header
  value:  value
Header sent n°1:
  header: a
  value:  b
Header sent n°2:
  header: aa
  value:  bb
# Failed test 342 in t/modules/headers.t at line 219
# testing : Checking return code is '200'
# expected: 200
# received: '200'
ok 343
Header received n°0:
  header:   Test-Header
  expected: value
  received: value			<--- Only once in this test?
Header received n°1:
  header:   aa
  expected: bb
  received: <undefined>			<--- Why header 'aa' is missing...
not ok 344
HTTP/1.1 200 OK
Connection: close
Date: Sun, 09 Dec 2018 08:33:30 GMT
Accept-Ranges: bytes
ETag: "0-52169385a8a8a"
Server: Apache/2.4.38-dev (Unix) OpenSSL/1.1.1
Vary: In-If1
Content-Length: 0
Content-Type: text/html
Last-Modified: Tue, 06 Oct 2015 05:51:24 GMT
Client-Date: Sun, 09 Dec 2018 08:33:30 GMT
Client-Peer: 127.0.0.1:8529
Client-Response-Num: 1
DMMATCH1: 1
Test-Header: value
# Failed test 344 in t/modules/headers.t at line 219 fail #2
Failed 2/344 subtests 

Test Summary Report
-------------------
t/modules/headers.t (Wstat: 0 Tests: 344 Failed: 2)
  Failed tests:  342, 344
Files=1, Tests=344,  2 wallclock secs ( 0.06 usr  0.04 sys +  0.77 cusr  0.30 csys =  1.17 CPU)
Result: FAIL
Failed 1/1 test programs. 2/344 subtests failed.
[warning] server localhost:8529 shutdown
[  error] error running tests (please examine t/logs/error_log)