[vhffs-dev] [443] Added a function for domain name test, this will be the only one used for all domain names tests. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [443] Added a function for domain name test, this will be the only one used for all domain names tests.
- From: subversion@xxxxxxxxx
- Date: Thu, 08 Feb 2007 17:21:23 +0100
Revision: 443
Author: beuss
Date: 2007-02-08 16:21:21 +0000 (Thu, 08 Feb 2007)
Log Message:
-----------
Added a function for domain name test, this will be the only one used for all domain names tests.
Modified Paths:
--------------
branches/vhffs_4.1/Makefile
branches/vhffs_4.1/vhffs-api/src/Vhffs/Functions.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Httpd.pm
Added Paths:
-----------
branches/vhffs_4.1/vhffs-tests/src/Functions.pl
Modified: branches/vhffs_4.1/Makefile
===================================================================
--- branches/vhffs_4.1/Makefile 2007-02-04 14:08:07 UTC (rev 442)
+++ branches/vhffs_4.1/Makefile 2007-02-08 16:21:21 UTC (rev 443)
@@ -303,4 +303,6 @@
@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Cvs.pl");'
test-web:
@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Httpd.pl");'
+test-functions:
+ @perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Functions.pl");'
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Functions.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Functions.pm 2007-02-04 14:08:07 UTC (rev 442)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Functions.pm 2007-02-08 16:21:21 UTC (rev 443)
@@ -452,6 +452,10 @@
return( 1 );
}
+sub check_domain_name($) {
+ my $domain_name = shift;
+ return (defined $domain_name && $domain_name =~ /^(?:[A-Za-z0-9\-]{1,63}[.])+([A-Za-z0-9]{2,10})$/);
+}
sub rotate_log
{
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Httpd.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Httpd.pm 2007-02-04 14:08:07 UTC (rev 442)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Httpd.pm 2007-02-08 16:21:21 UTC (rev 443)
@@ -39,6 +39,7 @@
package Vhffs::Services::Httpd;
+use Vhffs::Functions;
use base qw(Vhffs::Object);
use strict;
use DBI;
@@ -57,7 +58,7 @@
( $class , $main , $servername , $user , $group ) = @_;
- return undef unless(check_servername($servername));
+ return undef unless(Vhffs::Functions::check_domain_name($servername));
$this = {};
@@ -75,11 +76,6 @@
return $this;
}
-sub check_servername($) {
- my $servername = shift;
- return ( (defined($servername)) && ($servername =~ /^[a-z0-9](([a-z0-9]\-{0,1})+\.)+[a-z]{2,4}$/ ) && ($servername !~ /\.\./) );
-}
-
sub delete
{
my $self = shift;
Added: branches/vhffs_4.1/vhffs-tests/src/Functions.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Functions.pl 2007-02-04 14:08:07 UTC (rev 442)
+++ branches/vhffs_4.1/vhffs-tests/src/Functions.pl 2007-02-08 16:21:21 UTC (rev 443)
@@ -0,0 +1,22 @@
+use Vhffs::Tests::Main;
+use Vhffs::Tests::Utils;
+use Vhffs::Functions;
+use Test::More 'no_plan';
+use strict;
+
+
+my $main = init Vhffs::Tests::Main;
+Vhffs::Tests::Utils::init_db($main->get_db_object);
+
+# domain name check
+my @gooddn = qw(tuxfamily.org www.tuxfamily.org www1.malibu.tf-data.net atm.eagle-usb.org 2145.com www.643.com j-aime.la-tux-family.org -tuxfamily.org tuxfamily-.org tux--family.org);
+
+foreach(@gooddn) {
+ ok(Vhffs::Functions::check_domain_name($_), "$_ is a valid domain name");
+}
+
+my @baddn = qw(www.tuxfamily.or.g toto..duschmol.org *.ziva.com toto-org autre_essai.tuxfamily.org);
+
+foreach(@baddn) {
+ ok(! Vhffs::Functions::check_domain_name($_), "$_ isn't a valid domain name from vhffs POV");
+}