-
Notifications
You must be signed in to change notification settings - Fork 5.5k
mysql proxy: connection attributes parsing #17209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| #include <functional> | ||
|
|
||
| #include "source/common/buffer/buffer_impl.h" | ||
| #include "source/extensions/filters/network/mysql_proxy/mysql_codec.h" | ||
| #include "source/extensions/filters/network/mysql_proxy/mysql_codec_clogin.h" | ||
| #include "source/extensions/filters/network/mysql_proxy/mysql_utils.h" | ||
|
|
||
|
|
@@ -19,6 +22,7 @@ ClientLogin initClientLogin() { | |
| mysql_clogin_encode.setAuthResp(MySQLTestUtils::getAuthResp8()); | ||
| mysql_clogin_encode.setDb(MySQLTestUtils::getDb()); | ||
| mysql_clogin_encode.setAuthPluginName(MySQLTestUtils::getAuthPluginName()); | ||
| mysql_clogin_encode.addConnectionAttribute({"key", "val"}); | ||
| return mysql_clogin_encode; | ||
| } | ||
| }; // namespace | ||
|
|
@@ -188,8 +192,8 @@ TEST_F(MySQLCLoginTest, MySQLClientLogin41IncompleteAuthResp) { | |
| * - message is decoded using the ClientLogin class | ||
| */ | ||
| TEST_F(MySQLCLoginTest, MySQLClientLogin41EncDec) { | ||
| ClientLogin& mysql_clogin_encode = | ||
| MySQLCLoginTest::getClientLogin(CLIENT_PROTOCOL_41 | CLIENT_CONNECT_WITH_DB); | ||
| ClientLogin& mysql_clogin_encode = MySQLCLoginTest::getClientLogin( | ||
| CLIENT_PROTOCOL_41 | CLIENT_CONNECT_WITH_DB | CLIENT_CONNECT_ATTRS); | ||
| Buffer::OwnedImpl decode_data; | ||
| mysql_clogin_encode.encode(decode_data); | ||
|
|
||
|
|
@@ -204,7 +208,8 @@ TEST_F(MySQLCLoginTest, MySQLClientLogin41EncDec) { | |
| EXPECT_EQ(mysql_clogin_decode.getCharset(), mysql_clogin_encode.getCharset()); | ||
| EXPECT_EQ(mysql_clogin_decode.getUsername(), mysql_clogin_encode.getUsername()); | ||
| EXPECT_EQ(mysql_clogin_decode.getAuthResp(), mysql_clogin_encode.getAuthResp()); | ||
|
|
||
| EXPECT_EQ(mysql_clogin_decode.getConnectionAttribute(), | ||
| mysql_clogin_encode.getConnectionAttribute()); | ||
| EXPECT_TRUE(mysql_clogin_decode.getAuthPluginName().empty()); | ||
| } | ||
|
|
||
|
|
@@ -553,6 +558,106 @@ TEST_F(MySQLCLoginTest, MySQLClientLogin41IncompleteAuthPluginName) { | |
| EXPECT_EQ(mysql_clogin_decode.getAuthPluginName(), ""); | ||
| } | ||
|
|
||
| class MySQL41LoginConnAttrTest : public MySQLCLoginTest { | ||
| public: | ||
| MySQL41LoginConnAttrTest() { | ||
| login_encode = MySQLCLoginTest::getClientLogin(CLIENT_PROTOCOL_41 | CLIENT_CONNECT_WITH_DB | | ||
| CLIENT_PLUGIN_AUTH | CLIENT_CONNECT_ATTRS); | ||
| incomplete_base_len = sizeof(login_encode.getClientCap()) + | ||
| sizeof(login_encode.getMaxPacket()) + sizeof(login_encode.getCharset()) + | ||
| UNSET_BYTES + login_encode.getUsername().size() + 1 + | ||
| login_encode.getAuthResp().size() + 1 + login_encode.getDb().size() + 1 + | ||
| login_encode.getAuthPluginName().length() + 1; | ||
| } | ||
| void prepareLoginDecode(int delta_len = 0) { | ||
| Buffer::OwnedImpl buffer; | ||
| login_encode.encode(buffer); | ||
| int incomplete_len = incomplete_base_len + delta_len; | ||
| Buffer::OwnedImpl decode_data(buffer.toString().data(), incomplete_len); | ||
|
|
||
| login_decode.decode(decode_data, CHALLENGE_SEQ_NUM, decode_data.length()); | ||
| } | ||
|
|
||
| void checkLoginDecode(const std::function<void()>& additional_check = nullptr) { | ||
| EXPECT_TRUE(login_decode.isConnectWithDb()); | ||
| EXPECT_EQ(login_decode.getClientCap(), login_encode.getClientCap()); | ||
| EXPECT_EQ(login_decode.getExtendedClientCap(), login_decode.getExtendedClientCap()); | ||
| EXPECT_EQ(login_decode.getMaxPacket(), login_encode.getMaxPacket()); | ||
| EXPECT_EQ(login_decode.getCharset(), login_encode.getCharset()); | ||
| EXPECT_EQ(login_decode.getUsername(), login_encode.getUsername()); | ||
| EXPECT_EQ(login_decode.getAuthResp(), login_encode.getAuthResp()); | ||
| EXPECT_EQ(login_decode.getDb(), login_encode.getDb()); | ||
| EXPECT_EQ(login_decode.getAuthPluginName(), login_encode.getAuthPluginName()); | ||
| if (additional_check) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you compare to nullptr? |
||
| additional_check(); | ||
| } | ||
| } | ||
|
|
||
| ClientLogin login_encode; | ||
| ClientLogin login_decode; | ||
| int incomplete_base_len; | ||
|
cpakulski marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| /* | ||
| * Negative Test the MYSQL Client Login 41 message parser: | ||
| * Incomplete total length of connection attributions | ||
| */ | ||
| TEST_F(MySQL41LoginConnAttrTest, MySQLClientLogin41IncompleteConnAttrLength) { | ||
| prepareLoginDecode(); | ||
| checkLoginDecode([&]() { EXPECT_EQ(login_decode.getConnectionAttribute().size(), 0); }); | ||
| } | ||
|
|
||
| /* | ||
| * Negative Test the MYSQL Client Login 41 message parser: | ||
| * Incomplete length of connection attribution key | ||
| */ | ||
| TEST_F(MySQL41LoginConnAttrTest, MySQLClientLogin41IncompleteConnAttrKeyLength) { | ||
| prepareLoginDecode( | ||
| MySQLTestUtils::bytesOfConnAtrributeLength(login_encode.getConnectionAttribute())); | ||
|
|
||
| checkLoginDecode([&]() { EXPECT_EQ(login_decode.getConnectionAttribute().size(), 0); }); | ||
| } | ||
|
|
||
| /* | ||
| * Negative Test the MYSQL Client Login 41 message parser: | ||
| * Incomplete connection attribution key | ||
| */ | ||
| TEST_F(MySQL41LoginConnAttrTest, MySQLClientLogin41IncompleteConnAttrKey) { | ||
| prepareLoginDecode( | ||
| MySQLTestUtils::bytesOfConnAtrributeLength(login_encode.getConnectionAttribute()) + | ||
| MySQLTestUtils::sizeOfLengthEncodeInteger( | ||
| login_encode.getConnectionAttribute()[0].first.length())); | ||
| checkLoginDecode([&]() { EXPECT_EQ(login_decode.getConnectionAttribute().size(), 0); }); | ||
| } | ||
|
|
||
| /* | ||
| * Negative Test the MYSQL Client Login 41 message parser: | ||
| * Incomplete length of connection attribution val | ||
| */ | ||
| TEST_F(MySQL41LoginConnAttrTest, MySQLClientLogin41IncompleteConnAttrValLength) { | ||
| prepareLoginDecode( | ||
| MySQLTestUtils::bytesOfConnAtrributeLength(login_encode.getConnectionAttribute()) + | ||
| MySQLTestUtils::sizeOfLengthEncodeInteger( | ||
| login_encode.getConnectionAttribute()[0].first.length()) + | ||
| login_encode.getConnectionAttribute()[0].first.length()); | ||
| checkLoginDecode([&]() { EXPECT_EQ(login_decode.getConnectionAttribute().size(), 0); }); | ||
| } | ||
|
|
||
| /* | ||
| * Negative Test the MYSQL Client Login 41 message parser: | ||
| * Incomplete connection attribution val | ||
| */ | ||
| TEST_F(MySQL41LoginConnAttrTest, MySQLClientLogin41IncompleteConnAttrVal) { | ||
| prepareLoginDecode( | ||
| MySQLTestUtils::bytesOfConnAtrributeLength(login_encode.getConnectionAttribute()) + | ||
| MySQLTestUtils::sizeOfLengthEncodeInteger( | ||
| login_encode.getConnectionAttribute()[0].first.length()) + | ||
| login_encode.getConnectionAttribute()[0].first.length() + | ||
| MySQLTestUtils::sizeOfLengthEncodeInteger( | ||
| login_encode.getConnectionAttribute()[0].second.length())); | ||
| checkLoginDecode([&]() { EXPECT_EQ(login_decode.getConnectionAttribute().size(), 0); }); | ||
| } | ||
|
|
||
| /* | ||
| * Negative Test the MYSQL Client 320 login message parser: | ||
| * Incomplete header at cap | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.