Use skip_all and done_testing in all tests
Dagfinn Ilmari Mannsåker [Thu, 19 Feb 2015 19:11:30 +0000 (19:11 +0000)]
Makefile.PL
t/02-realms_api.t
t/03-entry_class.t
t/04-user_class.t
t/05-user_attributes.t
t/06-user_autoload.t
t/10-roles-mock.t
t/50.auth.case.sensitivity.t

index dc912f4..95a2c57 100644 (file)
@@ -11,7 +11,7 @@ requires( 'Catalyst::Plugin::Authentication' => '0.10003' );
 
 #requires('Catalyst::Model::LDAP');
 build_requires('Net::LDAP::Server::Test' => '0.07');
-build_requires('Test::More');
+build_requires('Test::More', '0.88');
 build_requires('Test::MockObject');
 build_requires('Test::Exception');
 
index 1cad31b..3d26b93 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Catalyst::Exception;
 
-use Test::More tests => 5;
+use Test::More;
 use lib 't/lib';
 use LDAPTest;
 my $server = LDAPTest::spawn_server();
@@ -35,3 +35,4 @@ isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
 my $displayname = $user->displayname;
 cmp_ok( $displayname, 'eq', 'Some Body', 'Should be Some Body' );
 
+done_testing;
index 9e16585..ebfce1f 100644 (file)
@@ -4,42 +4,38 @@ use strict;
 use warnings;
 use Catalyst::Exception;
 
-use Test::More tests => 6;
+use Test::More;
 use lib 't/lib';
 use LDAPTest;
 
-SKIP: {
+eval "use Catalyst::Model::LDAP";
+plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
 
-    eval "use Catalyst::Model::LDAP";
-    if ($@) {
-        skip "Catalyst::Model::LDAP not installed", 6;
+my $server = LDAPTest::spawn_server();
+
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+
+my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
+    {   'ldap_server' => LDAPTest::server_host(),
+        'binddn'      => 'anonymous',
+        'bindpw'      => 'dontcarehow',
+        'start_tls'   => 0,
+        'user_basedn' => 'ou=foobar',
+        'user_filter' => '(&(objectClass=person)(uid=%s))',
+        'user_scope'  => 'one',
+        'user_field'  => 'uid',
+        'use_roles'   => 0,
+        'entry_class' => 'EntryClass',
     }
+);
+
+isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
+my $user = $back->find_user( { username => 'somebody' } );
+isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+my $displayname = $user->displayname;
+cmp_ok( $displayname, 'eq', 'Some Body', 'Should be Some Body' );
+
+isa_ok( $user->ldap_entry, "EntryClass", "entry_class works" );
+is( $user->ldap_entry->my_method, 1001, "methods on entry_class works" );
 
-    my $server = LDAPTest::spawn_server();
-
-    use_ok("Catalyst::Authentication::Store::LDAP::Backend");
-
-    my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
-        {   'ldap_server' => LDAPTest::server_host(),
-            'binddn'      => 'anonymous',
-            'bindpw'      => 'dontcarehow',
-            'start_tls'   => 0,
-            'user_basedn' => 'ou=foobar',
-            'user_filter' => '(&(objectClass=person)(uid=%s))',
-            'user_scope'  => 'one',
-            'user_field'  => 'uid',
-            'use_roles'   => 0,
-            'entry_class' => 'EntryClass',
-        }
-    );
-
-    isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
-    my $user = $back->find_user( { username => 'somebody' } );
-    isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
-    my $displayname = $user->displayname;
-    cmp_ok( $displayname, 'eq', 'Some Body', 'Should be Some Body' );
-
-    isa_ok( $user->ldap_entry, "EntryClass", "entry_class works" );
-    is( $user->ldap_entry->my_method, 1001, "methods on entry_class works" );
-
-}
+done_testing;
index cd579f7..8689024 100644 (file)
@@ -4,58 +4,54 @@ use strict;
 use warnings;
 use Catalyst::Exception;
 
-use Test::More tests => 8;
+use Test::More;
 use lib 't/lib';
 use LDAPTest;
 use Storable qw/ freeze /;
 use Test::Exception;
 
