You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-cvs@httpd.apache.org by co...@apache.org on 2001/11/03 17:07:05 UTC
cvs commit: httpd-test/perl-framework/t/apache limits.t
coar 01/11/03 08:07:05
Modified: perl-framework/t/apache limits.t
Log:
More complete tests, and adapt to incorporate Stas' suggestion.
Still not very pretty, though, and full of special cases..
Revision Changes Path
1.2 +97 -26 httpd-test/perl-framework/t/apache/limits.t
Index: limits.t
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/t/apache/limits.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -u -r1.1 -r1.2
--- limits.t 2001/11/02 21:03:12 1.1
+++ limits.t 2001/11/03 16:07:05 1.2
@@ -7,6 +7,7 @@
use Apache::Test;
use Apache::TestRequest;
+use Apache::TestUtil;
#
# These values are chosen to exceed the limits in extra.conf, namely:
@@ -17,37 +18,107 @@
# LimitRequestBody 10250000
#
-my $fail_requestline = "/" . ('a' x 256);
-my $fail_fieldsize = ('a' x 2048);
-my %fail_fieldcount;
-my $fail_bodysize = 'a' x 10260000;
+my @conditions = qw(requestline fieldsize fieldcount bodysize);
+my %fail_inputs = ('requestline' => ("/" . ('a' x 256)),
+ 'fieldsize' => ('a' x 2048),
+ 'bodysize' => ('a' x 10260000),
+ 'fieldcount' => 64
+ );
+my %succeed_inputs = ('requestline' => '/',
+ 'fieldsize' => 'short value',
+ 'bodysize' => ('a' x 1024),
+ 'fieldcount' => 1
+ );
+
my $res;
#
-# Change to '3' when we get the fieldcount test working.
+# Two tests for each of the conditions, plus two more for the
+# chunked version of the body-too-large test.
#
-plan tests => 2;
+plan tests => (@conditions * 2) + 2;
-$res = GET_RC($fail_requestline);
-print "# Testing too-long request line\n",
- "# Expecting status: 414\n",
- "# Received status: $res\n";
-ok $res == 414;
-
-$res = GET_RC('/', 'X-overflow-field' => $fail_fieldsize);
-print "# Testing too-long request header field\n",
- "# Expecting status: 400\n",
- "# Received status: $res\n";
-ok $res == 400;
-
-if (0) {
-for (my $i = 1; $i < 65; $i++) {
- $fail_fieldcount{'X-Field$i'} = 'Testing field $i';
+my $testnum = 1;
+foreach my $cond (@conditions) {
+ foreach my $goodbad qw(succeed fail) {
+ my $param;
+ $param = ($goodbad eq 'succeed')
+ ? $succeed_inputs{$cond}
+ : $fail_inputs{$cond};
+ if ($cond eq 'fieldcount') {
+ my %fields;
+ for (my $i = 1; $i <= $param; $i++) {
+ $fields{"X-Field-$i"} = "Testing field $i";
+ }
+ print "# Testing LimitRequestFields; should $goodbad\n";
+ ok t_cmp(($goodbad eq 'fail' ? 400 : 200),
+ GET_RC("/", %fields),
+ "Test #$testnum");
+ $testnum++;
+ }
+ elsif ($cond eq 'bodysize') {
+ foreach my $chunked qw(disabled enabled) {
+ print "# Testing LimitRequestBodySize; should $goodbad\n";
+ set_chunking($chunked eq 'enabled');
+ ok t_cmp(($goodbad eq 'succeed' ? 200 : 413),
+ GET_RC('/', content => $param),
+ "Test #$testnum");
+ $testnum++;
+ }
+ }
+ elsif ($cond eq 'fieldsize') {
+ print "# Testing LimitRequestFieldSize; should $goodbad\n";
+ ok t_cmp(($goodbad eq 'fail' ? 400 : 200),
+ GET_RC("/", "X-overflow-field" => $param),
+ "Test #$testnum");
+ $testnum++;
+ }
+ elsif ($cond eq 'requestline') {
+ print "# Testing LimitRequestLine; should $goodbad\n";
+ ok t_cmp(($goodbad eq 'fail' ? 414 : 200),
+ GET_RC($param),
+ "Test #$testnum");
+ $testnum++;
+ }
+ }
}
-$res = GET_RC('/', \%fail_fieldcount);
-print "# Testing too many request header fields\n",
- "# Expecting status: 414\n",
- "# Received status: $res\n";
-ok $res == 414;
+exit(0);
+#
+# $res = GET_RC($fail_requestline);
+# print "# Testing too-long request line\n",
+# "# Expecting status: 414\n",
+# "# Received status: $res\n";
+# ok $res == 414;
+#
+# $res = GET_RC('/', 'X-overflow-field' => $fail_fieldsize);
+# print "# Testing too-long request header field\n",
+# "# Expecting status: 400\n",
+# "# Received status: $res\n";
+# ok $res == 400;
+#
+# for (my $i = 1; $i < 65; $i++) {
+# $fail_fieldcount{"X-Field$i"} = "Testing field $i";
+# }
+# $res = GET_RC('/', %fail_fieldcount);
+# print "# Testing too many request header fields\n",
+# "# Expecting status: 400\n",
+# "# Received status: $res\n";
+# ok $res == 400;
+# foreach my $with_chunking (0, 1) {
+# print "# Testing too large a request body\n";
+# set_chunking($with_chunking);
+# $res = GET_RC('/', content => $fail_bodysize);
+# print "# Expecting status: 400\n",
+# "# Received status: $res\n";
+# ok $res == 413;
+# }
+#
+sub set_chunking {
+ my ($setting) = @_;
+ $setting = $setting ? 1 : 0;
+ print "# Chunked transfer-encoding ",
+ ($setting ? "enabled" : "disabled"), "\n";
+ Apache::TestRequest::user_agent(keep_alive => ($setting ? 1 : 0));
}
+
Re: cvs commit: httpd-test/perl-framework/t/apache limits.t
Posted by Stas Bekman <st...@stason.org>.
coar@apache.org wrote:
> coar 01/11/03 08:07:05
>
> Modified: perl-framework/t/apache limits.t
> Log:
> More complete tests, and adapt to incorporate Stas' suggestion.
> Still not very pretty, though, and full of special cases..
> > +my $testnum = 1;
> +foreach my $cond (@conditions) {
> + foreach my $goodbad qw(succeed fail) {
that won't work under perl < 5.6, should be written as:
foreach my $cond (qw(succeed fail)) {
If I'm not mistaken some of the tests were fixed recently to work with
perl 5.005_03. Am I wrong? The README doesn't mention the requirement.
since you want the code look simpler, I've allowed myself to suggest
more simplifications
:
> + my $param;
> + $param = ($goodbad eq 'succeed')
> + ? $succeed_inputs{$cond}
> + : $fail_inputs{$cond};
my $param = ($goodbad eq 'succeed')...
> + my %fields;
> + for (my $i = 1; $i <= $param; $i++) {
> + $fields{"X-Field-$i"} = "Testing field $i";
> + }
more idiomatically and shorter written as:
for (1..$param) {
$fields{"X-Field-$_"} = "Testing field $_";
}
> + print "# Testing LimitRequestFields; should $goodbad\n";
> + ok t_cmp(($goodbad eq 'fail' ? 400 : 200),
> + GET_RC("/", %fields),
> + "Test #$testnum");
> + $testnum++;
I don't understand why do you maintain the test number? It's already
printed for you...
I think it could be:
ok t_cmp(($goodbad eq 'fail' ? 400 : 200),
GET_RC("/", %fields),
"Testing LimitRequestFields; should $goodbad"
);
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/