Skip to content

Commit

Permalink
Test connecting to a Unix domain socket.
Browse files Browse the repository at this point in the history
This avoids needing to run a full integration test suite when just testing the code that opens a connection is necessary.
  • Loading branch information
bgrainger committed Sep 24, 2019
1 parent 3298279 commit 7b62c79
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 57 deletions.
1 change: 1 addition & 0 deletions .ci/config/config.compression+ssl.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Data": {
"ConnectionString": "server=127.0.0.1;user id=ssltest;password=test;port=3306;database=mysqltest;ssl mode=required;use compression=true;DefaultCommandTimeout=3600",
"SocketPath": "./../../../../../.ci/run/mysql/mysqld.sock",
"PasswordlessUser": "no_password",
"SecondaryDatabase": "testdb2",
"UnsupportedFeatures": "RsaEncryption,CachingSha2Password,Tls12,UuidToBin",
Expand Down
3 changes: 2 additions & 1 deletion .ci/config/config.compression.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"Data": {
"ConnectionString": "server=127.0.0.1;user id=mysqltest;password=test;port=3306;database=mysqltest;ssl mode=none;UseCompression=true;DefaultCommandTimeout=3600",
"SocketPath": "./../../../../../.ci/run/mysql/mysqld.sock",
"PasswordlessUser": "no_password",
"SecondaryDatabase": "testdb2",
"UnsupportedFeatures": "Ed25519,RsaEncryption,CachingSha2Password,Tls12,UuidToBin",
"UnsupportedFeatures": "Ed25519,RsaEncryption,CachingSha2Password,Tls12,UnixDomainSocket,UuidToBin",
"MySqlBulkLoaderLocalCsvFile": "../../../../TestData/LoadData_UTF8_BOM_Unix.CSV",
"MySqlBulkLoaderLocalTsvFile": "../../../../TestData/LoadData_UTF8_BOM_Unix.TSV"
}
Expand Down
3 changes: 2 additions & 1 deletion .ci/config/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"Data": {
"ConnectionString": "server=127.0.0.1;user id=mysqltest;password=test;port=3306;database=mysqltest;ssl mode=none;DefaultCommandTimeout=3600",
"SocketPath": "./../../../../../.ci/run/mysql/mysqld.sock",
"PasswordlessUser": "no_password",
"SecondaryDatabase": "testdb2",
"UnsupportedFeatures": "Ed25519,RsaEncryption,CachingSha2Password,Tls12,UuidToBin",
"UnsupportedFeatures": "Ed25519,RsaEncryption,CachingSha2Password,Tls12,UnixDomainSocket,UuidToBin",
"MySqlBulkLoaderLocalCsvFile": "../../../../TestData/LoadData_UTF8_BOM_Unix.CSV",
"MySqlBulkLoaderLocalTsvFile": "../../../../TestData/LoadData_UTF8_BOM_Unix.TSV"
}
Expand Down
1 change: 1 addition & 0 deletions .ci/config/config.ssl.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Data": {
"ConnectionString": "server=127.0.0.1;user id=ssltest;password=test;port=3306;database=mysqltest;ssl mode=required;certificate file=../../../../../.ci/server/certs/ssl-client.pfx;DefaultCommandTimeout=3600",
"SocketPath": "./../../../../../.ci/run/mysql/mysqld.sock",
"PasswordlessUser": "no_password",
"SecondaryDatabase": "testdb2",
"UnsupportedFeatures": "RsaEncryption,CachingSha2Password,Tls12,UuidToBin",
Expand Down
29 changes: 14 additions & 15 deletions .ci/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,29 @@ then
fi