-SKIP: {
+eval "use Catalyst::Model::LDAP";
+plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
 
-    eval "use Catalyst::Model::LDAP";
-    if ($@) {
-        skip "Catalyst::Model::LDAP not installed", 8;
-    }
-
-    my $server = LDAPTest::spawn_server();
+my $server = LDAPTest::spawn_server();
 
-    use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
 
-    my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
-        {   'ldap_server' => LDAPTest::server_host(),
-            'binddn'      => 'anonymous',
-            'bindpw'      => 'dontcarehow',
-            'start_tls'   => 0,
-            'user_basedn' => 'ou=foobar',
-            'user_filter' => '(&(objectClass=person)(uid=%s))',
-            'user_scope'  => 'one',
-            'user_field'  => 'uid',
-            'use_roles'   => 0,
-            'user_class' => 'UserClass',
-        }
-    );
+my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
+    {   'ldap_server' => LDAPTest::server_host(),
+        'binddn'      => 'anonymous',
+        'bindpw'      => 'dontcarehow',
+        'start_tls'   => 0,
+        'user_basedn' => 'ou=foobar',
+        'user_filter' => '(&(objectClass=person)(uid=%s))',
+        'user_scope'  => 'one',
+        'user_field'  => 'uid',
+        'use_roles'   => 0,
+        'user_class' => 'UserClass',
+    }
+);
 
-    isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
-    my $user = $back->find_user( { username => 'somebody' } );
-    isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
-    isa_ok( $user, "UserClass");
+isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
+my $user = $back->find_user( { username => 'somebody' } );
+isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+isa_ok( $user, "UserClass");
 
-    is( $user->my_method, 'frobnitz', "methods on user class work" );
+is( $user->my_method, 'frobnitz', "methods on user class work" );
 
-    # RT 69615
-    diag("stop() server");
-    $server->stop();
+# RT 69615
+diag("stop() server");
+$server->stop();
 
-    $server = LDAPTest::spawn_server();
-    ok $user->check_password('foo'), 'Can check password';
+$server = LDAPTest::spawn_server();
+ok $user->check_password('foo'), 'Can check password';
 
-    my $frozen_user;
-    lives_ok { $frozen_user = freeze $user } 'Can freeze user with Storable';
-    ok $frozen_user, 'is frozen';
+my $frozen_user;
+lives_ok { $frozen_user = freeze $user } 'Can freeze user with Storable';
+ok $frozen_user, 'is frozen';
 
-    # RT 69615
-    diag("stop() server");
-    $server->stop();
+# RT 69615
+diag("stop() server");
+$server->stop();
 
-}
+done_testing;
 
index 88d3ac3..54d79c9 100644 (file)
@@ -4,50 +4,45 @@ use strict;
 use warnings;
 use Catalyst::Exception;
 
-use Test::More tests => 9;
+use Test::More;
 use lib 't/lib';
 use LDAPTest;
 
-SKIP: {
+eval "use Catalyst::Model::LDAP";
+plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
 
-    eval "use Catalyst::Model::LDAP";
-    if ($@) {
-        skip "Catalyst::Model::LDAP not installed", 9;
-    }
-
-    my $server = LDAPTest::spawn_server();
+my $server = LDAPTest::spawn_server();
 
-    use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
 
-    my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
-        {   'ldap_server' => LDAPTest::server_host(),
-            'binddn'      => 'anonymous',
-            'bindpw'      => 'dontcarehow',
-            'start_tls'   => 0,
-            'user_basedn' => 'ou=foobar',
-            'user_filter' => '(&(objectClass=person)(uid=%s))',
-            'user_scope'  => 'one',
-            'user_field'  => 'uid',
-            'use_roles'   => 0,
-            'entry_class' => 'EntryClass',
-        }
-    );
-
-    isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
-    my $user = $back->find_user( { username => 'somebody' } );
-    isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
+    {   'ldap_server' => LDAPTest::server_host(),
+        'binddn'      => 'anonymous',
+        'bindpw'      => 'dontcarehow',
+        'start_tls'   => 0,
+        'user_basedn' => 'ou=foobar',
+        'user_filter' => '(&(objectClass=person)(uid=%s))',
+        'user_scope'  => 'one',
+        'user_field'  => 'uid',
+        'use_roles'   => 0,
+        'entry_class' => 'EntryClass',
+    }
+);
 
-    #Check DN
-    ok $user->dn,"Get DN from AUTOLOAD"; #THIS ONLY WORKS BECAUSE dn is included as a user attribute in the test LDAP server.
-    ok defined $user->has_attribute('dn'),"Get dn from has_attribute";
+isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
+my $user = $back->find_user( { username => 'somebody' } );
+isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
 
-    #Check Username
-    ok $user->username, "Get username from AUTOLOAD";
-    ok defined $user->has_attribute('username'),"Get username from has_attribute";
+#Check DN
+ok $user->dn,"Get DN from AUTOLOAD"; #THIS ONLY WORKS BECAUSE dn is included as a user attribute in the test LDAP server.
+ok defined $user->has_attribute('dn'),"Get dn from has_attribute";
 
