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

(-)a/Koha/REST/V1/Config/SFTP/Servers.pm (-15 lines)
Lines 166-184 sub delete { Link Here
166
    };
166
    };
167
}
167
}
168
168
169
=head3 test
170
171
Controller method that invokes Koha::SFTP::Server->test_conn
172
173
=cut
174
175
sub test {
176
    my $c = shift->openapi->valid_input or return;
177
178
    my $sftp_server = Koha::File::Transports->find( $c->param('sftp_server_id') );
179
180
    return $c->render_resource_not_found("FTP/SFTP server")
181
        unless $sftp_server;
182
}
183
184
1;
169
1;
(-)a/t/db_dependent/api/v1/sftp_servers.t (-51 / +2 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 6;
20
use Test::More tests => 5;
21
use Test::Mojo;
21
use Test::Mojo;
22
22
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
Lines 400-451 subtest 'delete() tests' => sub { Link Here
400
    $schema->storage->txn_rollback;
400
    $schema->storage->txn_rollback;
401
};
401
};
402
402
403
subtest 'test() tests' => sub {
403
1;
404
405
    plan tests => 5;
406
407
    $schema->storage->txn_begin;
408
409
    my $librarian = $builder->build_object(
410
        {
411
            class => 'Koha::Patrons',
412
            value => { flags => 3**2 }    # parameters flag = 3
413
        }
414
    );
415
    my $password = 'thePassword123';
416
    $librarian->set_password( { password => $password, skip_validation => 1 } );
417
    my $userid = $librarian->userid;
418
419
    my $patron = $builder->build_object(
420
        {
421
            class => 'Koha::Patrons',
422
            value => { flags => 0 }
423
        }
424
    );
425
426
    $patron->set_password( { password => $password, skip_validation => 1 } );
427
    my $unauth_userid = $patron->userid;
428
429
    my $sftp_server = $builder->build_object(
430
        {
431
            class => 'Koha::File::Transports',
432
            value => {
433
                password => undef,
434
                key_file => undef,
435
                status   => undef,
436
            },
437
        }
438
    );
439
    my $sftp_server_id = $sftp_server->id;
440
441
    # Unauthorized attempt to test
442
    $t->get_ok("//$unauth_userid:$password@/api/v1/sftp_server/$sftp_server_id/test_connection")->status_is(403);
443
444
    $t->get_ok("//$userid:$password@/api/v1/sftp_server/$sftp_server_id/test_connection")
445
        ->status_is( 200, 'SWAGGER3.2.4' )
446
        ->content_is( '{"1_ftp_conn":{"err":"cannot connect to '
447
            . $sftp_server->host
448
            . ': Name or service not known","msg":null,"passed":false}}', 'SWAGGER3.3.4' );
449
450
    $schema->storage->txn_rollback;
451
};
452
- 

Return to bug 39190