Commit d725c675 authored by Xavier Guimard's avatar Xavier Guimard

More tests

parent b974e95f
......@@ -21,12 +21,11 @@ __END__
=pod
=cut
sub reDomainsToHost {
my $list = shift;
return qr/^$/ unless($list);
$list =~ s/^\./\\\./;
$list = join('|',split (/\s+/,$list);
return qr/^$/ unless ($list);
$list =~ s/^\./\\\./g;
$list = join( '|', split( /\s+/, $list ) );
return qr/^(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:$list)$/;
}
......@@ -5,11 +5,29 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Common::Crypto') }
use Test::More tests => 19;
use strict;
BEGIN {
use_ok('Lemonldap::NG::Common::Crypto');
}
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
my $c;
ok(
$c = Lemonldap::NG::Common::Crypto->new(
'lemonldap-ng-key', Crypt::Rijndael::MODE_CBC()
),
'New object'
);
foreach my $i ( 1 .. 17 ) {
my $s = '';
$s = join( '', map { chr( int( rand(94) ) + 33 ) } ( 1 .. $i ) );
ok( $c->decrypt( $c->encrypt($s) ) eq $s, "Test with $i characters string" );
}
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Common.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 20;
use strict;
BEGIN {
use_ok('Lemonldap::NG::Common::Regexp');
}
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
*HOST = *Lemonldap::NG::Common::Regexp::HOST;
*HOSTNAME = *Lemonldap::NG::Common::Regexp::HOSTNAME;
*HTTP_URI = *Lemonldap::NG::Common::Regexp::HTTP_URI;
*reDomainsToHost = *Lemonldap::NG::Common::Regexp::reDomainsToHost;
ok( 'test.ex.com' =~ HOST() );
ok( 'test.ex.com' =~ HOSTNAME() );
ok( 'test..ex.com' !~ HOST() );
ok( 'test..ex.com' !~ HOSTNAME() );
ok( '10.1.1.1' =~ HOST() );
ok( '10.1.1.1' !~ HOSTNAME() );
ok( 'test.ex.com' !~ HTTP_URI() );
ok( 'https://test.ex.com' =~ HTTP_URI() );
ok( 'https://test.ex.com/' =~ HTTP_URI() );
ok( 'https://test.ex.com/a' =~ HTTP_URI() );
ok( 'https://test.ex.com/?<script>' !~ HTTP_URI() );
my $re;
ok( $re = reDomainsToHost('a.com b.org c.net') );
ok( 'test.d.fr' !~ $re );
foreach (qw(a.com b.org c.net)) {
ok( "test.$_" =~ $re );
ok( "test..$_" !~ $re );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment