Skip to content

Commit 2b4975a

Browse files
committed
Bug#25530569 Fix "Invalid value type" when passing SSL_CA as
SessionSettings
1 parent d14eecb commit 2b4975a

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

devapi/session.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,21 @@ internal::XSession_base::XSession_base(SessionSettings settings)
272272
settings[SessionSettings::DB].get<string>()
273273
);
274274

275-
if (settings.has_option(SessionSettings::SSL_ENABLE))
275+
if (settings.has_option(SessionSettings::SSL_ENABLE) ||
276+
settings.has_option(SessionSettings::SSL_CA))
276277
{
277278
#ifdef WITH_SSL
278-
cdk::connection::TLS::Options opt_ssl(settings[SessionSettings::SSL_ENABLE]);
279+
280+
//ssl_enable by default, unless SSL_ENABLE = false
281+
bool ssl_enable = true;
282+
if (settings.has_option(SessionSettings::SSL_ENABLE))
283+
ssl_enable = settings[SessionSettings::SSL_ENABLE];
284+
285+
cdk::connection::TLS::Options opt_ssl(ssl_enable);
279286

280287

281288
if (settings.has_option(SessionSettings::SSL_CA))
282-
opt_ssl.set_ca(settings[SessionSettings::SSL_ENABLE].get<string>());
289+
opt_ssl.set_ca(settings[SessionSettings::SSL_CA].get<string>());
283290

284291
opt.set_tls(opt_ssl);
285292
#else

devapi/tests/session-t.cc

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ TEST_F(Sess, ssl_session)
432432
}
433433

434434

435-
//using wrong ssl-ca and ssl-ca-path as SessionSettings
435+
//using wrong ssl-ca as SessionSettings
436436
{
437437
EXPECT_THROW(
438438
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
@@ -497,4 +497,60 @@ TEST_F(Sess, ssl_session)
497497
EXPECT_FALSE(cipher.empty());
498498
}
499499

500+
//using ssl-enable and ssl-ca as SessionSettings
501+
{
502+
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
503+
SessionSettings::USER,get_user(),
504+
SessionSettings::PWD, get_password() ? get_password() : NULL ,
505+
SessionSettings::SSL_ENABLE, true,
506+
SessionSettings::SSL_CA, ssl_ca);
507+
508+
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
509+
510+
auto row = res.fetchOne();
511+
cout << row[0] << ":" << row[1] << endl;
512+
513+
string cipher = row[1];
514+
515+
EXPECT_FALSE(cipher.empty());
516+
517+
}
518+
519+
//using ssl-ca as SessionSettings
520+
{
521+
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
522+
SessionSettings::USER,get_user(),
523+
SessionSettings::PWD, get_password() ? get_password() : NULL ,
524+
SessionSettings::SSL_CA, ssl_ca);
525+
526+
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
527+
528+
auto row = res.fetchOne();
529+
cout << row[0] << ":" << row[1] << endl;
530+
531+
string cipher = row[1];
532+
533+
EXPECT_FALSE(cipher.empty());
534+
535+
}
536+
537+
//using ssl-ca but ssl-enable = false on SessionSettings
538+
{
539+
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
540+
SessionSettings::USER,get_user(),
541+
SessionSettings::PWD, get_password() ? get_password() : NULL ,
542+
SessionSettings::SSL_ENABLE, false,
543+
SessionSettings::SSL_CA, ssl_ca);
544+
545+
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
546+
547+
auto row = res.fetchOne();
548+
cout << row[0] << ":" << row[1] << endl;
549+
550+
string cipher = row[1];
551+
552+
EXPECT_TRUE(cipher.empty());
553+
554+
}
555+
500556
}

0 commit comments

Comments
 (0)