summaryrefslogtreecommitdiffstats
path: root/debian/perl-framework/t/modules/negotiation.t
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 02:04:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 02:04:07 +0000
commit1221c736f9a90756d47ea6d28320b6b83602dd2a (patch)
treeb453ba7b1393205258c9b098a773b4330984672f /debian/perl-framework/t/modules/negotiation.t
parentAdding upstream version 2.4.38. (diff)
downloadapache2-1221c736f9a90756d47ea6d28320b6b83602dd2a.tar.xz
apache2-1221c736f9a90756d47ea6d28320b6b83602dd2a.zip
Adding debian version 2.4.38-3+deb10u8.debian/2.4.38-3+deb10u8debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/perl-framework/t/modules/negotiation.t')
-rw-r--r--debian/perl-framework/t/modules/negotiation.t181
1 files changed, 181 insertions, 0 deletions
diff --git a/debian/perl-framework/t/modules/negotiation.t b/debian/perl-framework/t/modules/negotiation.t
new file mode 100644
index 0000000..0081ce0
--- /dev/null
+++ b/debian/perl-framework/t/modules/negotiation.t
@@ -0,0 +1,181 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestRequest;
+use Apache::TestUtil;
+
+## 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 @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');
+
+my $actual;
+
+#XXX: this is silly; need a better way to be portable
+sub my_chomp {
+ $actual =~ s/[\r\n]+$//s;
+}
+
+foreach (@language) {
+
+ ## verify that the correct default language content is returned
+ $actual = GET_BODY "/modules/negotiation/$_/";
+ print "# GET /modules/negotiation/$_/\n";
+ my_chomp();
+ ok t_cmp($actual, "index.html.$_",
+ "Verify correct default language for index.$_.foo");
+
+ $actual = GET_BODY "/modules/negotiation/$_/compressed/";
+ print "# GET /modules/negotiation/$_/compressed/\n";
+ my_chomp();
+ ok t_cmp($actual, "index.html.$_.gz",
+ "Verify correct default language for index.$_.foo.gz");
+
+ $actual = GET_BODY "/modules/negotiation/$_/two/index";
+ print "# GET /modules/negotiation/$_/two/index\n";
+ my_chomp();
+ ok t_cmp($actual, "index.$_.html",
+ "Verify correct default language for index.$_.html");
+
+ foreach my $ext (@language) {
+
+ ## verify that you can explicitly request all language files.
+ my $resp = GET("/modules/negotiation/$_/index.html.$ext");
+ print "# GET /modules/negotiation/$_/index.html.$ext\n";
+ ok t_cmp($resp->code,
+ 200,
+ "Explicitly request $_/index.html.$ext");
+ $resp = GET("/modules/negotiation/$_/two/index.$ext.html");
+ print "# GET /modules/negotiation/$_/two/index.$ext.html\n";
+ ok t_cmp($resp->code,
+ 200,
+ "Explicitly request $_/two/index.$ext.html");
+
+ ## verify that even tho there is a default language,
+ ## the Accept-Language header is obeyed when present.
+ $actual = GET_BODY "/modules/negotiation/$_/",
+ 'Accept-Language' => $ext;
+ print "# GET /modules/negotiation/$_/\n# Accept-Language: $ext\n";
+ my_chomp();
+ ok t_cmp($actual, "index.html.$ext",
+ "Verify with a default language Accept-Language still obeyed");
+
+ $actual = GET_BODY "/modules/negotiation/$_/compressed/",
+ 'Accept-Language' => $ext;
+ print "# GET /modules/negotiation/$_/compressed/\n# Accept-Language: $ext\n";
+ my_chomp();
+ ok t_cmp($actual, "index.html.$ext.gz",
+ "Verify with a default language Accept-Language still ".
+ "obeyed (compression on)");
+
+ $actual = GET_BODY "/modules/negotiation/$_/two/index",
+ 'Accept-Language' => $ext;
+ print "# GET /modules/negotiation/$_/two/index\n# Accept-Language: $ext\n";
+ my_chomp();
+ ok t_cmp($actual, "index.$ext.html",
+ "Verify with a default language Accept-Language still obeyed");
+
+ }
+}
+
+## more complex requests ##
+
+## 'fu' has a quality rating of 0.9 which is higher than the rest
+## we expect Apache to return the 'fu' content.
+$actual = GET_BODY "/modules/negotiation/$en/",
+ 'Accept-Language' => "$en; q=0.1, $fr; q=0.4, $fu; q=0.9, $de; q=0.2";
+print "# GET /modules/negotiation/$en/\n# Accept-Language: $en; q=0.1, $fr; q=0.4, $fu; q=0.9, $de; q=0.2\n";
+my_chomp();
+ok t_cmp($actual, "index.html.$fu",
+ "fu has a higher quality rating, so we expect fu");
+
+$actual = GET_BODY "/modules/negotiation/$en/two/index",
+ 'Accept-Language' => "$en; q=0.1, $fr; q=0.4, $fu; q=0.9, $de; q=0.2";
+print "# GET /modules/negotiation/$en/two/index\n# Accept-Language: $en; q=0.1, $fr; q=0.4, $fu; q=0.9, $de; q=0.2\n";
+my_chomp();
+ok t_cmp($actual, "index.$fu.html",
+ "fu has a higher quality rating, so we expect fu");
+
+$actual = GET_BODY "/modules/negotiation/$en/compressed/",
+ 'Accept-Language' => "$en; q=0.1, $fr; q=0.4, $fu; q=0.9, $de; q=0.2";
+print "# GET /modules/negotiation/$en/compressed/\n# Accept-Language: $en; q=0.1, $fr; q=0.4, $fu; q=0.9, $de; q=0.2\n";
+my_chomp();
+ok t_cmp($actual, "index.html.$fu.gz",
+ "fu has a higher quality rating, so we expect fu");
+
+## 'bu' has the highest quality rating, but is non-existant,
+## so we expect the next highest rated 'fr' content to be returned.
+$actual = GET_BODY "/modules/negotiation/$en/",
+ 'Accept-Language' => "$en; q=0.1, $fr; q=0.4, $bu; q=1.0";
+print "# GET /modules/negotiation/$en/\n# Accept-Language: $en; q=0.1, $fr; q=0.4, $bu; q=1.0\n";
+my_chomp();
+ok t_cmp($actual, "index.html.$fr",
+ "bu has the highest quality but is non-existant, so fr is next best");
+
+$actual = GET_BODY "/modules/negotiation/$en/two/index",
+ 'Accept-Language' => "$en; q=0.1, $fr; q=0.4, $bu; q=1.0";
+print "# GET /modules/negotiation/$en/two/index\n# Accept-Language: $en; q=0.1, $fr; q=0.4, $bu; q=1.0\n";
+my_chomp();
+ok t_cmp($actual, "index.$fr.html",
+ "bu has the highest quality but is non-existant, so fr is next best");
+
+$actual = GET_BODY "/modules/negotiation/$en/compressed/",
+ 'Accept-Language' => "$en; q=0.1, $fr; q=0.4, $bu; q=1.0";
+print "# GET /modules/negotiation/$en/compressed/\n# Accept-Language: $en; q=0.1, $fr; q=0.4, $bu; q=1.0\n";
+my_chomp();
+ok t_cmp($actual, "index.html.$fr.gz",
+ "bu has the highest quality but is non-existant, so fr is next best");
+
+$actual = GET_BODY "/modules/negotiation/query/test?foo";
+print "# GET /modules/negotiation/query/test?foo\n";
+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";
+ }
+}