Skip to content

Commit f6cab7f

Browse files
committed
Merge remote-tracking branch 'origin/2.0-wl9970' into 2.0
2 parents e5cd357 + 48aa131 commit f6cab7f

File tree

2 files changed

+15
-338
lines changed

2 files changed

+15
-338
lines changed

devapi/tests/session-t.cc

Lines changed: 7 additions & 327 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ TEST_F(Sess, ssl_session)
361361
//Test if ssl is enabled using cipher
362362
auto check_ssl_impl = [](mysqlx::XSession &sess, bool enable, int line)
363363
{
364+
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
365+
SessionSettings::USER,get_user(),
366+
SessionSettings::PWD, get_password() ? get_password() : NULL ,
367+
SessionSettings::SSL_ENABLE, true);
368+
364369
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
365370

366371
auto row = res.fetchOne();
@@ -520,341 +525,16 @@ TEST_F(Sess, ssl_session)
520525
SessionSettings::SSL_ENABLE, true,
521526
SessionSettings::SSL_CA, ssl_ca);
522527

523-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
524-
525-
auto row = res.fetchOne();
526-
cout << row[0] << ":" << row[1] << endl;
527-
528-
string cipher = row[1];
529-
530-
EXPECT_FALSE(cipher.empty());
531-
532-
}
533-
534-
//using ssl-ca as SessionSettings
535-
{
536-
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
537-
SessionSettings::USER,get_user(),
538-
SessionSettings::PWD, get_password() ? get_password() : NULL ,
539-
SessionSettings::SSL_CA, ssl_ca);
540-
541-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
542-
543-
auto row = res.fetchOne();
544-
cout << row[0] << ":" << row[1] << endl;
545-
546-
string cipher = row[1];
547-
548-
EXPECT_FALSE(cipher.empty());
549-
550-
}
551-
552-
//using ssl-ca but ssl-enable = false on SessionSettings
553-
{
554-
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
555-
SessionSettings::USER,get_user(),
556-
SessionSettings::PWD, get_password() ? get_password() : NULL ,
557-
SessionSettings::SSL_ENABLE, false,
558-
SessionSettings::SSL_CA, ssl_ca);
559-
560-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
561-
562-
auto row = res.fetchOne();
563-
cout << row[0] << ":" << row[1] << endl;
564-
565-
string cipher = row[1];
566-
567-
EXPECT_TRUE(cipher.empty());
568-
569-
}
570-
571-
}
572-
573-
TEST_F(Sess, ipv6)
574-
{
575-
576-
SKIP_IF_NO_XPLUGIN;
528+
check_ssl(sess, true);
577529

578-
{
579-
mysqlx::XSession sess(SessionSettings::HOST, "::1",
580-
SessionSettings::PORT, get_port(),
581-
SessionSettings::USER, get_user(),
582-
SessionSettings::PWD, get_password() ? get_password() : nullptr ,
583-
SessionSettings::SSL_ENABLE, false);
584530
}
585531

586-
//Using URI
587-
588-
std::stringstream uri;
589-
590-
uri << "mysqlx://" << get_user();
591-
592-
if (get_password() && *get_password())
593-
uri << ":"<< get_password();
594-
595-
uri << "@" << "[::1]:" << get_port();
596-
597-
//URI without ssl_enable
598-
{
599-
mysqlx::XSession sess(uri.str());
600-
601-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
602-
603-
auto row = res.fetchOne();
604-
cout << row[0] << ":" << row[1] << endl;
605-
606-
string cipher = row[1];
607-
608-
EXPECT_TRUE(cipher.empty());
609-
}
610532

611533
//Enable SSL
612534
uri << "/?ssl-enable";
613535
{
614536
mysqlx::XSession sess(uri.str());
615537

616-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
617-
618-
auto row = res.fetchOne();
619-
cout << row[0] << ":" << row[1] << endl;
620-
621-
string cipher = row[1];
622-
623-
EXPECT_FALSE(cipher.empty());
624-
}
625-
}
626-
627-
TEST_F(Sess, view)
628-
{
629-
SKIP_IF_NO_XPLUGIN;
630-
631-
XSession s(this);
632-
633-
const string schema_name = "schemaView";
634-
const string tbl_name = "tblView";
635-
const string view_name = "view1";
636-
const string view_name2 = "view2";
637-
638-
Schema sch = s.createSchema(schema_name,true);
639-
640-
s.dropTable(schema_name, tbl_name);
641-
642-
sch.dropView(view_name).ifExists().execute();
643-
644-
std::stringstream qry;
645-
646-
qry << "CREATE TABLE `"<< schema_name <<
647-
"`.`" << tbl_name <<"` (name VARCHAR(20) ,age INT);";
648-
649-
get_sess().sql(qry.str()).execute();
650-
651-
Table tbl = sch.getTable(tbl_name, true);
652-
653-
tbl.insert("name", "age")
654-
.values("Foo", 20)
655-
.values("Bar", 30)
656-
.values("Baz", 40)
657-
.execute();
658-
659-
std::cout << "Create View" << std::endl;
660-
661-
sch.createView(view_name, false)
662-
.security(mysqlx::SQLSecurity::DEFINER)
663-
.definer("root@localhost")
664-
.definedAs(tbl.select("name as view_name", "2016-age as view_birth"))
665-
.withCheckOption(mysqlx::CheckOption::LOCAL)
666-
.execute();
667-
668-
std::cout << "Check View" << std::endl;
669-
670-
{
671-
Table view = sch.getTable(view_name);
672-
673-
RowResult res = view.select().execute();
674-
675-
EXPECT_EQ(string("view_name"), res.getColumn(0).getColumnName());
676-
EXPECT_EQ(string("view_birth"), res.getColumn(1).getColumnName());
677-
678-
for(auto row : res)
679-
{
680-
if (row.get(0).get<string>() == string("Foo"))
681-
EXPECT_EQ(1996, row.get(1).get<int>());
682-
else if (row.get(0).get<string>() == string("Bar"))
683-
EXPECT_EQ(1986, row.get(1).get<int>());
684-
else if (row.get(0).get<string>() == string("Baz"))
685-
EXPECT_EQ(1976, row.get(1).get<int>());
686-
}
687-
}
688-
689-
std::cout << "Expects error, since view is already created" << std::endl;
690-
691-
EXPECT_THROW(
692-
sch.createView(view_name, false)
693-
.security(mysqlx::SQLSecurity::DEFINER)
694-
.definedAs(tbl.select("name as view_name", "2016-age as view_birth"))
695-
.withCheckOption(mysqlx::CheckOption::LOCAL)
696-
.execute()
697-
, mysqlx::Error
698-
);
699-
700-
TableSelect tbl_select=
701-
tbl.select("name", "2*age", "1 as one", "2 as two");
702-
703-
std::vector<string> columns_list = {"view_name", "view_double_age"};
704-
705-
std::cout << "Different number of columns... Error expected" << std::endl;
706-
707-
EXPECT_THROW(
708-
sch.alterView(view_name)
709-
.columns(columns_list, "one")
710-
.security(mysqlx::SQLSecurity::DEFINER)
711-
.definer("root@localhost")
712-
.definedAs(tbl_select)
713-
.withCheckOption(mysqlx::CheckOption::LOCAL)
714-
.execute()
715-
, mysqlx::Error);
716-
717-
auto view_exec = sch.alterView(view_name)
718-
.columns(columns_list, "one", string("two"))
719-
.security(mysqlx::SQLSecurity::DEFINER)
720-
.definer("root@localhost")
721-
.definedAs(tbl_select)
722-
.withCheckOption(mysqlx::CheckOption::LOCAL);
723-
724-
TableSelect tbl_select_2 = tbl_select;
725-
726-
std::cout << "Shouldn't update the alterView" << std::endl;
727-
728-
tbl_select.limit(1);
729-
730-
tbl_select_2.limit(2);
731-
732-
//Execute copy of ViewAlter obj
733-
auto view_exec2 = view_exec;
734-
735-
view_exec2.execute();
736-
737-
std::cout << "Execute previously create TableSelect" << std::endl;
738-
739-
EXPECT_EQ(1, tbl_select.execute().count());
740-
741-
std::cout << "Execute previously create TableSelect" << std::endl;
742-
743-
EXPECT_EQ(2, tbl_select_2.execute().count());
744-
745-
std::cout << "Cannot alter View that is not created" << std::endl;
746-
747-
EXPECT_THROW( sch.alterView(view_name2)
748-
.columns("view_name", "fake")
749-
.security(mysqlx::SQLSecurity::DEFINER)
750-
.definer("root@localhost")
751-
.definedAs(tbl_select)
752-
.withCheckOption(mysqlx::CheckOption::LOCAL)
753-
.execute()
754-
, mysqlx::Error);
755-
756-
std::cout << "Check View after alterView" << std::endl;
757-
758-
{
759-
Table view = sch.getTable(view_name);
760-
761-
RowResult res = view.select().execute();
762-
763-
std::vector<Column> columns_metadata = res.getColumns();
764-
765-
EXPECT_EQ(string("view_name"), res.getColumn(0).getColumnName());
766-
EXPECT_EQ(string("view_double_age"), res.getColumn(1).getColumnName());
767-
EXPECT_EQ(string("one"), res.getColumn(2).getColumnName());
768-
EXPECT_EQ(string("two"), res.getColumn(3).getColumnName());
769-
770-
//EXPECT 3 rows, since the changed tableSelect shouldn't affect the view
771-
EXPECT_EQ(3, res.count());
772-
773-
for(auto row : res)
774-
{
775-
if (row.get(0).get<string>() == string("Foo"))
776-
EXPECT_EQ(40, row.get(1).get<int>());
777-
if (row.get(0).get<string>() == string("Bar"))
778-
EXPECT_EQ(60, row.get(1).get<int>());
779-
if (row.get(0).get<string>() == string("Baz"))
780-
EXPECT_EQ(80, row.get(1).get<int>());
781-
}
782-
783-
}
784-
785-
std::cout << "Create view with select bind" << std::endl;
786-
787-
{
788-
TableSelect sel = tbl.select();
789-
sel.where("age = :age").bind("age", 40);
790-
791-
sch.dropView(view_name).execute();
792-
793-
sch.createView(view_name).definedAs(sel).execute();
794-
795-
Table view = sch.getTable(view_name);
796-
797-
RowResult res = view.select().execute();
798-
799-
EXPECT_EQ(1, res.count());
800-
801-
Row row = res.fetchOne();
802-
803-
EXPECT_EQ(40, row.get(1).get<int>());
804-
805-
sel.bind("age", 30);
806-
807-
sch.alterView(view_name).definedAs(sel).execute();
808-
809-
res = view.select().execute();
810-
811-
EXPECT_EQ(1, res.count());
812-
813-
row = res.fetchOne();
814-
815-
EXPECT_EQ(30, row.get(1).get<int>());
816-
817-
}
818-
819-
{
820-
sch.dropView(view_name).execute();
821-
822-
sch.createView(view_name)
823-
.algorithm(Algorithm::MERGE)
824-
.security(SQLSecurity::INVOKER)
825-
.definer("unknownUser")
826-
.definedAs(tbl.select())
827-
.withCheckOption(mysqlx::CheckOption::CASCADED)
828-
.execute();
829-
830-
std::stringstream qry;
831-
832-
qry << "show create view " << schema_name << "." << view_name;
833-
834-
SqlResult result = sql(qry.str());
835-
836-
Row r = result.fetchOne();
837-
std::string data = (string)r[1];
838-
839-
cout << r[0] << ": " << data << endl;
840-
841-
EXPECT_TRUE(data.find("MERGE") != std::string::npos);
842-
EXPECT_TRUE(data.find("INVOKER") != std::string::npos);
843-
EXPECT_TRUE(data.find("unknownUser") != std::string::npos);
844-
EXPECT_TRUE(data.find("CASCADED") != std::string::npos);
845-
846-
}
847-
848-
std::cout << "Drop view" << std::endl;
849-
850-
sch.dropView(view_name).execute();
851-
852-
std::cout << "Drop view doesn't throw error because using ifExists" << std::endl;
853-
854-
sch.dropView(view_name).ifExists().execute();
855-
856-
std::cout << "Without ifExists, will throw Error if no such View." << std::endl;
857-
858-
EXPECT_THROW(sch.dropView(view_name).execute(), mysqlx::Error);
538+
check_ssl(sess, true); }
859539

860540
}

0 commit comments

Comments
 (0)