|
Lines 16-23
Link Here
|
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
use Test::More tests => 3; |
19 |
use Test::More tests => 4; |
| 20 |
use C4::Context; |
20 |
use C4::Context; |
|
|
21 |
use t::lib::Mocks; |
| 21 |
|
22 |
|
| 22 |
my $dbh = C4::Context->dbh; |
23 |
my $dbh = C4::Context->dbh; |
| 23 |
my $sql_mode = $dbh->selectrow_array(q|SELECT @@SQL_MODE|); |
24 |
my $sql_mode = $dbh->selectrow_array(q|SELECT @@SQL_MODE|); |
|
Lines 33-35
subtest 'db_scheme2dbi' => sub {
Link Here
|
| 33 |
is(Koha::Database::db_scheme2dbi('xxx'), 'mysql', 'ask for unsupported DBMS, get mysql'); |
34 |
is(Koha::Database::db_scheme2dbi('xxx'), 'mysql', 'ask for unsupported DBMS, get mysql'); |
| 34 |
is(Koha::Database::db_scheme2dbi(), 'mysql', 'ask for nothing, get mysql'); |
35 |
is(Koha::Database::db_scheme2dbi(), 'mysql', 'ask for nothing, get mysql'); |
| 35 |
}; |
36 |
}; |
| 36 |
- |
37 |
|
|
|
38 |
subtest 'generate_dsn' => sub { |
| 39 |
plan tests => 6; |
| 40 |
|
| 41 |
my $config = Koha::Config->get_instance; |
| 42 |
|
| 43 |
t::lib::Mocks::mock_config( 'database', 'koha' ); |
| 44 |
t::lib::Mocks::mock_config( 'hostname', 'localhost' ); |
| 45 |
t::lib::Mocks::mock_config( 'port', '3306' ); |
| 46 |
t::lib::Mocks::mock_config( 'db_scheme', 'mysql' ); |
| 47 |
t::lib::Mocks::mock_config( 'tls', 'no' ); |
| 48 |
|
| 49 |
is( |
| 50 |
Koha::Database::generate_dsn($config), |
| 51 |
'dbi:mysql:database=koha;host=localhost;port=3306', |
| 52 |
'DSN string for MySQL configuration without TLS.' |
| 53 |
); |
| 54 |
|
| 55 |
t::lib::Mocks::mock_config( 'tls', 'yes' ); |
| 56 |
is( |
| 57 |
Koha::Database::generate_dsn($config), |
| 58 |
'dbi:mysql:database=koha;host=localhost;port=3306;mysql_ssl=1', |
| 59 |
'DSN string for MySQL configuration with TLS without client key, client cert and ca file.' |
| 60 |
); |
| 61 |
|
| 62 |
t::lib::Mocks::mock_config( 'key', '/path/to/client-key.pem' ); |
| 63 |
is( |
| 64 |
Koha::Database::generate_dsn($config), |
| 65 |
'dbi:mysql:database=koha;host=localhost;port=3306;mysql_ssl=1;mysql_ssl_client_key=/path/to/client-key.pem', |
| 66 |
'DSN string for MySQL configuration with TLS and client key.' |
| 67 |
); |
| 68 |
|
| 69 |
t::lib::Mocks::mock_config( 'cert', '/path/to/client-cert.pem' ); |
| 70 |
is( |
| 71 |
Koha::Database::generate_dsn($config), |
| 72 |
'dbi:mysql:database=koha;host=localhost;port=3306;mysql_ssl=1;mysql_ssl_client_key=/path/to/client-key.pem;mysql_ssl_client_cert=/path/to/client-cert.pem', |
| 73 |
'DSN string for MySQL configuration with TLS, client key and client cert.' |
| 74 |
); |
| 75 |
|
| 76 |
t::lib::Mocks::mock_config( 'ca', '/path/to/ca.pem' ); |
| 77 |
is( |
| 78 |
Koha::Database::generate_dsn($config), |
| 79 |
'dbi:mysql:database=koha;host=localhost;port=3306;mysql_ssl=1;mysql_ssl_client_key=/path/to/client-key.pem;mysql_ssl_client_cert=/path/to/client-cert.pem;mysql_ssl_ca_file=/path/to/ca.pem', |
| 80 |
'DSN string for MySQL configuration with TLS with client key, client cert and ca file.' |
| 81 |
); |
| 82 |
|
| 83 |
t::lib::Mocks::mock_config( 'key', '__DB_TLS_CLIENT_KEY__' ); |
| 84 |
t::lib::Mocks::mock_config( 'cert', '__DB_TLS_CLIENT_CERTIFICATE__' ); |
| 85 |
|
| 86 |
is( |
| 87 |
Koha::Database::generate_dsn($config), |
| 88 |
'dbi:mysql:database=koha;host=localhost;port=3306;mysql_ssl=1;mysql_ssl_ca_file=/path/to/ca.pem', |
| 89 |
'DSN string for MySQL configuration with TLS with ca file.' |
| 90 |
); |
| 91 |
}; |