From 2e304d693460cf338103fd644bc488a18dd51c59 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 23 Sep 2019 18:38:02 +0200 Subject: [PATCH] test stuff --- test/bs.sql | 13 ++++++++++ test/dotnet/DatabaseTest.csproj | 14 ++++++++++ test/dotnet/Program.cs | 46 +++++++++++++++++++++++++++++++++ test/startEnv.sh | 21 +++++++++++++++ test/startLdapServer.sh | 0 5 files changed, 94 insertions(+) create mode 100644 test/bs.sql create mode 100644 test/dotnet/DatabaseTest.csproj create mode 100644 test/dotnet/Program.cs create mode 100755 test/startEnv.sh mode change 100644 => 100755 test/startLdapServer.sh diff --git a/test/bs.sql b/test/bs.sql new file mode 100644 index 0000000..d3b1b32 --- /dev/null +++ b/test/bs.sql @@ -0,0 +1,13 @@ +create user 'testuser'@'%' identified via pam using 'mariadb'; +create database testdb; +grant all privileges on testdb.* to 'testuser'@'%'; +flush privileges; + +use testdb; +create table testtable ( + id int primary key auto_increment, + bla varchar(32) +); +insert into testtable (bla) values('bla1'); +insert into testtable (bla) values('bla2'); +insert into testtable (bla) values('bla3'); diff --git a/test/dotnet/DatabaseTest.csproj b/test/dotnet/DatabaseTest.csproj new file mode 100644 index 0000000..ac408cc --- /dev/null +++ b/test/dotnet/DatabaseTest.csproj @@ -0,0 +1,14 @@ + + + + Exe + netcoreapp2.2 + + DatabaseTest.Program + + + + + + + diff --git a/test/dotnet/Program.cs b/test/dotnet/Program.cs new file mode 100644 index 0000000..19a68c1 --- /dev/null +++ b/test/dotnet/Program.cs @@ -0,0 +1,46 @@ +using MySql.Data.MySqlClient; +using System; +using System.Data; + +namespace DatabaseTest +{ + class Program + { + private const string SERVER_ADDRESS = "127.0.0.1"; + private const string SERVER_PORT = "3306"; + private const string DATABASE_NAME = "testdb"; + private const string USERNAME = "testuser"; + private const string PASSWORD = "test123"; + + + static void Main(string[] args) + { + string connectionStr = $"Server={SERVER_ADDRESS};Port={SERVER_PORT};Database={DATABASE_NAME};Uid={USERNAME};Pwd={PASSWORD}"; + + MySqlConnection con = new MySqlConnection(); + con.ConnectionString = connectionStr; + + try + { + con.Open(); + + MySqlCommand cmd = con.CreateCommand(); + cmd.CommandText = "SELECT * FROM testtable"; + var reader = cmd.ExecuteReader(); + DataTable dt = new DataTable(); + dt.Load(reader); + + con.Close(); + } + catch (MySqlException sqlEx) + { + Console.WriteLine(sqlEx.Message); + Console.WriteLine(); + Console.WriteLine(sqlEx.InnerException?.Message); + } + + Console.WriteLine("Press any key to close."); + Console.ReadKey(); + } + } +} diff --git a/test/startEnv.sh b/test/startEnv.sh new file mode 100755 index 0000000..e99abbe --- /dev/null +++ b/test/startEnv.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +echo "Starting LDAP server" +docker run --name ldapserver --rm -d -p 389:389 osixia/openldap:1.2.5 + +echo "Wait until it settled" +sleep 10 + +echo "Load LDAP server" +cat bs.ldif | docker exec -i ldapserver ldapadd -x -H ldap://localhost -D "cn=admin,dc=example,dc=org" -w admin + + +echo "Start database server" +docker run -d --rm -e MYSQL_ROOT_PASSWORD=test123 -p 3306:3306 --name mariadb --link ldapserver registry.gitlab.com/wolutator/mariadb-with-ldap-pam:TEST-0.2-10.4 + +echo "Wait until it settled" +sleep 60 + +echo "Load database server" +cat bs.sql | docker exec -i mariadb mysql -h 127.0.0.1 -u root --password=test123 mysql + diff --git a/test/startLdapServer.sh b/test/startLdapServer.sh old mode 100644 new mode 100755