[Bps-public-commit] rt-authen-externalauth branch, improve-tests, created. 0.10_01-21-g9c058f9
Ruslan Zakirov
ruz at bestpractical.com
Wed Jun 6 07:03:22 EDT 2012
The branch, improve-tests has been created
at 9c058f96e9f0067a69a57980fc85a1947fe48d1f (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;
+}
commit d281beb22d543b59b84abb97fde8905ecbd8f6d1
Merge: c74d697 ef39cf0
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Tue Jun 5 22:30:32 2012 +0400
Merge branch 'improve-tests' into try-merge-test-improvements
Conflicts:
inc/Module/Install.pm
inc/Module/Install/AutoInstall.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Include.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
xt/ldap/basics.t
xt/ldap/privileged.t
commit 6f2516f7b63594bbe32ae192ec768d145845bf50
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Tue Jun 5 22:50:08 2012 +0400
bring in M::I::Substitute for Test.pm
diff --git a/Makefile.PL b/Makefile.PL
index a4a2260..bf93ff5 100755
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -34,5 +34,14 @@ requires_rt('3.8.2');
&auto_install();
+my ($lib_path) = $INC{'RT.pm'} =~ /^(.*)[\\\/]/;
+my $local_lib_path = "$RT::LocalPath/lib";
+substitute(
+ {
+ RT_LIB_PATH => join( ' ', $local_lib_path, $lib_path ),
+ },
+ 'lib/RT/Authen/ExternalAuth/Test.pm',
+);
+
sign;
&WriteAll;
diff --git a/inc/Module/Install/Substitute.pm b/inc/Module/Install/Substitute.pm
new file mode 100644
index 0000000..56af7fe
--- /dev/null
+++ b/inc/Module/Install/Substitute.pm
@@ -0,0 +1,131 @@
+#line 1
+package Module::Install::Substitute;
+
+use strict;
+use warnings;
+use 5.008; # I don't care much about earlier versions
+
+use Module::Install::Base;
+our @ISA = qw(Module::Install::Base);
+
+our $VERSION = '0.03';
+
+require File::Temp;
+require File::Spec;
+require Cwd;
+
+#line 89
+
+sub substitute
+{
+ my $self = shift;
+ $self->{__subst} = shift;
+ $self->{__option} = {};
+ if( UNIVERSAL::isa( $_[0], 'HASH' ) ) {
+ my $opts = shift;
+ while( my ($k,$v) = each( %$opts ) ) {
+ $self->{__option}->{ lc( $k ) } = $v || '';
+ }
+ }
+ $self->_parse_options;
+
+ my @file = @_;
+ foreach my $f (@file) {
+ $self->_rewrite_file( $f );
+ }
+
+ return;
+}
+
+sub _parse_options
+{
+ my $self = shift;
+ my $cwd = Cwd::getcwd();
+ foreach my $t ( qw(from to) ) {
+ $self->{__option}->{$t} = $cwd unless $self->{__option}->{$t};
+ my $d = $self->{__option}->{$t};
+ die "Couldn't read directory '$d'" unless -d $d && -r _;
+ }
+}
+
+sub _rewrite_file
+{
+ my ($self, $file) = @_;
+ my $source = File::Spec->catfile( $self->{__option}{from}, $file );
+ $source .= $self->{__option}{sufix} if $self->{__option}{sufix};
+ unless( -f $source && -r _ ) {
+ print STDERR "Couldn't find file '$source'\n";
+ return;
+ }
+ my $dest = File::Spec->catfile( $self->{__option}{to}, $file );
+ return $self->__rewrite_file( $source, $dest );
+}
+
+sub __rewrite_file
+{
+ my ($self, $source, $dest) = @_;
+
+ my $mode = (stat($source))[2];
+
+ open my $sfh, "<$source" or die "Couldn't open '$source' for read";
+ print "Open input '$source' file for substitution\n";
+
+ my ($tmpfh, $tmpfname) = File::Temp::tempfile('mi-subst-XXXX', UNLINK => 1);
+ $self->__process_streams( $sfh, $tmpfh, ($source eq $dest)? 1: 0 );
+ close $sfh;
+
+ seek $tmpfh, 0, 0 or die "Couldn't seek in tmp file";
+
+ open my $dfh, ">$dest" or die "Couldn't open '$dest' for write";
+ print "Open output '$dest' file for substitution\n";
+
+ while( <$tmpfh> ) {
+ print $dfh $_;
+ }
+ close $dfh;
+ chmod $mode, $dest or "Couldn't change mode on '$dest'";
+}
+
+sub __process_streams
+{
+ my ($self, $in, $out, $replace) = @_;
+
+ my @queue = ();
+ my $subst = $self->{'__subst'};
+ my $re_subst = join('|', map {"\Q$_"} keys %{ $subst } );
+
+ while( my $str = <$in> ) {
+ if( $str =~ /^###\s*(before|replace|after)\:\s?(.*)$/s ) {
+ my ($action, $nstr) = ($1,$2);
+ $nstr =~ s/\@($re_subst)\@/$subst->{$1}/ge;
+
+ die "Replace action is bad idea for situations when dest is equal to source"
+ if $replace && $action eq 'replace';
+ if( $action eq 'before' ) {
+ die "no line before 'before' action" unless @queue;
+ # overwrite prev line;
+ pop @queue;
+ push @queue, $nstr;
+ push @queue, $str;
+ } elsif( $action eq 'replace' ) {
+ push @queue, $nstr;
+ } elsif( $action eq 'after' ) {
+ push @queue, $str;
+ push @queue, $nstr;
+ # skip one line;
+ <$in>;
+ }
+ } else {
+ push @queue, $str;
+ }
+ while( @queue > 3 ) {
+ print $out shift(@queue);
+ }
+ }
+ while( scalar @queue ) {
+ print $out shift(@queue);
+ }
+}
+
+1;
+
diff --git a/lib/RT/Authen/ExternalAuth/Test.pm b/lib/RT/Authen/ExternalAuth/Test.pm
index 5e9a440..6fe73c1 100644
--- a/lib/RT/Authen/ExternalAuth/Test.pm
+++ b/lib/RT/Authen/ExternalAuth/Test.pm
@@ -2,7 +2,7 @@ use strict;
use warnings;
### after: use lib qw(@RT_LIB_PATH@);
-use lib qw(/opt/rt3/local/lib /opt/rt3/lib);
+use lib qw(/opt/rt4/local/lib /opt/rt4/lib);
package RT::Authen::ExternalAuth::Test;
commit 56f4748a1b057ae4611f2e8de25879346f6da34d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Wed Jun 6 00:31:33 2012 +0400
create our generate_port method
refactoring in RT::Test was lost somewhere
diff --git a/lib/RT/Authen/ExternalAuth/Test.pm b/lib/RT/Authen/ExternalAuth/Test.pm
index 6fe73c1..b7c1c59 100644
--- a/lib/RT/Authen/ExternalAuth/Test.pm
+++ b/lib/RT/Authen/ExternalAuth/Test.pm
@@ -53,7 +53,7 @@ my %ldap;
sub bootstrap_ldap_server {
my $self = shift;
- my $port = RT::Test->generate_port;
+ my $port = $self->generate_port;
require Net::LDAP::Server::Test;
my $server = Net::LDAP::Server::Test->new( $port, auto_schema => 1 );
@@ -97,6 +97,10 @@ sub bootstrap_ldap_basics {
return ($server, $client);
}
+sub generate_port {
+ return 1024 + int rand(10000) + $$ % 1024;
+}
+
sub add_ldap_user {
my $self = shift;
my %args = @_;
commit 9c058f96e9f0067a69a57980fc85a1947fe48d1f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Wed Jun 6 00:33:03 2012 +0400
make test pass
diff --git a/xt/ldap/basics.t b/xt/ldap/basics.t
index 093772e..1689a58 100644
--- a/xt/ldap/basics.t
+++ b/xt/ldap/basics.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Authen::ExternalAuth::Test ldap => 1, tests => 16;
+use RT::Authen::ExternalAuth::Test ldap => 1, tests => 18;
my $class = 'RT::Authen::ExternalAuth::Test';
my ($server, $client) = $class->bootstrap_ldap_basics;
diff --git a/xt/ldap/privileged.t b/xt/ldap/privileged.t
index 3e14631..4dd277b 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, tests => 13;
+use RT::Authen::ExternalAuth::Test ldap => 1, tests => 15;
my $class = 'RT::Authen::ExternalAuth::Test';
diff --git a/xt/ldap/user-create.t b/xt/ldap/user-create.t
index d656f24..596d118 100644
--- a/xt/ldap/user-create.t
+++ b/xt/ldap/user-create.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Authen::ExternalAuth::Test ldap => 1, tests => 18;
+use RT::Authen::ExternalAuth::Test ldap => 1, tests => 20;
my $class = 'RT::Authen::ExternalAuth::Test';
my ($server, $client) = $class->bootstrap_ldap_basics;
diff --git a/xt/ldap_escaping.t b/xt/ldap_escaping.t
index ef8a59b..1461545 100644
--- a/xt/ldap_escaping.t
+++ b/xt/ldap_escaping.t
@@ -1,14 +1,7 @@
use strict;
use warnings;
-use RT::Test tests => undef, testing => 'RT::Authen::ExternalAuth';
-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';
-};
-
+use RT::Authen::ExternalAuth::Test tests => undef, ldap => 1;
my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
diff --git a/xt/ldap_group.t b/xt/ldap_group.t
index c305289..07e7466 100644
--- a/xt/ldap_group.t
+++ b/xt/ldap_group.t
@@ -6,14 +6,7 @@ BEGIN {
$ENV{RT_TEST_WEB_HANDLER} = 'inline';
}
-use RT::Test tests => undef, testing => 'RT::Authen::ExternalAuth';
-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';
-};
-
+use RT::Authen::ExternalAuth::Test tests => undef, ldap => 1;
my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
diff --git a/xt/obfuscate-password.t b/xt/obfuscate-password.t
index ff5c636..783a775 100644
--- a/xt/obfuscate-password.t
+++ b/xt/obfuscate-password.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Test testing => 'RT::Authen::ExternalAuth';
+use RT::Authen::ExternalAuth::Test;
RT->Config->Set(
ExternalSettings => {
diff --git a/xt/sqlite.t b/xt/sqlite.t
index 179861f..3c52649 100644
--- a/xt/sqlite.t
+++ b/xt/sqlite.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Test testing => 'RT::Authen::ExternalAuth';
+use RT::Authen::ExternalAuth::Test;
use DBI;
use File::Temp;
use Digest::MD5;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list