[Bps-public-commit] rt-authen-externalauth branch, improve-tests, created. 0.09-13-gef39cf0

Ruslan Zakirov ruz at bestpractical.com
Mon May 9 08:38:24 EDT 2011


The branch, improve-tests has been created
        at  ef39cf013f260c8ff503137ea5a3b236cac91aa9 (commit)

- Log -----------------------------------------------------------------
commit 8a9a501fadb44a9b5a43e981552bc543f2cfd69c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 7 17:47:07 2011 +0400

    .../Test.pm

diff --git a/lib/RT/Authen/ExternalAuth/Test.pm b/lib/RT/Authen/ExternalAuth/Test.pm
new file mode 100644
index 0000000..04383c5
--- /dev/null
+++ b/lib/RT/Authen/ExternalAuth/Test.pm
@@ -0,0 +1,86 @@
+use strict;
+use warnings;
+
+### after: use lib qw(@RT_LIB_PATH@);
+use lib qw(/opt/rt3/local/lib /opt/rt3/lib);
+
+package RT::Authen::ExternalAuth::Test;
+
+our @ISA;
+BEGIN {
+    local $@;
+    eval { require RT::Test; 1 } or do {
+        require Test::More;
+        Test::More::BAIL_OUT(
+            "requires 3.8 to run tests. Error:\n$@\n"
+            ."You may need to set PERL5LIB=/path/to/rt/lib"
+        );
+    };
+    push @ISA, 'RT::Test';
+}
+
+sub import {
+    my $class = shift;
+    my %args  = @_;
+
+    $args{'requires'} ||= [];
+    if ( $args{'testing'} ) {
+        unshift @{ $args{'requires'} }, 'RT::Authen::ExternalAuth';
+    } else {
+        $args{'testing'} = 'RT::Authen::ExternalAuth';
+    }
+
+    $class->SUPER::import( %args );
+    $class->export_to_level(1);
+
+    require RT::Authen::ExternalAuth;
+}
+
+sub bootstrap_ldap_server {
+    my $self = shift;
+
+    my $port = 1024 + int rand(10000) + $$ % 1024;
+
+    require Net::LDAP::Server::Test;
+    my $server = Net::LDAP::Server::Test->new( $port, auto_schema => 1 );
+    return () unless $server;
+
+    return ($server, "localhost:$port", $port);
+}
+
+sub bootstrap_ldap_basics {
+    my $self = shift;
+    my ($server, $address, $port) = $self->bootstrap_ldap_server;
+
+    my $client = Net::LDAP->new( $address );
+    $client->bind;
+
+    RT->Config->Set( Plugins                     => 'RT::Authen::ExternalAuth' );
+    RT->Config->Set( ExternalAuthPriority        => ['My_LDAP'] );
+    RT->Config->Set( ExternalInfoPriority        => ['My_LDAP'] );
+    RT->Config->Set( ExternalServiceUsesSSLorTLS => 0 );
+    RT->Config->Set( AutoCreateNonExternalUsers  => 0 );
+    RT->Config->Set( AutoCreate  => undef );
+    RT->Config->Set(
+        ExternalSettings => {
+            'My_LDAP' => {
+                'type'            => 'ldap',
+                'server'          => $address,
+                'base'            => 'dc=bestpractical,dc=com',
+                'filter'          => '(objectClass=*)',
+                'd_filter'        => '()',
+                'tls'             => 0,
+                'net_ldap_args'   => [ version => 3 ],
+                'attr_match_list' => [ 'Name', 'EmailAddress' ],
+                'attr_map'        => {
+                    'Name'         => 'uid',
+                    'EmailAddress' => 'mail',
+                },
+            },
+        },
+    );
+    return ($server, $client);
+
+}
+
+1;

commit 2361eee6e3bb095a9cdfaf164cf185876bc58b76
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 7 19:13:58 2011 +0400

    update M::I

