View | Details | Raw Unified | Return to bug 30646
Collapse All | Expand All

(-)a/t/db_dependent/Auth_with_ldap.t (-3 / +57 lines)
Lines 28-33 use C4::Context; Link Here
28
28
29
use Koha::Patrons;
29
use Koha::Patrons;
30
30
31
# Hide all the subrouteine redefined warnings when running this test..
32
# We reload the ldap module lots in the test and each reload triggers the 
33
# 'Subroutine X redefined at' warning.. disable that to make the test output
34
# readable.
35
$SIG{__WARN__} = sub {
36
    my $warning = shift;
37
    warn $warning unless $warning =~ /Subroutine .* redefined at/;
38
};
39
31
# Start transaction
40
# Start transaction
32
my $schema = Koha::Database->new->schema;
41
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin();
42
$schema->storage->txn_begin();
Lines 37-42 my $builder = t::lib::TestBuilder->new(); Link Here
37
# Variables controlling LDAP server config
46
# Variables controlling LDAP server config
38
my $update         = 0;
47
my $update         = 0;
39
my $replicate      = 0;
48
my $replicate      = 0;
49
my $welcome        = 0;
40
my $auth_by_bind   = 1;
50
my $auth_by_bind   = 1;
41
my $anonymous_bind = 1;
51
my $anonymous_bind = 1;
42
my $user           = 'cn=Manager,dc=metavore,dc=com';
52
my $user           = 'cn=Manager,dc=metavore,dc=com';
Lines 144-150 subtest 'checkpw_ldap tests' => sub { Link Here
144
154
145
    subtest 'auth_by_bind = 1 tests' => sub {
155
    subtest 'auth_by_bind = 1 tests' => sub {
146
156
147
        plan tests => 11;
157
        plan tests => 14;
148
158
149
        $auth_by_bind = 1;
159
        $auth_by_bind = 1;
150
160
Lines 221-227 subtest 'checkpw_ldap tests' => sub { Link Here
221
            'checkpw_ldap returns 0 if user lookup returns 0'
231
            'checkpw_ldap returns 0 if user lookup returns 0'
222
        );
232
        );
223
233
224
        $desired_bind_result = 'error';
234
        # test replicate functionality and welcome notice
235
        $desired_authentication_result = 'success';
236
        $anonymous_bind                = 1;
237
        $desired_admin_bind_result     = 'success';
238
        $desired_search_result         = 'success';
239
        $desired_count_result          = 1;
240
        $desired_bind_result           = 'success';
241
        $replicate                     = 1;
242
        $welcome                       = 1;
243
        reload_ldap_module();
244
245
        $auth->mock(
246
            'ldap_entry_2_hash',
247
            sub {
248
                return (
249
                    userid       => 'hola',
250
                    branchcode   => $branchcode,
251
                    categorycode => $categorycode,
252
                    email        => 'me@myemail.com',
253
                );
254
            }
255
        );
256
257
        C4::Auth_with_ldap::checkpw_ldap( 'hola', password => 'hey' );
258
        my $patrons = Koha::Patrons->search( { userid => 'hola' } );
259
        is( $patrons->count, 1, 'New patron added with "replicate"' );
260
261
        $patron = $patrons->next;
262
        my $queued_notices = Koha::Notice::Messages->search(
263
            { borrowernumber => $patron->borrowernumber } );
264
        is( $queued_notices->count, 1,
265
            "One notice queued when `welcome` is set" );
266
267
        my $THE_notice = $queued_notices->next;
268
        is( $THE_notice->status, 'failed', "The notice was sent immediately" );
269
270
        # clean up
271
        $patron->delete;
272
        $replicate = 0;
273
        $welcome   = 0;
274
        $auth->unmock('ldap_entry_2_hash');
275
        # end replicate testing
276
        
277
        $desired_count_result = 0;
278
        $desired_bind_result  = 'error';
225
        reload_ldap_module();
279
        reload_ldap_module();
226
280
227
        warning_like {
281
        warning_like {
Lines 376-381 sub mockedC4Config { Link Here
376
            pass           => $pass,
430
            pass           => $pass,
377
            principal_name => '%s@my_domain.com',
431
            principal_name => '%s@my_domain.com',
378
            replicate      => $replicate,
432
            replicate      => $replicate,
433
            welcome        => $welcome,
379
            update         => $update,
434
            update         => $update,
380
            user           => $user,
435
            user           => $user,
381
        );
436
        );
382
- 

Return to bug 30646