Skip to content

Commit

Permalink
Travis and Appveyor integration:
Browse files Browse the repository at this point in the history
  - added travis support
  - fixed appveyor settings
  - fixed some warnings (gcc 4.8)
  - removed sleep commands
  - disabled failing tests when running against MySQL server,
    mostly related to stored procedures and binary protocol
  - reverted fix for MDEV_10361

Still open: TLS/SSL appveyor tests, since .msi installation on appveyor doesn't provide certificates.
  • Loading branch information
9EOR9 committed Feb 16, 2018
1 parent da9ed3c commit 9296149
Show file tree
Hide file tree
Showing 23 changed files with 549 additions and 131 deletions.
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
sudo: true
language: c
services: docker
addons:
hosts:
- mariadb.example.com

before_script:
# Disable services enabled by default
- sudo /etc/init.d/mysql stop


before_install:
- chmod +x .travis/script.sh
- chmod +x .travis/gen-ssl.sh
- export PROJ_PATH=`pwd`
- export ENTRYPOINT=$PROJ_PATH/.travis/sql
- mkdir tmp
- .travis/gen-ssl.sh mariadb.example.com tmp
- export SSLCERT=$PROJ_PATH/tmp

env:
- DB=mysql:5.7
- DB=mariadb:5.5
- DB=mariadb:10.0
- DB=mariadb:10.1
- DB=mariadb:10.2
- DB=mariadb:10.3

script: .travis/script.sh
13 changes: 13 additions & 0 deletions .travis/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '2'
services:
db:
image: $DB
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key --bind-address=0.0.0.0
ports:
- 3305:3306
volumes:
- $SSLCERT:/etc/sslcert
- $ENTRYPOINT:/docker-entrypoint-initdb.d
environment:
MYSQL_DATABASE: test
MYSQL_ALLOW_EMPTY_PASSWORD: 1
155 changes: 155 additions & 0 deletions .travis/gen-ssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/bin/bash
set -e

log () {
echo "$@" 1>&2
}

print_error () {
echo "$@" 1>&2
exit 1
}

print_usage () {
print_error "Usage: gen-ssl-cert-key <fqdn> <output-dir>"
}

gen_cert_subject () {
local fqdn="$1"
[[ "${fqdn}" != "" ]] || print_error "FQDN cannot be blank"
echo "/C=/ST=/O=/localityName=/CN=${fqdn}/organizationalUnitName=/emailAddress=/"
}

