httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Kobes <ra...@theoryx5.uwinnipeg.ca>
Subject Re: Problem use Apache::Upload
Date Sat, 31 Jul 2004 16:32:11 GMT
On Fri, 30 Jul 2004, Markus Wichitill wrote:

> Randy Kobes wrote:
> > On Fri, 30 Jul 2004, Markus Wichitill wrote:
> >>Sorry, no test patch since my modifications to upload.t
> >>are too ugly (a copy of the second foreach loop with a
> >>hardcoded filename basically). That "getfiles-binary"
> >>stuff in there is so obscure that I can't figure out how
> >>to properly add another bigger file to @names.
> >
> > The /getfiles-binary-(perl|httpd) is defined by Apache-Test
> > just to be an alias to the (perl|httpd) binary on the system
> > (see httpd.conf). What you might try is adding a similar
> > alias in httpd.conf to another file and then adding that to
> > @names (making sure when running the tests that you don't
> > regenerate httpd.conf).
>
> I tried that, but httpd.conf is generated every time from
> apache_test_config.pm I guess, which in turn is generated
> from whoknowswhat, and that's where I stopped.

Perhaps the template below would illustrate your problem? In
here, I put in a POST_MAX of 555555, and tried uploading a
file larger than that - this was specified by the alias
/getfiles-binary-too_big in glue/perl/t/conf/extra.conf.in.
I then called $req->parse(), and returned
Apache::SERVER_ERROR unless $req->parse() was APR::SUCCESS.
Is this more or less what's happening? You should just be
able to change the /getfiles-binary-too_big alias in
glue/perl/t/conf/extra.conf.in from D:/test.xml (a 10 MB
file on my system) to whatever you want to test this; for
me, on Win32, these tests still pass, but perhaps this isn't
the same configuration as you?

===============================================================
Index: glue/perl/t/conf/extra.conf.in
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/conf/extra.conf.in,v
retrieving revision 1.2
diff -u -r1.2 extra.conf.in
--- glue/perl/t/conf/extra.conf.in	11 Jun 2004 03:13:30 -0000	1.2
+++ glue/perl/t/conf/extra.conf.in	31 Jul 2004 16:17:07 -0000
@@ -8,3 +8,4 @@
    Options None
 </Directory>

+Alias /getfiles-binary-too_big "D:/test.xml"
Index: glue/perl/t/response/TestApReq/upload.pm
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/response/TestApReq/upload.pm,v
retrieving revision 1.3
diff -u -r1.3 upload.pm
--- glue/perl/t/response/TestApReq/upload.pm	23 Jul 2004 23:52:14 -0000	1.3
+++ glue/perl/t/response/TestApReq/upload.pm	31 Jul 2004 16:17:07 -0000
@@ -9,16 +9,20 @@
 use Apache::Upload;
 use File::Spec;
 require File::Basename;
+use APR::Const -compile => qw(SUCCESS);
+use Apache::Const -compile => qw(OK SERVER_ERROR);

 sub handler {
     my $r = shift;
-    my $req = Apache::Request->new($r);
+    my $req = Apache::Request->new($r, POST_MAX => 555555);
     my $temp_dir = File::Spec->tmpdir;

     my $method  = $req->args('method');
     my $has_md5  = $req->args('has_md5');
     require Digest::MD5 if $has_md5;
     my $upload = $req->upload(($req->upload)[0]);
+    my $status = $req->parse();
+    return Apache::SERVER_ERROR unless ($status == APR::SUCCESS);
     my $type = $upload->type;
     my $basename = File::Basename::basename($upload->filename);
     my ($data, $fh);
@@ -71,7 +75,7 @@
 md5: $cs
 END
     unlink $temp_file if -f $temp_file;
-    return 0;
+    return Apache::OK;
 }

 sub cs {
Index: glue/perl/t/apreq/upload.t
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/apreq/upload.t,v
retrieving revision 1.2
diff -u -r1.2 upload.t
--- glue/perl/t/apreq/upload.t	23 Jul 2004 05:46:48 -0000	1.2
+++ glue/perl/t/apreq/upload.t	31 Jul 2004 16:17:07 -0000
@@ -3,14 +3,17 @@

 use Apache::Test;
 use Apache::TestUtil;
-use Apache::TestRequest qw(UPLOAD_BODY GET_BODY_ASSERT);
+use Apache::TestRequest qw(UPLOAD_BODY UPLOAD GET_BODY_ASSERT);
 use Cwd;
 require File::Basename;

 my $cwd = getcwd();
 my $location = "/TestApReq__upload";

+my $server = join ':', Apache::Test::vars(qw(servername port));
+
 my %types = (perl => 'application/octet-stream',
+             too_big => 'application/octet-stream',
              httpd => 'application/octet-stream',
              'perltoc.pod' => 'text/x-pod',
              'perlport.pod' => 'text/x-pod');
@@ -19,15 +22,14 @@

 plan tests => @names * @methods, have_lwp;

+use LWP::Simple qw(getstore is_success);
 foreach my $name (@names) {
     my $url = ( ($name =~ /\.pod$/) ?
         "getfiles-perl-pod/" : "/getfiles-binary-" ) . $name;
-    my $content = GET_BODY_ASSERT($url);
-    my $path = File::Spec->catfile($cwd, 't', $name);
-    open my $fh, ">", $path or die "Cannot open $path: $!";
-    binmode $fh;
-    print $fh $content;
-    close $fh;
+     my $store = File::Spec->catfile($cwd, 't', $name);
+     unless (is_success(getstore("http://$server/$url", $store)) ) {
+        die "Cannot fetch $server$url to $store";
+     }
 }

 eval {require Digest::MD5;};
@@ -39,8 +41,13 @@
     my $basename = File::Basename::basename($file);

     for my $method ( @methods) {
-        my $result = UPLOAD_BODY("$location?method=$method;has_md5=$has_md5",
+        my $result = UPLOAD("$location?method=$method;has_md5=$has_md5",
                                  filename => $file);
+        if ($file =~ /too_big/) {
+            ok t_cmp($result->code, 500, "upload max exceeded");
+            next;
+        }
+        my $content = $result->content;
         my $expected = <<END;

 type: $types{$basename}
@@ -48,7 +55,7 @@
 filename: $basename
 md5: $cs
 END
-        ok t_cmp($result, $expected, "$method test for $basename");
+        ok t_cmp($content, $expected, "$method test for $basename");
     }
     unlink $file if -f $file;
 }

=================================================================

I used getstore() here to fetch the file to be
uploaded, as it was quicker.

By the way, if you don't want to go through all the
tests via 'nmake test', and just test this one, what
you could do is install the Perl modules (so as to
not bother with adding blib/ - this assumes your
Win32 is just a test box), and then, within glue/perl,
   perl t/TEST --config
which generates the new t/conf/httpd.conf and
t/conf/extra.conf, based on extra.conf.in), and then
   perl t/TEST -v apreq/upload
to run just the upload tests.

-- 
best regards,
randy

Mime
View raw message