summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 299c6ba)
raw | patch | inline | side by side (parent: 299c6ba)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Fri, 27 Oct 2006 15:37:31 +0000 (15:37 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Fri, 27 Oct 2006 15:37:31 +0000 (15:37 +0000) |
characters
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1531 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1531 f882894a-f735-0410-b71e-b25c423dba1c
plugins-scripts/t/utils.t | patch | blob | history | |
plugins-scripts/utils.pm.in | patch | blob | history |
index 469988c91aca8008bfff34786aa96b8b661d7047..4df5606b76d3497a276be8ac0f3bb0b7e82d5d14 100644 (file)
#
# $Id$
#
+# Run with perl t/utils.t
-#use strict;
+use warnings;
+use strict;
use Test::More;
use NPTest;
"host-hyphened.com" => 1,
"rubbish" => 1,
"-start.com" => 0,
- "endsindot." => 0,
+ "nonfqdn-but-endsindot." => 1,
+ "fqdn.and.endsindot." => 1,
"lots.of.dots.dot.org" => 1,
+ "endingwithdoubledots.." => 0,
+ "toomany..dots" => 0,
+ ".start.with.dot" => 0,
"10.20.30.40" => 1,
"10.20.30.40.50" => 0,
"10.20.30" => 0,
+ "10.20.30.40." => 1, # This is considered a hostname because of trailing dot. It probably won't exist though...
+ "888." => 1, # This is because it could be a domain
+ "host.888." => 1,
+ "where.did.that.!.come.from." => 0,
+ "no.underscores_.com" => 0,
};
-plan tests => scalar keys %$hostname_checks;
+plan tests => ((scalar keys %$hostname_checks) + 4);
foreach my $h (sort keys %$hostname_checks) {
is (utils::is_hostname($h), $hostname_checks->{$h}, "$h should return ".$hostname_checks->{$h});
}
+is(utils::is_hostname(), 0, "No parameter errors");
+is(utils::is_hostname(""), 0, "Empty string errors");
+is(utils::is_hostname(0), 0, "0 also errors");
+is(utils::is_hostname(1), 0, "1 also errors");
index e245835924cc32a3a8aa374bec3eaaed51d2809a..8449b544468403bc8191a85df701a5eed61a8e57 100644 (file)
sub is_hostname {
my $host1 = shift;
- if ($host1 && $host1 =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z0-9][-a-zA-Z0-9]+(\.[a-zA-Z0-9][-a-zA-Z0-9]+)*)$/) {
+ return 0 unless defined $host1;
+ if ($host1 =~ m/^[\d\.]+$/ && $host1 !~ /\.$/) {
+ if ($host1 =~ m/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
+ return 1;
+ } else {
+ return 0;
+ }
+ } elsif ($host1 =~ m/^[a-zA-Z0-9][-a-zA-Z0-9]+(\.[a-zA-Z0-9][-a-zA-Z0-9]+)*\.?$/) {
return 1;
- }else{
+ } else {
return 0;
}
}