diff --git a/inc/Module/Install.pm b/inc/Module/Install.pm
index 8ee839d..74caf9c 100644
--- a/inc/Module/Install.pm
+++ b/inc/Module/Install.pm
@@ -31,7 +31,7 @@ BEGIN {
 	# This is not enforced yet, but will be some time in the next few
 	# releases once we can make sure it won't clash with custom
 	# Module::Install extensions.
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 
 	# Storage for the pseudo-singleton
 	$MAIN    = undef;
@@ -467,4 +467,4 @@ sub _CLASS ($) {
 
 1;
 
-# Copyright 2008 - 2010 Adam Kennedy.
+# Copyright 2008 - 2011 Adam Kennedy.
diff --git a/inc/Module/Install/AutoInstall.pm b/inc/Module/Install/AutoInstall.pm
index f1f5356..bc3d172 100644
--- a/inc/Module/Install/AutoInstall.pm
+++ b/inc/Module/Install/AutoInstall.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Base.pm b/inc/Module/Install/Base.pm
index b55bda3..d3662c9 100644
--- a/inc/Module/Install/Base.pm
+++ b/inc/Module/Install/Base.pm
@@ -4,7 +4,7 @@ package Module::Install::Base;
 use strict 'vars';
 use vars qw{$VERSION};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 }
 
 # Suspend handler for "redefined" warnings
diff --git a/inc/Module/Install/Can.pm b/inc/Module/Install/Can.pm
index 71ccc27..276409a 100644
--- a/inc/Module/Install/Can.pm
+++ b/inc/Module/Install/Can.pm
@@ -9,7 +9,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Fetch.pm b/inc/Module/Install/Fetch.pm
index ec1f106..093cb7a 100644
--- a/inc/Module/Install/Fetch.pm
+++ b/inc/Module/Install/Fetch.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Include.pm b/inc/Module/Install/Include.pm
index a28cd4c..90cc979 100644
--- a/inc/Module/Install/Include.pm
+++ b/inc/Module/Install/Include.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Makefile.pm b/inc/Module/Install/Makefile.pm
index 5dfd0e9..4c71003 100644
--- a/inc/Module/Install/Makefile.pm
+++ b/inc/Module/Install/Makefile.pm
@@ -8,7 +8,7 @@ use Fcntl qw/:flock :seek/;
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Metadata.pm b/inc/Module/Install/Metadata.pm
index cfe45b3..3b01e09 100644
--- a/inc/Module/Install/Metadata.pm
+++ b/inc/Module/Install/Metadata.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
@@ -515,6 +515,7 @@ sub __extract_license {
 		'GNU Free Documentation license'     => 'unrestricted', 1,
 		'GNU Affero General Public License'  => 'open_source',  1,
 		'(?:Free)?BSD license'               => 'bsd',          1,
+		'Artistic license 2\.0'              => 'artistic_2',   1,
 		'Artistic license'                   => 'artistic',     1,
 		'Apache (?:Software )?license'       => 'apache',       1,
 		'GPL'                                => 'gpl',          1,
@@ -550,9 +551,9 @@ sub license_from {
 
 sub _extract_bugtracker {
 	my @links   = $_[0] =~ m#L<(
-	 \Qhttp://rt.cpan.org/\E[^>]+|
-	 \Qhttp://github.com/\E[\w_]+/[\w_]+/issues|
-	 \Qhttp://code.google.com/p/\E[\w_\-]+/issues/list
+	 https?\Q://rt.cpan.org/\E[^>]+|
+	 https?\Q://github.com/\E[\w_]+/[\w_]+/issues|
+	 https?\Q://code.google.com/p/\E[\w_\-]+/issues/list
 	 )>#gx;
 	my %links;
 	@links{@links}=();
diff --git a/inc/Module/Install/Win32.pm b/inc/Module/Install/Win32.pm
index edc18b4..3139a63 100644
--- a/inc/Module/Install/Win32.pm
+++ b/inc/Module/Install/Win32.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/WriteAll.pm b/inc/Module/Install/WriteAll.pm
index d0f6599..1f724a7 100644
--- a/inc/Module/Install/WriteAll.pm
+++ b/inc/Module/Install/WriteAll.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = qw{Module::Install::Base};
 	$ISCORE  = 1;
 }

commit 1a30a4ec9551d969c190cea64544cd5820b6f07a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 7 19:16:03 2011 +0400

    make author's tests recursive

diff --git a/Makefile.PL b/Makefile.PL
index 4e55763..d4cb1bf 100755
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -27,7 +27,7 @@ feature 'SSO Cookie Sources' =>
     recommends('CGI::Cookie' => 0),
     ;
 
-author_tests('xt');
+recursive_author_tests('xt');
 
 requires_rt('3.8.2');
 

commit 6ea70c0a95830dd07b6f4a032888faef4af52d46
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 7 19:16:55 2011 +0400

    sub-dir for ldap tests

diff --git a/xt/ldap.t b/xt/ldap/basics.t
similarity index 100%
rename from xt/ldap.t
rename to xt/ldap/basics.t

commit 02c4d451458a14104d4dfea104b4b50129fd41ac
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 7 19:19:31 2011 +0400

    use API from .../Test.pm

diff --git a/xt/ldap/basics.t b/xt/ldap/basics.t
index 89b9203..754c94e 100644
--- a/xt/ldap/basics.t
+++ b/xt/ldap/basics.t
@@ -1,21 +1,24 @@
 use strict;
 use warnings;
 
-use RT::Test;
-use Net::LDAP;
-use RT::Authen::ExternalAuth;
-
-eval { require Net::LDAP::Server::Test; 1; } or do {
-    plan skip_all => 'Unable to test without Net::Server::LDAP::Test';
-};
+BEGIN {
+    eval {
+        use Net::LDAP;
+        use Net::LDAP::Server::Test;
+        1;
+    } or do {
+        use Test::More;
+        plan skip_all => 'Unable to test without LDAP modules: '. $@;
+        exit;
+    }
+}
 
+use RT::Authen::ExternalAuth::Test;
+my $class = 'RT::Authen::ExternalAuth::Test';
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
-ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
-    "spawned test LDAP server on port $ldap_port" );
+my ($server, $client) = $class->bootstrap_ldap_basics;
+ok( $server, "spawned test LDAP server" );
 
-my $ldap = Net::LDAP->new("localhost:$ldap_port");
-$ldap->bind();
 my $username = "testuser";
 my $dn       = "uid=$username,dc=bestpractical,dc=com";
 my $entry    = {
@@ -25,32 +28,7 @@ my $entry    = {
     objectClass  => 'User',
     userPassword => 'password',
 };
-$ldap->add( $dn, attr => [%$entry] );
-
-RT->Config->Set( Plugins                     => 'RT::Authen::ExternalAuth' );
-RT->Config->Set( ExternalAuthPriority        => ['My_LDAP'] );
-RT->Config->Set( ExternalInfoPriority        => ['My_LDAP'] );
-RT->Config->Set( ExternalServiceUsesSSLorTLS => 0 );
-RT->Config->Set( AutoCreateNonExternalUsers  => 0 );
-RT->Config->Set( AutoCreate  => undef );
-RT->Config->Set(
-    ExternalSettings => {    # AN EXAMPLE DB SERVICE
-        'My_LDAP' => {
-            'type'            => 'ldap',
-            'server'          => "127.0.0.1:$ldap_port",
-            'base'            => 'dc=bestpractical,dc=com',
-            'filter'          => '(objectClass=*)',
-            'd_filter'        => '()',
-            'tls'             => 0,
-            'net_ldap_args'   => [ version => 3 ],
-            'attr_match_list' => [ 'Name', 'EmailAddress' ],
-            'attr_map'        => {
-                'Name'         => 'uid',
-                'EmailAddress' => 'mail',
-            }
-        },
-    }
-);
+$client->add( $dn, attr => [%$entry] );
 
 my ( $baseurl, $m ) = RT::Test->started_ok();
 
@@ -59,15 +37,15 @@ diag "test uri login";
     ok( !$m->login( 'fakeuser', 'password' ), 'not logged in with fake user' );
     ok( $m->login( 'testuser', 'password' ), 'logged in' );
 }
+
 diag "test user creation";
 {
-my $testuser = RT::User->new($RT::SystemUser);
-my ($ok,$msg) = $testuser->Load( 'testuser' );
-ok($ok,$msg);
-is($testuser->EmailAddress,'testuser at invalid.tld');
+    my $testuser = RT::User->new($RT::SystemUser);
+    my ($ok,$msg) = $testuser->Load( 'testuser' );
+    ok($ok,$msg);
+    is($testuser->EmailAddress,'testuser at invalid.tld');
 }
 
-
 diag "test form login";
 {
     $m->logout;
@@ -93,6 +71,6 @@ diag "test redirect after login";
     is( $m->uri, $baseurl . '/SelfService/Closed.html' );
 }
 
-$ldap->unbind();
+$client->unbind();
 
 $m->get_warnings;

commit 7edd6f4ded28e5af102c50e1fe5320fccadc10b7
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun May 8 00:23:20 2011 +0400

    move test file

diff --git a/xt/ldap_privileged.t b/xt/ldap/privileged.t
similarity index 100%
rename from xt/ldap_privileged.t
rename to xt/ldap/privileged.t

commit 8a5071525d66fd716374f221e7aba6e4012e8ff9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun May 8 00:25:34 2011 +0400

    move LDAP dependecy checks into .../Test.pm

diff --git a/lib/RT/Authen/ExternalAuth/Test.pm b/lib/RT/Authen/ExternalAuth/Test.pm
index 04383c5..3939a78 100644
--- a/lib/RT/Authen/ExternalAuth/Test.pm
+++ b/lib/RT/Authen/ExternalAuth/Test.pm
@@ -30,6 +30,19 @@ sub import {
         $args{'testing'} = 'RT::Authen::ExternalAuth';
     }
 
+    if ( delete $args{'ldap'} ) {
+        local $@;
+        eval {
+            require Net::LDAP;
+            require Net::LDAP::Server::Test;
+            1;
+        } or do {
+            require Test::More;
+            Test::More::plan( skip_all => 'Unable to test without LDAP modules: '. $@ );
+            exit;
+        }
+    }
+
     $class->SUPER::import( %args );
     $class->export_to_level(1);
 
diff --git a/xt/ldap/basics.t b/xt/ldap/basics.t
index 754c94e..7146478 100644
--- a/xt/ldap/basics.t
+++ b/xt/ldap/basics.t
@@ -1,19 +1,7 @@
 use strict;
 use warnings;
 
-BEGIN {
-    eval {
-        use Net::LDAP;
-        use Net::LDAP::Server::Test;
-        1;
-    } or do {
-        use Test::More;
-        plan skip_all => 'Unable to test without LDAP modules: '. $@;
-        exit;
-    }
-}
-
-use RT::Authen::ExternalAuth::Test;
+use RT::Authen::ExternalAuth::Test ldap => 1;
 my $class = 'RT::Authen::ExternalAuth::Test';
 
 my ($server, $client) = $class->bootstrap_ldap_basics;

commit 6968f31b4e8c6f55e06bbe590b9e44294f0b696c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun May 8 00:27:40 2011 +0400

    use new tests API to cut code

diff --git a/xt/ldap/privileged.t b/xt/ldap/privileged.t
index 770cea8..c409c75 100644
--- a/xt/ldap/privileged.t
+++ b/xt/ldap/privileged.t
@@ -1,20 +1,13 @@
 use strict;
 use warnings;
 
-use RT::Test;
-use Net::LDAP;
-use RT::Authen::ExternalAuth;
+use RT::Authen::ExternalAuth::Test ldap => 1;
+my $class = 'RT::Authen::ExternalAuth::Test';
 
-eval { require Net::LDAP::Server::Test; 1; } or do {
-    plan skip_all => 'Unable to test without Net::Server::LDAP::Test';
-};
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
-ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
-    "spawned test LDAP server on port $ldap_port" );
+my ($server, $client) = $class->bootstrap_ldap_basics;
+ok( $server, "spawned test LDAP server" );
 