-    #Make sure both methods match output
-    ok $user->username eq $user->has_attribute('username'),"username from AUTOLOAD and has_attribute should match";
-    ok $user->dn eq $user->has_attribute('dn'),"dn from AUTOLOAD and has_attribute should match";
+#Check Username
+ok $user->username, "Get username from AUTOLOAD";
+ok defined $user->has_attribute('username'),"Get username from has_attribute";
 
+#Make sure both methods match output
+ok $user->username eq $user->has_attribute('username'),"username from AUTOLOAD and has_attribute should match";
+ok $user->dn eq $user->has_attribute('dn'),"dn from AUTOLOAD and has_attribute should match";
 
-}
+done_testing;
index b12c815..9376291 100644 (file)
@@ -23,4 +23,4 @@ ok(my $meth = $o->can('exists'), 'can returns true');
 
 is($o->$meth, $message, 'can returns right coderef');
 
-done_testing;;
+done_testing;
index 359e76e..49a7d18 100644 (file)
@@ -4,111 +4,108 @@ use strict;
 use warnings;
 use Catalyst::Exception;
 
-use Test::More tests => 11;
+use Test::More;
 use Test::MockObject::Extends;
 use Test::Exception;
 use Net::LDAP::Entry;
 use lib 't/lib';
 
-SKIP: {
+eval "use Catalyst::Model::LDAP";
+plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
 
-    eval "use Catalyst::Model::LDAP";
-    if ($@) {
-        skip "Catalyst::Model::LDAP not installed", 11;
-    }
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
 
-    use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+my (@searches, @binds);
+for my $i (0..1) {
 
-    my (@searches, @binds);
-    for my $i (0..1) {
+    my $back = Catalyst::Authentication::Store::LDAP::Backend->new({
+        'ldap_server' => 'ldap://127.0.0.1:555',
+        'binddn'      => 'anonymous',
+        'bindpw'      => 'dontcarehow',
+        'start_tls'   => 0,
+        'user_basedn' => 'ou=foobar',
+        'user_filter' => '(&(objectClass=inetOrgPerson)(uid=%s))',
+        'user_scope'  => 'one',
+        'user_field'  => 'uid',
+        'use_roles'   => 1,
+        'role_basedn' => 'ou=roles',
+        'role_filter' => '(&(objectClass=posixGroup)(memberUid=%s))',
+        'role_scope'  => 'one',
+        'role_field'  => 'userinrole',
+        'role_value'  => 'cn',
+        'role_search_as_user' => $i,
+    });
+    $back = Test::MockObject::Extends->new($back);
+    my $bind_msg = Test::MockObject->new;
+    $bind_msg->mock(is_error => sub {}); # Cause bind call to always succeed
+    my $ldap = Test::MockObject->new;
+    $ldap->mock('bind', sub { shift; push (@binds, [@_]); return $bind_msg});
+    $ldap->mock('unbind' => sub {});
+    $ldap->mock('disconnect' => sub {});
+    my $search_res = Test::MockObject->new();
+    my $search_is_error = 0;
+    $search_res->mock(is_error => sub { $search_is_error });
+    $search_res->mock(entries => sub {
+        return map 
+            {   my $id = $_; 
+                Test::MockObject->new->mock(
+                    get_value => sub { "quux$id" }
+                ) 
+            }
+            qw/one two/
+    });
+    my @user_entries;
+    $search_res->mock(pop_entry => sub { return pop @user_entries });
+    $ldap->mock('search', sub { shift; push(@searches, [@_]); return $search_res; });
+    $back->mock('ldap_connect' => sub { $ldap });
+    my $user_entry = Net::LDAP::Entry->new;
+    push(@user_entries, $user_entry);
+    $user_entry->dn('ou=foobar');
+    $user_entry->add(
+        uid => 'somebody',
+        cn => 'test',
+    );
+    my $user = $back->find_user( { username => 'somebody' } );
+    isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+    $user->check_password('password');
+    is_deeply( [sort $user->roles], 
+               [sort qw/quuxone quuxtwo/], 
+                "User has the expected set of roles" );
 
-        my $back = Catalyst::Authentication::Store::LDAP::Backend->new({
-            'ldap_server' => 'ldap://127.0.0.1:555',
-            'binddn'      => 'anonymous',
-            'bindpw'      => 'dontcarehow',
-            'start_tls'   => 0,
-            'user_basedn' => 'ou=foobar',
-            'user_filter' => '(&(objectClass=inetOrgPerson)(uid=%s))',
-            'user_scope'  => 'one',
-            'user_field'  => 'uid',
-            'use_roles'   => 1,
-            'role_basedn' => 'ou=roles',
-            'role_filter' => '(&(objectClass=posixGroup)(memberUid=%s))',
-            'role_scope'  => 'one',
-            'role_field'  => 'userinrole',
-            'role_value'  => 'cn',
-            'role_search_as_user' => $i,
-        });
-        $back = Test::MockObject::Extends->new($back);
-        my $bind_msg = Test::MockObject->new;
-        $bind_msg->mock(is_error => sub {}); # Cause bind call to always succeed
-        my $ldap = Test::MockObject->new;
-        $ldap->mock('bind', sub { shift; push (@binds, [@_]); return $bind_msg});
-        $ldap->mock('unbind' => sub {});
-        $ldap->mock('disconnect' => sub {});
-        my $search_res = Test::MockObject->new();
-        my $search_is_error = 0;
-        $search_res->mock(is_error => sub { $search_is_error });
-        $search_res->mock(entries => sub {
-            return map 
-                {   my $id = $_; 
-                    Test::MockObject->new->mock(
-                        get_value => sub { "quux$id" }
-                    ) 
-                }
-                qw/one two/
-        });
-        my @user_entries;
-        $search_res->mock(pop_entry => sub { return pop @user_entries });
-        $ldap->mock('search', sub { shift; push(@searches, [@_]); return $search_res; });
-        $back->mock('ldap_connect' => sub { $ldap });
-        my $user_entry = Net::LDAP::Entry->new;
-        push(@user_entries, $user_entry);
-        $user_entry->dn('ou=foobar');
-        $user_entry->add(
-            uid => 'somebody',
-            cn => 'test',
-        );
-        my $user = $back->find_user( { username => 'somebody' } );
-        isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
-        $user->check_password('password');
-        is_deeply( [sort $user->roles], 
-                   [sort qw/quuxone quuxtwo/], 
-                    "User has the expected set of roles" );
+    $search_is_error = 1;
+    lives_ok {
+        ok !$back->find_user( { username => 'doesnotexist' } ),
+            'Nonexistent user returns undef';
+    } 'No exception thrown for nonexistent user';
 
-        $search_is_error = 1;
-        lives_ok {
-            ok !$back->find_user( { username => 'doesnotexist' } ),
-                'Nonexistent user returns undef';
-        } 'No exception thrown for nonexistent user';
-
-    }
-    is_deeply(\@searches, [ 
-        ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'],
-        ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]],
-        ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'],
-        ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'],
-        ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]],
-        ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'],
-    ], 'User searches as expected');
-    is_deeply(\@binds, [
-        [ undef ], # First user search
-        [
-            'ou=foobar',
-            'password',
-            'password'
-        ], # Rebind to confirm user
-        [
-            undef
-        ], # Rebind with initial credentials to find roles
-        [ undef ], # Second user search
-        # 2nd pass round main loop
-        [  undef ], # First user search
-        [
-            'ou=foobar',
-            'password',
-            'password'
-        ], # Rebind to confirm user _and_ lookup roles;
-        [ undef ], # Second user search
-    ], 'Binds as expected');
 }
+is_deeply(\@searches, [ 
+    ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'],
+    ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]],
+    ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'],
+    ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'],
+    ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]],
+    ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'],
+], 'User searches as expected');
+is_deeply(\@binds, [
+    [ undef ], # First user search
+    [
+        'ou=foobar',
+        'password',
+        'password'
+    ], # Rebind to confirm user
+    [
+        undef
+    ], # Rebind with initial credentials to find roles
+    [ undef ], # Second user search
+    # 2nd pass round main loop
+    [  undef ], # First user search
+    [
+        'ou=foobar',
+        'password',
+        'password'
+    ], # Rebind to confirm user _and_ lookup roles;
+    [ undef ], # Second user search
+], 'Binds as expected');
+
+done_testing;
index ca3cbd7..c4d669d 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Catalyst::Exception;
 
-use Test::More tests => 4;
+use Test::More;
 
 use lib 't/lib';
 use LDAPTest;
@@ -35,3 +35,4 @@ isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
 ok( my $user_mixed = $back->find_user( { username => 'SOmeBOdy' } ), "find_user (mixed case)" );
 isa_ok( $user_mixed, "Catalyst::Authentication::Store::LDAP::User" );
 
+done_testing;