# check number of arguments
if [ $# -ne 4 ]
if [ $# -ne 3 ]
then
display_usage
exit 1
fi

IMAGE=$1
NAME=$2
PORT=$3
OMIT_FEATURES=$4
PORT=$2
OMIT_FEATURES=$3
MYSQL_EXTRA=

if [ "$IMAGE" == "mysql:8.0" ]; then
MYSQL_EXTRA='--default-authentication-plugin=mysql_native_password'
fi

sudo mkdir -p run/$NAME
sudo chmod 777 run/$NAME
sudo mkdir -p run/mysql
sudo chmod 777 run/mysql

docker run -d \
-v $(pwd)/run/$NAME:/var/run/mysqld:rw \
-v $(pwd)/run/mysql:/var/run/mysqld:rw \
-v $(pwd)/server:/etc/mysql/conf.d:ro \
-p $PORT:3306 \
--name $NAME \
--name mysql \
-e MYSQL_ROOT_PASSWORD='test' \
$IMAGE \
--log-bin-trust-function-creators=1 \
Expand All @@ -48,38 +47,38 @@ for i in `seq 1 120`; do
# wait for mysql to come up
sleep 1
echo "Testing if container is responding"
docker exec $NAME mysql -uroot -ptest -e "SELECT 1" >/dev/null 2>&1
docker exec mysql mysql -uroot -ptest -e "SELECT 1" >/dev/null 2>&1
if [ $? -ne 0 ]; then continue; fi

# try running the init script
echo "Creating mysqltest user"
docker exec $NAME bash -c 'mysql -uroot -ptest < /etc/mysql/conf.d/init.sql'
docker exec mysql bash -c 'mysql -uroot -ptest < /etc/mysql/conf.d/init.sql'
if [ $? -ne 0 ]; then continue; fi
if [[ $OMIT_FEATURES != *"Sha256Password"* ]]; then
docker exec $NAME bash -c 'mysql -uroot -ptest < /etc/mysql/conf.d/init_sha256.sql'
docker exec mysql bash -c 'mysql -uroot -ptest < /etc/mysql/conf.d/init_sha256.sql'
if [ $? -ne 0 ]; then continue; fi
fi

if [[ $OMIT_FEATURES != *"CachingSha2Password"* ]]; then
docker exec $NAME bash -c 'mysql -uroot -ptest < /etc/mysql/conf.d/init_caching_sha2.sql'
docker exec mysql bash -c 'mysql -uroot -ptest < /etc/mysql/conf.d/init_caching_sha2.sql'
if [ $? -ne 0 ]; then continue; fi
fi

if [[ $OMIT_FEATURES != *"Ed25519"* ]]; then
docker exec $NAME bash -c 'mysql -uroot -ptest < /etc/mysql/conf.d/init_ed25519.sql'
docker exec mysql bash -c 'mysql -uroot -ptest < /etc/mysql/conf.d/init_ed25519.sql'
if [ $? -ne 0 ]; then continue; fi
fi

# exit if successful
docker exec $NAME mysql -ussltest -ptest \
docker exec mysql mysql -ussltest -ptest \
--ssl-mode=REQUIRED \
--ssl-ca=/etc/mysql/conf.d/certs/ssl-ca-cert.pem \
--ssl-cert=/etc/mysql/conf.d/certs/ssl-client-cert.pem \
--ssl-key=/etc/mysql/conf.d/certs/ssl-client-key.pem \
-e "SELECT 1"
if [ $? -ne 0 ]; then
# mariadb uses --ssl=TRUE instead of --ssl-mode=REQUIRED
docker exec $NAME mysql -ussltest -ptest \
docker exec mysql mysql -ussltest -ptest \
--ssl=TRUE \
--ssl-ca=/etc/mysql/conf.d/certs/ssl-ca-cert.pem \
--ssl-cert=/etc/mysql/conf.d/certs/ssl-client-cert.pem \
Expand Down
2 changes: 1 addition & 1 deletion .ci/integration-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
DotNetCoreSdkVersion: ''

steps:
- bash: ${{ format('.ci/docker-run.sh {0} mysql 3300 {1}', parameters.image, parameters.unsupportedFeatures) }}
- bash: ${{ format('.ci/docker-run.sh {0} 3300 {1}', parameters.image, parameters.unsupportedFeatures) }}
displayName: 'Start Docker container'
- template: 'sidebyside-test-steps.yml'
parameters:
Expand Down
1 change: 1 addition & 0 deletions .ci/sidebyside-test-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ steps:
DATA__CERTIFICATESPATH: '$(Build.Repository.LocalPath)/.ci/server/certs/'
DATA__MYSQLBULKLOADERLOCALCSVFILE: '$(Build.Repository.LocalPath)/tests/TestData/LoadData_UTF8_BOM_Unix.CSV'
DATA__MYSQLBULKLOADERLOCALTSVFILE: '$(Build.Repository.LocalPath)/tests/TestData/LoadData_UTF8_BOM_Unix.TSV'
DATA__SOCKETPATH: '$(Build.Repository.LocalPath)/.ci/run/mysql/mysqld.sock'
TF_BUILD: $(TF_BUILD)
- task: PublishTestResults@2
condition: always()
Expand Down
9 changes: 2 additions & 7 deletions .ci/use-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cd $(dirname $0)/config

display_usage() {
echo -e "\nUsage:\n$0 [config.json script] [host] [port] [name] [features]\n"
echo -e "\nUsage:\n$0 [config.json script] [host] [port] [features]\n"
}

# check whether user had supplied -h or --help . If yes display usage
Expand Down Expand Up @@ -40,10 +40,5 @@ fi

if [ $# -ge 4 ]
then
sed -i "s/run\/mysql/run\/$4/g" ../../tests/SideBySide/config.json
fi

if [ $# -ge 5 ]
then
sed -i "s/\"UnsupportedFeatures\": \".*\"/\"UnsupportedFeatures\": \"$5\"/g" ../../tests/SideBySide/config.json
sed -i "s/\"UnsupportedFeatures\": \".*\"/\"UnsupportedFeatures\": \"$4\"/g" ../../tests/SideBySide/config.json
fi
24 changes: 8 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,22 @@ services: docker

env:
- IMAGE=mysql:5.6
NAME=mysql
OMIT_FEATURES=Ed25519,Json,Sha256Password,RsaEncryption,LargePackets,CachingSha2Password,SessionTrack,Tls11,Tls12,UuidToBin
- IMAGE=mysql:5.7
NAME=mysql
OMIT_FEATURES=Ed25519,RsaEncryption,CachingSha2Password,Tls12,UuidToBin
- IMAGE=mysql:8.0
NAME=mysql
OMIT_FEATURES=Ed25519
- IMAGE=percona:5.7.22
NAME=percona
OMIT_FEATURES=CachingSha2Password,Ed25519,UuidToBin
- IMAGE=mariadb:10.2
NAME=mariadb
OMIT_FEATURES=Ed25519,Json,Sha256Password,CachingSha2Password,RoundDateTime,UuidToBin
- IMAGE=mariadb:10.3
NAME=mariadb
OMIT_FEATURES=Ed25519,Json,Sha256Password,CachingSha2Password,RoundDateTime,UuidToBin
- IMAGE=mariadb:10.4
NAME=mariadb
OMIT_FEATURES=Json,Sha256Password,CachingSha2Password,RoundDateTime,UuidToBin

before_install:
- .ci/docker-run.sh $IMAGE $NAME 3307 $OMIT_FEATURES
- .ci/docker-run.sh $IMAGE 3307 $OMIT_FEATURES
- sudo apt-get install -y libunwind8
- mkdir -p $HOME/dotnet
- wget -q https://download.visualstudio.microsoft.com/download/pr/14b65ed5-f508-49c4-b429-1b22085895cf/a6820dabd3a0303135fe11217405bfd1/dotnet-ubuntu.16.04-x64.1.1.13.tar.gz
Expand All @@ -47,14 +40,13 @@ script:
- pushd tests/Conformance.Tests && CONNECTION_STRING="Server=localhost;Port=3307;User Id=mysqltest;Password=test;SSL Mode=None" dotnet test -c Release && popd
- pushd tests/SideBySide
- dotnet build SideBySide.csproj -c Release -f netcoreapp2.0
- echo 'Executing netcoreapp1.1.2 tests with No Compression, No SSL' && ../../.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp1.1.2
- echo 'Executing netcoreapp2.0 tests with No Compression, No SSL' && ../../.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.0
- echo 'Executing netcoreapp2.1 tests with No Compression, No SSL' && ../../.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.1
- echo 'Executing netcoreapp2.1 tests with Compression, No SSL' && ../../.ci/use-config.sh config.compression.json 172.17.0.1 3307 $NAME $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.1
- echo 'Executing netcoreapp1.1.2 tests with No Compression, SSL' && ../../.ci/use-config.sh config.ssl.json 172.17.0.1 3307 $NAME $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp1.1.2
- echo 'Executing netcoreapp2.1 tests with No Compression, SSL' && ../../.ci/use-config.sh config.ssl.json 172.17.0.1 3307 $NAME $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.1
- echo 'Executing netcoreapp2.0 tests with Compression, SSL' && ../../.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 $NAME $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.0
- echo 'Executing netcoreapp2.0 tests with Unix Domain Socket, No Compression, No SSL' && ../../.ci/use-config.sh config.uds.json 172.17.0.1 3307 $NAME $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.0
- echo 'Executing netcoreapp1.1.2 tests with No Compression, No SSL' && ../../.ci/use-config.sh config.json 172.17.0.1 3307 $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp1.1.2
- echo 'Executing netcoreapp2.0 tests with No Compression, No SSL' && ../../.ci/use-config.sh config.json 172.17.0.1 3307 $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.0
- echo 'Executing netcoreapp2.1 tests with No Compression, No SSL' && ../../.ci/use-config.sh config.json 172.17.0.1 3307 $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.1
- echo 'Executing netcoreapp2.1 tests with Compression, No SSL' && ../../.ci/use-config.sh config.compression.json 172.17.0.1 3307 $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.1
- echo 'Executing netcoreapp1.1.2 tests with No Compression, SSL' && ../../.ci/use-config.sh config.ssl.json 172.17.0.1 3307 $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp1.1.2
- echo 'Executing netcoreapp2.1 tests with No Compression, SSL' && ../../.ci/use-config.sh config.ssl.json 172.17.0.1 3307 $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.1
- echo 'Executing netcoreapp2.0 tests with Compression, SSL' && ../../.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 $OMIT_FEATURES && time dotnet test -c Release -f netcoreapp2.0
- popd

notifications:
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
command: 'test'
arguments: 'tests\SideBySide\SideBySide.csproj -c Baseline --logger'
env:
DATA__UNSUPPORTEDFEATURES: 'Ed25519'
DATA__UNSUPPORTEDFEATURES: 'Ed25519,UnixDomainSocket'
DATA__CONNECTIONSTRING: 'server=localhost;port=3306;user id=root;password=test;database=mysqltest;ssl mode=none;DefaultCommandTimeout=3600'
DATA__CERTIFICATESPATH: '$(Build.Repository.LocalPath)\.ci\server\certs\'
DATA__MYSQLBULKLOADERLOCALCSVFILE: '$(Build.Repository.LocalPath)\tests\TestData\LoadData_UTF8_BOM_Unix.CSV'
Expand Down
2 changes: 2 additions & 0 deletions tests/SideBySide/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ private static IConfiguration BuildConfiguration()

public static string SecondaryDatabase => Config.GetValue<string>("Data:SecondaryDatabase");

public static string SocketPath => Config.GetValue<string>("Data:SocketPath");

private static ServerFeatures UnsupportedFeatures => (ServerFeatures) Enum.Parse(typeof(ServerFeatures), Config.GetValue<string>("Data:UnsupportedFeatures"));

public static ServerFeatures SupportedFeatures => ~ServerFeatures.None & ~UnsupportedFeatures & ~(IsCiBuild ? ServerFeatures.Timeout : ServerFeatures.None);
Expand Down
11 changes: 11 additions & 0 deletions tests/SideBySide/ConnectAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,17 @@ public async Task PingConnection()
}
#endif

[SkippableFact(ServerFeatures.UnixDomainSocket)]
public async Task UnixDomainSocket()
{
var csb = AppConfig.CreateConnectionStringBuilder();
csb.Server = AppConfig.SocketPath;
csb.ConnectionProtocol = MySqlConnectionProtocol.Unix;
using var connection = new MySqlConnection(csb.ConnectionString);
await connection.OpenAsync();
Assert.Equal(ConnectionState.Open, connection.State);
}

readonly DatabaseFixture m_database;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/SideBySide/ConnectSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ public void PingConnection()
Assert.True(connection.Ping());
}

[SkippableFact(ServerFeatures.UnixDomainSocket)]
public void UnixDomainSocket()
{
var csb = AppConfig.CreateConnectionStringBuilder();
csb.Server = AppConfig.SocketPath;
csb.ConnectionProtocol = MySqlConnectionProtocol.Unix;
using var connection = new MySqlConnection(csb.ConnectionString);
connection.Open();
Assert.Equal(ConnectionState.Open, connection.State);
}

readonly DatabaseFixture m_database;
}
}
31 changes: 16 additions & 15 deletions tests/SideBySide/ServerFeatures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ namespace SideBySide
public enum ServerFeatures
{
None = 0,
Json = 1,
StoredProcedures = 2,
Sha256Password = 4,
RsaEncryption = 8,
LargePackets = 16,
CachingSha2Password = 32,
SessionTrack = 64,
Timeout = 128,
ErrorCodes = 256,
KnownCertificateAuthority = 512,
Tls11 = 1024,
Tls12 = 2048,
RoundDateTime = 4096,
UuidToBin = 8192,
Ed25519 = 16384,
Json = 0x1,
StoredProcedures = 0x2,
Sha256Password = 0x4,
RsaEncryption = 0x8,
LargePackets = 0x10,
CachingSha2Password = 0x20,
SessionTrack = 0x40,
Timeout = 0x80,
ErrorCodes = 0x100,
KnownCertificateAuthority = 0x200,
Tls11 = 0x400,
Tls12 = 0x800,
RoundDateTime = 0x1000,
UuidToBin = 0x2000,
Ed25519 = 0x4000,
UnixDomainSocket = 0x8000,
}
}

0 comments on commit 7b62c79

Please sign in to comment.