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 Gary Benson <gb...@redhat.com> on 2001/08/28 12:05:58 UTC

Fix for mod_access test

Hi all,

The tests for mod_access fail if 127.0.0.1 does not resolve as "localhost"
(mine resolves as "localhost.localdomain"). This patch fixes it.

I changed the regexp matches to explicit equals where possible, since
changing /^from localhost$/ to /^from $localhost_name$/ could hide all
kinds of problems when there are dots in the hostnames.

Oh, and it needs the Socket package to access the constant AF_INET...

Gary

[ Gary Benson, Red Hat Europe ][ gbenson@redhat.com ][ GnuPG 60E8793A ]

Index: t/modules/access.t
===================================================================
RCS file: /home/cvspublic/httpd-test/perl-framework/t/modules/access.t,v
retrieving revision 1.2
diff -u -r1.2 access.t
--- t/modules/access.t	2001/08/08 17:53:10	1.2
+++ t/modules/access.t	2001/08/28 09:56:40
@@ -4,14 +4,18 @@
 use Apache::Test;
 use Apache::TestRequest;
 use Apache::TestConfig;
+use Socket;

 ##
 ## mod_access test
 ##

+my $localhost_addr = pack('C4', 127, 0, 0, 1);
+my $localhost_name = gethostbyaddr($localhost_addr, AF_INET);
+
 my @localhost = (
     'from all',
-    'from localhost',
+    "from $localhost_name",
     'from 127.0.0.1',
     'from 127.0',
     'from 127.0.0.1/255.255.0.0',
@@ -47,8 +51,8 @@
             ## denying by default

             if ($allow =~ /^from 127/
-                || $allow =~ /^from localhost$/
-                || $allow =~ /^from all$/) {
+                || $allow eq "from $localhost_name"
+                || $allow eq 'from all') {

                 ## if we are explicitly allowed, its ok
                 ok GET_OK "/modules/access/htaccess/index.html";
@@ -71,8 +75,8 @@
                 ## allowing by default

                 if ($deny =~ /^from 127/
-                    || $deny =~ /^from localhost$/
-                    || $deny =~ /^from all$/) {
+                    || $deny eq "from $localhost_name"
+                    || $deny eq 'from all') {

                     ## if we are denied explicitly
                     ## its not ok
@@ -102,16 +106,16 @@
                 ## allowing by default

                 if ($allow =~ /^from 127/
-                    || $allow =~ /^from localhost$/
-                    || $allow =~ /^from all$/) {
+                    || $allow eq "from $localhost_name"
+                    || $allow eq 'from all') {

                     ## we are explicitly allowed
                     ## so it is ok.
                     ok GET_OK "/modules/access/htaccess/index.html";

                 } elsif ($deny =~ /^from 127/
-                    || $deny =~ /^from localhost$/
-                    || $deny =~ /^from all$/) {
+                    || $deny eq "from $localhost_name"
+                    || $deny eq 'from all') {

                     ## if we are not explicitly allowed
                     ## and are explicitly denied,
@@ -131,16 +135,16 @@
                 ## denying by default

                 if ($deny =~ /^from 127/
-                    || $deny =~ /^from localhost$/
-                    || $deny =~ /^from all$/) {
+                    || $deny eq "from $localhost_name"
+                    || $deny eq 'from all') {

                     ## if we are explicitly denied,
                     ## we get no access.
                     ok !GET_OK "/modules/access/htaccess/index.html";

                 } elsif ($allow =~ /^from 127/
-                    || $allow =~ /^from localhost$/
-                    || $allow =~ /^from all$/) {
+                    || $allow eq "from $localhost_name"
+                    || $allow eq 'from all') {

                     ## if we are not explicitly denied
                     ## and are explicitly allowed,



Re: Fix for mod_access test

Posted by Gary Benson <gb...@redhat.com>.
On Tue, 28 Aug 2001, Doug MacEachern wrote:

> On Tue, 28 Aug 2001, Gary Benson wrote:
>
> > Is "my $localhost_name = Apache::TestConfig->default_localhost;" valid?
> > Should you not do this:
> >
> >     my $env = Apache::TestConfig->thaw;
> >     my $localhost_name = $env->{vars}->{servername};
>
> yeah, just trying to avoid thaw() multiple times.
> my $localhost_name = Apache::TestRequest::vars()->{servername};
>
> would be fine.
>
> Apache::TestRequest caches the thaw so it only happens once per-process.

Okay then, here's the new patch.
G

[ Gary Benson, Red Hat Europe ][ gbenson@redhat.com ][ GnuPG 60E8793A ]

Index: t/modules/access.t
===================================================================
RCS file: /home/cvspublic/httpd-test/perl-framework/t/modules/access.t,v
retrieving revision 1.3
diff -u -r1.3 access.t
--- t/modules/access.t	2001/08/24 18:19:30	1.3
+++ t/modules/access.t	2001/08/28 16:51:55
@@ -9,9 +9,10 @@
 ## mod_access test
 ##

+my $localhost_name = Apache::TestRequest::vars()->{servername};
 my @localhost = (
     'from all',
-    'from localhost',
+    "from $localhost_name",
     'from 127.0.0.1',
     'from 127.0',
     'from 127.0.0.1/255.255.0.0',
@@ -26,8 +27,8 @@
 plan tests => (@order * @allow * @deny * 2) + (@order * @allow),
     test_module 'access';

-my $env = Apache::TestConfig->thaw;
-my $dir = "$env->{vars}->{t_dir}/htdocs/modules/access/htaccess";
+my $dir = Apache::TestRequest::vars()->{t_dir};
+$dir .=  "/htdocs/modules/access/htaccess";

 sub write_htaccess {
     my $conf_str = shift;
@@ -58,8 +59,8 @@
             ## denying by default

             if ($allow =~ /^from 127/
-                || $allow =~ /^from localhost$/
-                || $allow =~ /^from all$/) {
+                || $allow eq "from $localhost_name"
+                || $allow eq 'from all') {

                 ## if we are explicitly allowed, its ok
                 print "expecting access.\n";
@@ -85,8 +86,8 @@
                 ## allowing by default

                 if ($deny =~ /^from 127/
-                    || $deny =~ /^from localhost$/
-                    || $deny =~ /^from all$/) {
+                    || $deny eq "from $localhost_name"
+                    || $deny eq 'from all') {

                     ## if we are denied explicitly
                     ## its not ok
@@ -120,8 +121,8 @@
                 ## allowing by default

                 if ($allow =~ /^from 127/
-                    || $allow =~ /^from localhost$/
-                    || $allow =~ /^from all$/) {
+                    || $allow eq "from $localhost_name"
+                    || $allow eq 'from all') {

                     ## we are explicitly allowed
                     ## so it is ok.
@@ -129,8 +130,8 @@
                     ok GET_OK "/modules/access/htaccess/index.html";

                 } elsif ($deny =~ /^from 127/
-                    || $deny =~ /^from localhost$/
-                    || $deny =~ /^from all$/) {
+                    || $deny eq "from $localhost_name"
+                    || $deny eq 'from all') {

                     ## if we are not explicitly allowed
                     ## and are explicitly denied,
@@ -152,8 +153,8 @@
                 ## denying by default

                 if ($deny =~ /^from 127/
-                    || $deny =~ /^from localhost$/
-                    || $deny =~ /^from all$/) {
+                    || $deny eq "from $localhost_name"
+                    || $deny eq 'from all') {

                     ## if we are explicitly denied,
                     ## we get no access.
@@ -161,8 +162,8 @@
                     ok !GET_OK "/modules/access/htaccess/index.html";

                 } elsif ($allow =~ /^from 127/
-                    || $allow =~ /^from localhost$/
-                    || $allow =~ /^from all$/) {
+                    || $allow eq "from $localhost_name"
+                    || $allow eq 'from all') {

                     ## if we are not explicitly denied
                     ## and are explicitly allowed,


Re: Fix for mod_access test

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 28 Aug 2001, Gary Benson wrote:
 
> Is "my $localhost_name = Apache::TestConfig->default_localhost;" valid?
> Should you not do this:
> 
>     my $env = Apache::TestConfig->thaw;
>     my $localhost_name = $env->{vars}->{servername};

yeah, just trying to avoid thaw() multiple times.
my $localhost_name = Apache::TestRequest::vars()->{servername};

would be fine.

Apache::TestRequest caches the thaw so it only happens once per-process.



Re: Fix for mod_access test

Posted by Gary Benson <gb...@redhat.com>.
On Tue, 28 Aug 2001, Doug MacEachern wrote:

> On Tue, 28 Aug 2001, Gary Benson wrote:
>
> > The tests for mod_access fail if 127.0.0.1 does not resolve as "localhost"
> > (mine resolves as "localhost.localdomain"). This patch fixes it.
>
> excellent!  however, your patch did not apply for me, maybe you needed to
> cvs up first?  the first two hunks applied with offset, so that would seem
> to be the case.
> i added your code to determine localhost to Apache::TestConfig, so you can
> say:
>
> my $localhost_name = Apache::TestConfig->default_localhost;
>
> if you could resubmit against the current version using that method, that
> would be great.  thanks.

Is "my $localhost_name = Apache::TestConfig->default_localhost;" valid?
Should you not do this:

    my $env = Apache::TestConfig->thaw;
    my $localhost_name = $env->{vars}->{servername};

instead?

Gary

[ Gary Benson, Red Hat Europe ][ gbenson@redhat.com ][ GnuPG 60E8793A ]


Re: Fix for mod_access test

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 28 Aug 2001, Gary Benson wrote:

> 
> Hi all,
> 
> The tests for mod_access fail if 127.0.0.1 does not resolve as "localhost"
> (mine resolves as "localhost.localdomain"). This patch fixes it.

excellent!  however, your patch did not apply for me, maybe you needed to
cvs up first?  the first two hunks applied with offset, so that would seem
to be the case.
i added your code to determine localhost to Apache::TestConfig, so you can
say:

my $localhost_name = Apache::TestConfig->default_localhost;

if you could resubmit against the current version using that method, that
would be great.  thanks.