You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Stas Bekman <st...@stason.org> on 2003/01/31 01:55:35 UTC

Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestRun.pm

stas@apache.org wrote:
> stas        2003/01/30 16:53:45
> 
>   Modified:    perl-framework/Apache-Test/lib/Apache TestRun.pm
>   Log:
>   # handle the cases when the test suite is run under 'root':
>   #
>   # 1. When user 'bar' is chosen to run Apache with, files and dirs
>   #    created by 'root' might be not writable/readable by 'bar'
>   #
>   # 2. when the source is extracted as user 'foo', and the chosen user
>   #    to run Apache under is 'bar', in which case normally 'bar' won't
>   #    have the right permissions to write into the fs created by 'foo'.
>   #
>   # We solve that by 'chown -R bar.bar t/' in a portable way.
>   #
>   # at the end of the run we restore the perms to the original ones

Randy, can you please check that this handles the win32 case as well? I've no 
clue whether the concept of 'root' applies there.

>   Revision  Changes    Path
>   1.100     +46 -0     httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm
>   
>   Index: TestRun.pm
>   ===================================================================
>   RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
>   retrieving revision 1.99
>   retrieving revision 1.100
>   diff -u -r1.99 -r1.100
>   --- TestRun.pm	30 Jan 2003 23:59:40 -0000	1.99
>   +++ TestRun.pm	31 Jan 2003 00:53:45 -0000	1.100
>   @@ -20,6 +20,7 @@
>    use subs qw(exit_shell exit_perl);
>    
>    my %core_files  = ();
>   +my %original_t_perms = ();
>    
>    my @std_run      = qw(start-httpd run-tests stop-httpd);
>    my @others       = qw(verbose configure clean help ssl http11);
>   @@ -451,6 +452,8 @@
>            }
>        }
>    
>   +    $self->adjust_t_perms();
>   +
>        if ($opts->{'start-httpd'}) {
>            exit_perl 0 unless $server->start;
>        }
>   @@ -489,6 +492,8 @@
>    sub stop {
>        my $self = shift;
>    
>   +    $self->restore_t_perms;
>   +
>        return $self->{server}->stop if $self->{opts}->{'stop-httpd'};
>    }
>    
>   @@ -645,6 +650,47 @@
>            # old core file at the end of the run and not complain then
>            $core_files{$core} = -M $core;
>        }, $vars->{top_dir});
>   +}
>   +
>   +# this function handles the cases when the test suite is run under
>   +# 'root':
>   +#
>   +# 1. When user 'bar' is chosen to run Apache with, files and dirs
>   +#    created by 'root' might be not writable/readable by 'bar'
>   +#
>   +# 2. when the source is extracted as user 'foo', and the chosen user
>   +#    to run Apache under is 'bar', in which case normally 'bar' won't
>   +#    have the right permissions to write into the fs created by 'foo'.
>   +#
>   +# We solve that by 'chown -R bar.bar t/' in a portable way.
>   +sub adjust_t_perms {
>   +    my $self = shift;
>   +    %original_t_perms = (); # reset global
>   +
>   +    my $user = getpwuid($>) || '';
>   +    if ($user eq 'root') {
>   +        my $vars = $self->{test_config}->{vars};
>   +        my $user = $vars->{user};
>   +        my($uid, $gid) = (getpwnam($user))[2..3]
>   +            or die "Can't find out uid/gid of '$user'";
>   +        warning "root mode: changing the fs ownership to '$user' ($uid:$gid)";
>   +        finddepth(sub {
>   +            $original_t_perms{$File::Find::name} = [(stat $_)[4..5]];
>   +            chown $uid, $gid, $_;
>   +        }, $vars->{t_dir});
>   +    }
>   +}
>   +
>   +sub restore_t_perms {
>   +    my $self = shift;
>   +
>   +    if (%original_t_perms) {
>   +        my $vars = $self->{test_config}->{vars};
>   +        while (my($file, $ids) = each %original_t_perms) {
>   +            next unless -e $file; # files could be deleted
>   +            chown @$ids, $file;
>   +        }
>   +    }
>    }
>    
>    sub run_request {
>   
>   
>   


-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestRun.pm

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Fri, 31 Jan 2003, Stas Bekman wrote:
> 
> 
>>Is the whole test-under-'root' issue moot under win32, and can
>>be safely skipped without messing the code?
> 
> 
> Hi Stas,
>   There is a concept of permissions under Win32 (some flavours)
> which in principle can enter this (for example, an Administrator
> can block users from modifying certain system settings). However,
> I've not had, or heard of, such problems in this context of
> testing Apache. Probably if they did arise a much different
> logic would have to be used.

Thanks Randy, so I'll just change the code to skip the function for win32.



__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestRun.pm

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Fri, 31 Jan 2003, Stas Bekman wrote:

> Is the whole test-under-'root' issue moot under win32, and can
> be safely skipped without messing the code?

Hi Stas,
  There is a concept of permissions under Win32 (some flavours)
which in principle can enter this (for example, an Administrator
can block users from modifying certain system settings). However,
I've not had, or heard of, such problems in this context of
testing Apache. Probably if they did arise a much different
logic would have to be used.
  
-- 
best regards,
randy


Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestRun.pm

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Fri, 31 Jan 2003, Stas Bekman wrote:
> 
> 
>>stas@apache.org wrote:
>>
>>>stas        2003/01/30 16:53:45
>>>
>>>  Modified:    perl-framework/Apache-Test/lib/Apache TestRun.pm
>>>  Log:
>>>  # handle the cases when the test suite is run under 'root':
>>>  #
>>>  # 1. When user 'bar' is chosen to run Apache with, files and dirs
>>>  #    created by 'root' might be not writable/readable by 'bar'
>>>  #
>>>  # 2. when the source is extracted as user 'foo', and the chosen user
>>>  #    to run Apache under is 'bar', in which case normally 'bar' won't
>>>  #    have the right permissions to write into the fs created by 'foo'.
>>>  #
>>>  # We solve that by 'chown -R bar.bar t/' in a portable way.
>>>  #
>>>  # at the end of the run we restore the perms to the original ones
>>
>>Randy, can you please check that this handles the win32 case as well? I've no 
>>clue whether the concept of 'root' applies there.
> 
> 
> Hi Stas,
>    On Win32, I get an error about getpwuid($>) being 
> unimplemented. This diff

Thanks Randy!

Is the whole test-under-'root' issue moot under win32, and can be safely 
skipped without messing the code?

> ==============================================================
> Index: Apache-Test/lib/Apache/TestRun.pm
> ===================================================================
> RCS file: /home/cvspublic/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
> retrieving revision 1.100
> diff -u -r1.100 TestRun.pm
> --- Apache-Test/lib/Apache/TestRun.pm	31 Jan 2003 00:53:45 -0000	1.100
> +++ Apache-Test/lib/Apache/TestRun.pm	31 Jan 2003 04:38:35 -0000
> @@ -667,7 +667,7 @@
>      my $self = shift;
>      %original_t_perms = (); # reset global
>  
> -    my $user = getpwuid($>) || '';
> +    my $user = Apache::TestConfig::WIN32 ? '' : (getpwuid($>) || '');
>      if ($user eq 'root') {
>          my $vars = $self->{test_config}->{vars};
>          my $user = $vars->{user};
> =======================================================================
> 
> allows things to run.
> 


-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestRun.pm

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Fri, 31 Jan 2003, Stas Bekman wrote:

> stas@apache.org wrote:
> > stas        2003/01/30 16:53:45
> > 
> >   Modified:    perl-framework/Apache-Test/lib/Apache TestRun.pm
> >   Log:
> >   # handle the cases when the test suite is run under 'root':
> >   #
> >   # 1. When user 'bar' is chosen to run Apache with, files and dirs
> >   #    created by 'root' might be not writable/readable by 'bar'
> >   #
> >   # 2. when the source is extracted as user 'foo', and the chosen user
> >   #    to run Apache under is 'bar', in which case normally 'bar' won't
> >   #    have the right permissions to write into the fs created by 'foo'.
> >   #
> >   # We solve that by 'chown -R bar.bar t/' in a portable way.
> >   #
> >   # at the end of the run we restore the perms to the original ones
> 
> Randy, can you please check that this handles the win32 case as well? I've no 
> clue whether the concept of 'root' applies there.

Hi Stas,
   On Win32, I get an error about getpwuid($>) being 
unimplemented. This diff

==============================================================
Index: Apache-Test/lib/Apache/TestRun.pm
===================================================================
RCS file: /home/cvspublic/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
retrieving revision 1.100
diff -u -r1.100 TestRun.pm
--- Apache-Test/lib/Apache/TestRun.pm	31 Jan 2003 00:53:45 -0000	1.100
+++ Apache-Test/lib/Apache/TestRun.pm	31 Jan 2003 04:38:35 -0000
@@ -667,7 +667,7 @@
     my $self = shift;
     %original_t_perms = (); # reset global
 
-    my $user = getpwuid($>) || '';
+    my $user = Apache::TestConfig::WIN32 ? '' : (getpwuid($>) || '');
     if ($user eq 'root') {
         my $vars = $self->{test_config}->{vars};
         my $user = $vars->{user};
=======================================================================

allows things to run.

-- 
best regards,
randy