Skip to content

Commit 5087277

Browse files
author
Roberto Garcia
committed
Bug #23257011 CHARACTER SET HANDSHAKE NOT WORKING TO SERVER 5.6.20
Fixed incorrect encoding in connection passwords. Added test to validate that the default encoding is taken from @@character_set_server variable. Added xunit.runner.visualstudio Nuget package to run test in Visual Studio Test Explorer.
1 parent 3e441f1 commit 5087277

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
6.9.10
22
- Added user contribution in bug MySql.Web.Security.CreateUserInUserTable does not work (MySQL Bug #83656, Oracle Bug # 25046364).
3+
- Fixed incorrect encoding in connection passwords (MySQL Bug #80611, Oracle Bug #23257011).
4+
35

46
6.9.9
57
- Fix for Nested transactions are not supported in Entity Framework (MySQL Bug #71502, Oracle Bug #22366266).

Source/MySql.Data/Authentication/NativePasswordPlugins.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2012, 2017 Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -82,7 +82,7 @@ private byte[] Get411Password(string password, byte[] seedBytes)
8282

8383
SHA1 sha = new SHA1CryptoServiceProvider();
8484

85-
byte[] firstHash = sha.ComputeHash(AliasText.Encoding.Default.GetBytes(password));
85+
byte[] firstHash = sha.ComputeHash(this.Encoding.GetBytes(password));
8686
byte[] secondHash = sha.ComputeHash(firstHash);
8787

8888
byte[] input = new byte[seedBytes.Length + secondHash.Length];

Source/MySql.Data/Driver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2004, 2016, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2004, 2017 Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -324,6 +324,7 @@ public virtual void Configure(MySqlConnection connection)
324324
setNamesCmd.InternallyCreated = true;
325325
setNamesCmd.ExecuteNonQuery();
326326
}
327+
// sets character_set_results to null to return values in their original character set
327328
charSetCmd.ExecuteNonQuery();
328329

329330
if (charSet != null)

Tests/MySql.Data.Tests/CharacterSetTests.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2013, 2015 Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2013, 2017 Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -642,12 +642,12 @@ public void ExtendedCharsetOnConnection()
642642
{
643643
string database = "数据库";
644644
string user = "用户";
645-
string password = "test";
645+
string password = "tést€";
646646

647647
rootConnection.Open();
648648
MySqlCommand rootCommand = new MySqlCommand();
649649
rootCommand.Connection = rootConnection;
650-
rootCommand.CommandText = string.Format("CREATE DATABASE `{0}`;", database);
650+
rootCommand.CommandText = string.Format("CREATE DATABASE IF NOT EXISTS `{0}`;", database);
651651
rootCommand.CommandText += string.Format("GRANT ALL ON `{0}`.* to '{1}'@'localhost' identified by '{2}';", database, user, password);
652652
rootCommand.ExecuteNonQuery();
653653

@@ -675,5 +675,43 @@ public void ExtendedCharsetOnConnection()
675675
}
676676
}
677677
}
678+
679+
[Fact]
680+
public void CharacterVariablesByDefault()
681+
{
682+
MySqlConnectionStringBuilder rootSb = new MySqlConnectionStringBuilder(st.rootConn.ConnectionString);
683+
rootSb.CharacterSet = string.Empty;
684+
using (MySqlConnection rootConnection = new MySqlConnection(rootSb.ToString()))
685+
{
686+
rootConnection.Open();
687+
MySqlCommand cmd = rootConnection.CreateCommand();
688+
cmd.CommandText = "SELECT @@character_set_server";
689+
string characterSet = cmd.ExecuteScalar().ToString();
690+
Assert.False(string.IsNullOrWhiteSpace(characterSet));
691+
692+
cmd.CommandText = "SHOW VARIABLES LIKE 'character_set_c%'";
693+
using (MySqlDataReader dr = cmd.ExecuteReader())
694+
{
695+
Assert.True(dr.HasRows);
696+
while (dr.Read())
697+
{
698+
switch (dr.GetString(0).ToLowerInvariant())
699+
{
700+
case "character_set_client":
701+
Assert.Equal(characterSet, dr.GetString(1));
702+
break;
703+
case "character_set_connection":
704+
Assert.Equal(characterSet, dr.GetString(1));
705+
break;
706+
default:
707+
throw new InvalidOperationException(string.Format("Variable '{0}' not expected.", dr.GetString(0)));
708+
}
709+
}
710+
}
711+
712+
cmd.CommandText = "SELECT @@character_set_results";
713+
Assert.Equal(DBNull.Value, cmd.ExecuteScalar());
714+
}
715+
}
678716
}
679717
}

Tests/MySql.Data.Tests/MySql.Data.Tests.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
34
<Choose>
45
<When Condition="$(SolutionName) == 'MySQLClient-4.0'">
56
<PropertyGroup>
@@ -48,6 +49,8 @@
4849
<BootstrapperEnabled>true</BootstrapperEnabled>
4950
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
5051
<RestorePackages>true</RestorePackages>
52+
<NuGetPackageImportStamp>
53+
</NuGetPackageImportStamp>
5154
</PropertyGroup>
5255
<Choose>
5356
<When Condition="$(SolutionName) == 'MySQLClient-4.0'">
@@ -273,6 +276,12 @@
273276
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
274277
</ItemGroup>
275278
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
279+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
280+
<PropertyGroup>
281+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
282+
</PropertyGroup>
283+
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
284+
</Target>
276285
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
277286
Other similar extension points exist, see Microsoft.Common.targets.
278287
<Target Name="BeforeBuild">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="xunit" version="1.9.2" targetFramework="net46" />
4+
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net45" />
45
</packages>

0 commit comments

Comments
 (0)