main () {
local fqdn="$1"
local sslDir="$2"
[[ "${fqdn}" != "" ]] || print_usage
[[ -d "${sslDir}" ]] || print_error "Directory does not exist: ${sslDir}"

local caCertFile="${sslDir}/ca.crt"
local caKeyFile="${sslDir}/ca.key"
local certFile="${sslDir}/server.crt"
local certShaFile="${sslDir}/server-cert.sha1"
local keyFile="${sslDir}/server.key"
local csrFile=$(mktemp)
local clientCertFile="${sslDir}/client-cert.pem"
local clientKeyFile="${sslDir}/client-key.pem"
local clientEncryptedKeyFile="${sslDir}/client-key-enc.pem"
local clientKeystoreFile="${sslDir}/client-keystore.jks"
local fullClientKeystoreFile="${sslDir}/fullclient-keystore.jks"
local tmpKeystoreFile=$(mktemp)
local pcks12FullKeystoreFile="${sslDir}/fullclient-keystore.p12"
local clientReqFile=$(mktemp)

log "Generating CA key"
openssl genrsa -out "${caKeyFile}" 2048

log "Generating CA certificate"
openssl req \
-sha1 \
-new \
-x509 \
-nodes \
-days 3650 \
-subj "$(gen_cert_subject ca.example.com)" \
-key "${caKeyFile}" \
-out "${caCertFile}"

log "Generating private key"
openssl genrsa -out "${keyFile}" 2048

log "Generating certificate signing request"
openssl req \
-new \
-batch \
-sha1 \
-subj "$(gen_cert_subject "$fqdn")" \
-set_serial 01 \
-key "${keyFile}" \
-out "${csrFile}" \
-nodes

log "Generating X509 certificate"
openssl x509 \
-req \
-sha1 \
-set_serial 01 \
-CA "${caCertFile}" \
-CAkey "${caKeyFile}" \
-days 3650 \
-in "${csrFile}" \
-signkey "${keyFile}" \
-out "${certFile}"

log "Generating client certificate"
openssl req \
-batch \
-newkey rsa:2048 \
-days 3600 \
-subj "$(gen_cert_subject "$fqdn")" \
-nodes \
-keyout "${clientKeyFile}" \
-out "${clientReqFile}"

log "Generating password protected client key file"
openssl rsa \
-aes256 \
-in "${clientKeyFile}" \
-out "${clientEncryptedKeyFile}" \
-passout pass:qwerty

log "Generating finger print of server certificate"
openssl x509 \
-noout \
-fingerprint \
-sha1 \
-inform pem \
-in "${certFile}" | \
sed -e "s/SHA1 Fingerprint=//g" \
> "${certShaFile}"

log "copy ca file"
cp "${caCertFile}" "${sslDir}/cacert.pem"

openssl x509 \
-req \
-in "${clientReqFile}" \
-days 3600 \
-CA "${caCertFile}" \
-CAkey "${caKeyFile}" \
-set_serial 01 \
-out "${clientCertFile}"

# Now generate a keystore with the client cert & key
log "Generating client keystore"
openssl pkcs12 \
-export \
-in "${clientCertFile}" \
-inkey "${clientKeyFile}" \
-out "${tmpKeystoreFile}" \
-name "mysqlAlias" \
-passout pass:kspass


# Now generate a full keystore with the client cert & key + trust certificates
log "Generating full client keystore"
openssl pkcs12 \
-export \
-in "${clientCertFile}" \
-inkey "${clientKeyFile}" \
-out "${pcks12FullKeystoreFile}" \
-name "mysqlAlias" \
-passout pass:kspass


# Clean up CSR file:
rm "$csrFile"
rm "$clientReqFile"
rm "$tmpKeystoreFile"

log "Generated key file and certificate in: ${sslDir}"
ls -l "${sslDir}"
}

main "$@"

67 changes: 67 additions & 0 deletions .travis/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

set -x
set -e

###################################################################################################################
# test different type of configuration
###################################################################################################################
mysql=( mysql --protocol=tcp -ubob -h127.0.0.1 --port=3305 )
export COMPOSE_FILE=.travis/docker-compose.yml


###################################################################################################################
# launch docker server and maxscale
###################################################################################################################
export INNODB_LOG_FILE_SIZE=$(echo ${PACKET}| cut -d'M' -f 1)0M
docker-compose -f ${COMPOSE_FILE} build
docker-compose -f ${COMPOSE_FILE} up -d


###################################################################################################################
# wait for docker initialisation
###################################################################################################################