-my $ldap = Net::LDAP->new("localhost:$ldap_port");
-$ldap->bind();
 my $username = "testuser";
 my $dn       = "uid=$username,dc=bestpractical,dc=com";
 my $entry    = {
@@ -24,31 +17,9 @@ my $entry    = {
     objectClass  => 'User',
     userPassword => 'password',
 };
-$ldap->add( $dn, attr => [%$entry] );
+$client->add( $dn, attr => [%$entry] );
 
-RT->Config->Set( Plugins                     => 'RT::Authen::ExternalAuth' );
-RT->Config->Set( ExternalAuthPriority        => ['My_LDAP'] );
-RT->Config->Set( ExternalInfoPriority        => ['My_LDAP'] );
-RT->Config->Set( ExternalServiceUsesSSLorTLS => 0 );
-RT->Config->Set( AutoCreateNonExternalUsers  => 0 );
 RT->Config->Set( AutoCreate                  => { Privileged => 1 } );
-RT->Config->Set(
-    ExternalSettings => {    # AN EXAMPLE DB SERVICE
-        'My_LDAP' => {
-            'type'            => 'ldap',
-            'server'          => "127.0.0.1:$ldap_port",
-            'base'            => 'dc=bestpractical,dc=com',
-            'filter'          => '(objectClass=*)',
-            'tls'             => 0,
-            'net_ldap_args'   => [ version => 3 ],
-            'attr_match_list' => [ 'Name', 'EmailAddress' ],
-            'attr_map'        => {
-                'Name'         => 'uid',
-                'EmailAddress' => 'mail',
-            }
-        },
-    }
-);
 
 my ( $baseurl, $m ) = RT::Test->started_ok();
 
@@ -60,10 +31,10 @@ diag "test uri login";
 
 diag "test user creation";
 {
-my $testuser = RT::User->new($RT::SystemUser);
-my ($ok,$msg) = $testuser->Load( 'testuser' );
-ok($ok,$msg);
-is($testuser->EmailAddress,'testuser at invalid.tld');
+    my $testuser = RT::User->new($RT::SystemUser);
+    my ($ok,$msg) = $testuser->Load( 'testuser' );
+    ok($ok,$msg);
+    is($testuser->EmailAddress,'testuser at invalid.tld');
 }
 
 
@@ -80,6 +51,6 @@ diag "test form login";
 
 like( $m->uri, qr!$baseurl/(index\.html)?!, 'privileged home page' );
 
-$ldap->unbind();
+$client->unbind();
 
 $m->get_warnings;

commit a81285c7e3713446fed260568abcaa2a8d832261
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon May 9 01:28:44 2011 +0400

    use RT::Test->generate_port

diff --git a/lib/RT/Authen/ExternalAuth/Test.pm b/lib/RT/Authen/ExternalAuth/Test.pm
index 3939a78..5c931fe 100644
--- a/lib/RT/Authen/ExternalAuth/Test.pm
+++ b/lib/RT/Authen/ExternalAuth/Test.pm
@@ -52,7 +52,7 @@ sub import {
 sub bootstrap_ldap_server {
     my $self = shift;
 
-    my $port = 1024 + int rand(10000) + $$ % 1024;
+    my $port = RT::Test->generate_port;
 
     require Net::LDAP::Server::Test;
     my $server = Net::LDAP::Server::Test->new( $port, auto_schema => 1 );
@@ -93,7 +93,6 @@ sub bootstrap_ldap_basics {
         },
     );
     return ($server, $client);
-
 }
 
 1;

commit 1f6bcdfedf56a1cbaa7fe85dadfe7803d4f91321
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon May 9 14:04:15 2011 +0400

    create client in bootstrap_ldap_server, store for re-use

diff --git a/lib/RT/Authen/ExternalAuth/Test.pm b/lib/RT/Authen/ExternalAuth/Test.pm
index 5c931fe..3c5558d 100644
--- a/lib/RT/Authen/ExternalAuth/Test.pm
+++ b/lib/RT/Authen/ExternalAuth/Test.pm
@@ -49,6 +49,7 @@ sub import {
     require RT::Authen::ExternalAuth;
 }
 
+my %ldap;
 sub bootstrap_ldap_server {
     my $self = shift;
 
@@ -58,15 +59,16 @@ sub bootstrap_ldap_server {
     my $server = Net::LDAP::Server::Test->new( $port, auto_schema => 1 );
     return () unless $server;
 
-    return ($server, "localhost:$port", $port);
+    my $client = Net::LDAP->new( "localhost:$port" );
+    $client->bind;
+
+    @ldap{'server','client'} = ($server, $client);
+    return ($server, $client, "localhost:$port", $port);
 }
 
 sub bootstrap_ldap_basics {
     my $self = shift;
-    my ($server, $address, $port) = $self->bootstrap_ldap_server;
-
-    my $client = Net::LDAP->new( $address );
-    $client->bind;
+    my ($server, $client, $address, $port) = $self->bootstrap_ldap_server;
 
     RT->Config->Set( Plugins                     => 'RT::Authen::ExternalAuth' );
     RT->Config->Set( ExternalAuthPriority        => ['My_LDAP'] );

commit ce0b392020a9e8192e9fabc1471f4be23964f5e4
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon May 9 14:05:27 2011 +0400

    new method ::Test->add_ldap_user

diff --git a/lib/RT/Authen/ExternalAuth/Test.pm b/lib/RT/Authen/ExternalAuth/Test.pm
index 3c5558d..5e9a440 100644
--- a/lib/RT/Authen/ExternalAuth/Test.pm
+++ b/lib/RT/Authen/ExternalAuth/Test.pm
@@ -97,4 +97,20 @@ sub bootstrap_ldap_basics {
     return ($server, $client);
 }
 
+sub add_ldap_user {
+    my $self = shift;
+    my %args = @_;
+
+    $args{'uid'} ||= $args{'cn'};
+    $args{'cn'} ||= $args{'uid'};
+
+    my $dn = delete $args{'dn'};
+    $dn ||= "uid=". $args{'uid'} .",dc=bestpractical,dc=com";
+
+    $args{'objectClass'} ||= 'User';
+    $args{'userPassword'} ||= 'password';
+
+    return $ldap{'client'}->add( $dn, attr => [%args] );
+}
+
 1;

commit a29faa758482c28ac017eed761bb1c5bed2fb59d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon May 9 14:10:42 2011 +0400

    use add_ldap_user in old tests

diff --git a/xt/ldap/basics.t b/xt/ldap/basics.t
index 7146478..093772e 100644
--- a/xt/ldap/basics.t
+++ b/xt/ldap/basics.t
@@ -1,22 +1,17 @@
 use strict;
 use warnings;
 
-use RT::Authen::ExternalAuth::Test ldap => 1;
+use RT::Authen::ExternalAuth::Test ldap => 1, tests => 16;
 my $class = 'RT::Authen::ExternalAuth::Test';
 
 my ($server, $client) = $class->bootstrap_ldap_basics;
 ok( $server, "spawned test LDAP server" );
 
-my $username = "testuser";
-my $dn       = "uid=$username,dc=bestpractical,dc=com";
-my $entry    = {
-    cn           => $username,
-    mail         => "$username\@invalid.tld",
-    uid          => $username,
-    objectClass  => 'User',
-    userPassword => 'password',
-};
-$client->add( $dn, attr => [%$entry] );
+my $username = 'testuser';
+$class->add_ldap_user(
+    uid  => $username,
+    mail => "$username\@invalid.tld",
+);
 
 my ( $baseurl, $m ) = RT::Test->started_ok();
 
diff --git a/xt/ldap/privileged.t b/xt/ldap/privileged.t
index c409c75..3e14631 100644
--- a/xt/ldap/privileged.t
+++ b/xt/ldap/privileged.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use RT::Authen::ExternalAuth::Test ldap => 1;
+use RT::Authen::ExternalAuth::Test ldap => 1, tests => 13;
 my $class = 'RT::Authen::ExternalAuth::Test';
 
 
@@ -9,15 +9,10 @@ my ($server, $client) = $class->bootstrap_ldap_basics;
 ok( $server, "spawned test LDAP server" );
 
 my $username = "testuser";
-my $dn       = "uid=$username,dc=bestpractical,dc=com";
-my $entry    = {
-    cn           => $username,
-    mail         => "$username\@invalid.tld",
-    uid          => $username,
-    objectClass  => 'User',
-    userPassword => 'password',
-};
-$client->add( $dn, attr => [%$entry] );
+$class->add_ldap_user(
+    uid  => $username,
+    mail => "$username\@invalid.tld",
+);
 
 RT->Config->Set( AutoCreate                  => { Privileged => 1 } );
 

commit ef39cf013f260c8ff503137ea5a3b236cac91aa9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon May 9 14:11:19 2011 +0400

    make sure users properly created in variouse circumstances

diff --git a/xt/ldap/user-create.t b/xt/ldap/user-create.t
new file mode 100644
index 0000000..d656f24
--- /dev/null
+++ b/xt/ldap/user-create.t
@@ -0,0 +1,82 @@
+use strict;
+use warnings;
+
+use RT::Authen::ExternalAuth::Test ldap => 1, tests => 18;
+my $class = 'RT::Authen::ExternalAuth::Test';
+
+my ($server, $client) = $class->bootstrap_ldap_basics;
+ok( $server, "spawned test LDAP server" );
+
+my $queue = RT::Test->load_or_create_queue(Name => 'General');
+ok($queue->id, "loaded the General queue");
+
+RT->Config->Set( AutoCreate                  => { Privileged => 1 } );
+
+RT::Test->set_rights(
+    { Principal => 'Everyone', Right => [qw(SeeQueue ShowTicket CreateTicket)] },
+);
+
+my ( $baseurl, $m ) = RT::Test->started_ok();
+
+diag "first via email - a new ticket";
+{
+    my $username = new_user();
+
+    my $mail = << "MAIL";
+Subject: Test
+From: $username\@invalid.tld
+
+test
+MAIL
+
+    my ($status, $id) = RT::Test->send_via_mailgate($mail);
+    is ($status >> 8, 0, "The mail gateway exited normally");
+    ok ($id, "got id of a newly created ticket - $id");
+
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $id );
+    ok ($ticket->id, 'loaded ticket');
+
+    my $user = $ticket->CreatorObj;
+    is( $user->Name, $username );
+    is( $user->EmailAddress, "$username\@invalid.tld" );
+}
+
+diag "first web login with username";
+{
+    my $username = new_user();
+    ok( $m->login( $username, 'password' ), 'logged in' );
+
+    ok( $m->goto_create_ticket( $queue ), "go to create ticket" );
+    $m->form_name('TicketCreate');
+    $m->submit;
+
+    my ($id) = ($m->content =~ /.*Ticket (\d+) created.*/g);
+    ok $id, "created a ticket";
+
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $id );
+    ok ($ticket->id, 'loaded ticket');
+
+    my $user = $ticket->CreatorObj;
+    is( $user->Name, $username );
+    is( $user->EmailAddress, "$username\@invalid.tld" );
+}
+
+$client->unbind;
+$m->get_warnings;
+
+
+my $i = 0;
+sub new_user {
+    my $name = "testuser". ++$i;
+    $class->add_ldap_user(
+        cn   => $name,
+        mail => "$name\@invalid.tld",
+    );
+    return $name;
+}
+
+END {
+    $client->unbind if $client;
+}

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list