You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jc...@apache.org on 2017/07/05 23:36:48 UTC

svn commit: r1800951 - in /httpd/test/framework/trunk/t: htdocs/modules/negotiation/content-type/ htdocs/modules/negotiation/content-type/test.var modules/negotiation.t

Author: jchampion
Date: Wed Jul  5 23:36:48 2017
New Revision: 1800951

URL: http://svn.apache.org/viewvc?rev=1800951&view=rev
Log:
mod_negotiation: add Accept variant tests

Also remove the duplicated config in the comments.

Added:
    httpd/test/framework/trunk/t/htdocs/modules/negotiation/content-type/
    httpd/test/framework/trunk/t/htdocs/modules/negotiation/content-type/test.var
Modified:
    httpd/test/framework/trunk/t/modules/negotiation.t

Added: httpd/test/framework/trunk/t/htdocs/modules/negotiation/content-type/test.var
URL: http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/htdocs/modules/negotiation/content-type/test.var?rev=1800951&view=auto
==============================================================================
--- httpd/test/framework/trunk/t/htdocs/modules/negotiation/content-type/test.var (added)
+++ httpd/test/framework/trunk/t/htdocs/modules/negotiation/content-type/test.var Wed Jul  5 23:36:48 2017
@@ -0,0 +1,26 @@
+URI: test
+
+# NOTE: When adding new cases, pad out bodies with spaces so that they're of
+# equal length. mod_negotiation will prefer shorter bodies if all else is equal,
+# which is confusing. We just want the first acceptable alternate to win for
+# these tests.
+
+URI: test.txt
+Content-Type: text/plain
+Body:---
+text/plain---
+
+URI: test.html
+Content-Type: text/html
+Body:---
+text/html ---
+
+URI: test.jpg
+Content-Type: image/jpeg
+Body:---
+image/jpeg---
+
+URI: test.gif
+Content-Type: image/gif
+Body:---
+image/gif ---

Modified: httpd/test/framework/trunk/t/modules/negotiation.t
URL: http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/modules/negotiation.t?rev=1800951&r1=1800950&r2=1800951&view=diff
==============================================================================
--- httpd/test/framework/trunk/t/modules/negotiation.t (original)
+++ httpd/test/framework/trunk/t/modules/negotiation.t Wed Jul  5 23:36:48 2017
@@ -5,42 +5,31 @@ use Apache::Test;
 use Apache::TestRequest;
 use Apache::TestUtil;
 
-## mod_negotiation test
-##
-## extra.conf.in:
-##
-## <IfModule mod_mime.c>
-## AddLanguage en .en
-## AddLanguage fr .fr
-## AddLanguage de .de
-## AddLanguage fu .fu
-## AddHandler type-map .var
-## 
-## <IfModule mod_negotiation.c>
-## CacheNegotiatedDocs
-## <Directory @SERVERROOT@/htdocs/modules/negotiation/en>
-## Options +MultiViews
-## LanguagePriority en fr de fu
-## </Directory>
-## <Directory @SERVERROOT@/htdocs/modules/negotiation/de>
-## Options +MultiViews
-## LanguagePriority de en fr fu
-## </Directory>
-## <Directory @SERVERROOT@/htdocs/modules/negotiation/fr>
-## Options +MultiViews
-## LanguagePriority fr en de fu
-## </Directory>
-## <Directory @SERVERROOT@/htdocs/modules/negotiation/fu>
-## Options +MultiViews
-## LanguagePriority fu fr en de
-## </Directory>
-## </IfModule>
-## </IfModule>
-
+## mod_negotiation test (see extra.conf.in)
 
 my ($en, $fr, $de, $fu, $bu) = qw(en fr de fu bu);
 my @language = ($en, $fr, $de, $fu);
-my $tests = (@language * 3) + (@language * @language * 5) + 7;
+
+my @ct_tests = (
+    # [ Accept header, Expected response ]
+    [ "*/*",       "text/plain" ],
+    [ "text/*",    "text/plain" ],
+    [ "text/html", "text/html"  ],
+    [ "image/*",   "image/jpeg" ],
+    [ "image/gif", "image/gif"  ],
+
+    [ "*",         "text/plain" ], # Dubious
+
+    # Tests which expect a 406 response
+    [ "",     undef ],
+    [ "*bad", undef ],
+    [ "/*",   undef ],
+    [ "*/",   undef ],
+    [ "te/*", undef ],
+);
+
+my $tests = (@language * 3) + (@language * @language * 5) + (scalar @ct_tests)
+            + 7;
 
 plan tests => $tests, need 
      need_module('negotiation') && need_cgi && need_module('mime');
@@ -168,3 +157,25 @@ my_chomp();
 ok t_cmp($actual, "QUERY_STRING --> foo",
          "The type map gives the script the highest quality;"
          . "\nthe request included a query string");
+
+## Content-Type tests
+
+foreach my $test (@ct_tests) {
+    my $accept   = $test->[0];
+    my $expected = $test->[1];
+
+    my $r = GET "/modules/negotiation/content-type/test.var",
+                Accept => $accept;
+
+    if ($expected) {
+        $actual = $r->content;
+
+        # Strip whitespace from the body (we pad the variant map with spaces).
+        $actual =~ s/^\s+|\s+$//g;
+
+        ok t_cmp $expected, $actual, "should send correct variant";
+    }
+    else {
+        ok t_cmp $r->code, 406, "expect Not Acceptable for Accept: $accept";
+    }
+}