for i in {60..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
break
fi
echo 'data server still not active'
sleep 1
done

docker-compose -f ${COMPOSE_FILE} logs

if [ "$i" = 0 ]; then
echo 'SELECT 1' | "${mysql[@]}"
echo >&2 'data server init process failed.'
exit 1
fi

#list ssl certificates
ls -lrt ${SSLCERT}


#build C connector
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_SSL=OPENSSL -DCERT_PATH=${SSLCERT}
make

export MYSQL_TEST_HOST=mariadb.example.com
export MYSQL_TEST_DB=ctest
export MYSQL_TEST_USER=bob
export MYSQL_TEST_PORT=3305
export MYSQL_TEST_TRAVIS=1
export MARIADB_PLUGIN_DIR=$PWD/plugins/lib

## list ciphers
openssl ciphers -v

###################################################################################################################
# run test suite
###################################################################################################################
echo "Running tests"

cd unittest/libmariadb

ctest -V

6 changes: 6 additions & 0 deletions .travis/sql/dbinit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE USER 'bob'@'%';
GRANT ALL ON *.* TO 'bob'@'%' with grant option;

FLUSH PRIVILEGES;

CREATE DATABASE ctest;
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SET(CC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

SET(CPACK_PACKAGE_VERSION_MAJOR 3)
SET(CPACK_PACKAGE_VERSION_MINOR 0)
SET(CPACK_PACKAGE_VERSION_PATCH 2)
SET(CPACK_PACKAGE_VERSION_PATCH 4)
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
MATH(EXPR MARIADB_PACKAGE_VERSION_ID "${CPACK_PACKAGE_VERSION_MAJOR} * 10000 +
${CPACK_PACKAGE_VERSION_MINOR} * 100 +
Expand Down
60 changes: 42 additions & 18 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
version: 3.0.0.{build}
version: 3.0.4;{build}
branches:
only:
- master
os: Visual Studio 2015
configuration: RelWithDebInfo
platform: x64
clone_folder: c:\projects\mariadb-connector-c
environment:
MYSQL_TEST_USER: root
MYSQL_TEST_HOST: 127.0.0.1
MYSQL_TEST_PASSWD: Password12!
services: mysql56
before_build:
- ps: >-
cd c:\projects\mariadb-connector-c
matrix:
- DB: '10.2.12'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
- DB: '10.2.12'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_PARAM: 'Visual Studio 14 2015 Win64'
- DB: '10.2.12'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017'
- DB: '10.2.12'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_PARAM: 'Visual Studio 14 2015'
- DB: '10.3.4'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
- DB: '10.1.30'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
- DB: '10.0.33'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
- DB: '5.5.59'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'

echo running cmake

cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=RelWithDebInfo
configuration: RelWithDebInfo
clone_folder: c:\projects\mariadb-connector-c
before_build:
- cmd: set MYSQL_TEST_USER=root
- cmd: set MYSQL_TEST_HOST=127.0.0.1
- cmd: set MYSQL_TEST_PASSWD=
- cmd: set MYSQL_TEST_PORT=3306
- cmd: set MYSQL_TEST_DB=testc
- cmd: set FILE=http://mariadb.mirrors.ovh.net/MariaDB/mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi
- ps: Start-FileDownload $Env:FILE -FileName server.msi
- cmd: msiexec /i server.msi INSTALLDIR=c:\projects\server SERVICENAME=mariadb ALLOWREMOTEROOTACCESS=true /qn
- cmd: "\"c:\\projects\\server\\bin\\mysql.exe\" -e \"create database testc\" --user=root"
- cmd: cmake -G "%CMAKE_PARAM%" -DCMAKE_BUILD_TYPE=RelWithDebInfo
build:
project: mariadb-connector-c.sln
parallel: true
verbosity: minimal
test_script:
- cmd: >-
cd c:\projects\mariadb-connector-c\unittest\libmariadb
ctest -V
- cmd: cd c:\projects\mariadb-connector-c\unittest\libmariadb
- cmd: set MARIADB_PLUGIN_DIR=cd c:\projects\mariadb-connector-c\plugins\lib\RelWithDebInfo
- cmd: ctest -V
6 changes: 5 additions & 1 deletion libmariadb/mariadb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,11 @@ mysql_stat(MYSQL *mysql)
int STDCALL
mysql_ping(MYSQL *mysql)
{
return ma_simple_command(mysql, COM_PING,0,0,0,0);
int rc;
rc= ma_simple_command(mysql, COM_PING, 0, 0, 0, 0);
if (rc && mysql_errno(mysql) == CR_SERVER_LOST)
rc= ma_simple_command(mysql, COM_PING, 0, 0, 0, 0);
return rc;
}

char * STDCALL
Expand Down
13 changes: 9 additions & 4 deletions libmariadb/mariadb_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,15 @@ void mthd_stmt_flush_unbuffered(MYSQL_STMT *stmt)
}
if (packet_len < 8 && *pos == 254) /* EOF */
{
stmt->mysql->server_status= uint2korr(pos + 3);
if (in_resultset)
if (mariadb_connection(stmt->mysql))
{
stmt->mysql->server_status= uint2korr(pos + 3);
if (in_resultset)
goto end;
in_resultset= 1;
}
else
goto end;
in_resultset= 1;
}
}
end:
Expand Down Expand Up @@ -2279,7 +2284,7 @@ int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt)
}

if (stmt->mysql->status == MYSQL_STATUS_GET_RESULT)
stmt->mysql->status= MYSQL_STATUS_STMT_RESULT;
stmt->mysql->status= MYSQL_STATUS_STMT_RESULT;

if (stmt->mysql->field_count)
rc= madb_alloc_stmt_fields(stmt);
Expand Down
Loading

0 comments on commit 9296149

Please sign in to comment.