2022-01-23 02:10:13 +00:00
|
|
|
{
|
|
|
|
system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../../.. { inherit system config; },
|
|
|
|
lib ? pkgs.lib
|
|
|
|
}:
|
2021-09-22 15:38:15 +00:00
|
|
|
|
|
|
|
let
|
2023-11-16 04:20:00 +00:00
|
|
|
inherit (import ./common.nix { inherit pkgs lib; }) mkTestName mariadbPackages mysqlPackages perconaPackages;
|
2021-09-22 15:38:15 +00:00
|
|
|
|
2022-01-23 02:10:13 +00:00
|
|
|
makeTest = import ./../make-test-python.nix;
|
|
|
|
# Setup common users
|
|
|
|
makeMySQLTest = {
|
|
|
|
package,
|
|
|
|
name ? mkTestName package,
|
|
|
|
useSocketAuth ? true,
|
|
|
|
hasMroonga ? true,
|
2023-05-24 13:37:59 +00:00
|
|
|
hasRocksDB ? pkgs.stdenv.hostPlatform.is64bit
|
2022-01-23 02:10:13 +00:00
|
|
|
}: makeTest {
|
|
|
|
inherit name;
|
2024-01-02 11:29:13 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = lib.teams.helsinki-systems.members;
|
2021-09-22 15:38:15 +00:00
|
|
|
};
|
|
|
|
|
2022-01-23 02:10:13 +00:00
|
|
|
nodes = {
|
|
|
|
${name} =
|
|
|
|
{ pkgs, ... }: {
|
2021-09-22 15:38:15 +00:00
|
|
|
|
2022-01-23 02:10:13 +00:00
|
|
|
users = {
|
|
|
|
groups.testusers = { };
|
2021-09-22 15:38:15 +00:00
|
|
|
|
2022-01-23 02:10:13 +00:00
|
|
|
users.testuser = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "testusers";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-01-23 02:10:13 +00:00
|
|
|
users.testuser2 = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "testusers";
|
|
|
|
};
|
2020-06-18 07:06:33 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-01-23 02:10:13 +00:00
|
|
|
services.mysql = {
|
|
|
|
enable = true;
|
|
|
|
initialDatabases = [
|
|
|
|
{ name = "testdb3"; schema = ./testdb.sql; }
|
|
|
|
];
|
|
|
|
# note that using pkgs.writeText here is generally not a good idea,
|
|
|
|
# as it will store the password in world-readable /nix/store ;)
|
|
|
|
initialScript = pkgs.writeText "mysql-init.sql" (if (!useSocketAuth) then ''
|
|
|
|
CREATE USER 'testuser3'@'localhost' IDENTIFIED BY 'secure';
|
|
|
|
GRANT ALL PRIVILEGES ON testdb3.* TO 'testuser3'@'localhost';
|
|
|
|
'' else ''
|
|
|
|
ALTER USER root@localhost IDENTIFIED WITH unix_socket;
|
|
|
|
DELETE FROM mysql.user WHERE password = ''' AND plugin = ''';
|
|
|
|
DELETE FROM mysql.user WHERE user = ''';
|
|
|
|
FLUSH PRIVILEGES;
|
|
|
|
'');
|
|
|
|
|
|
|
|
ensureDatabases = [ "testdb" "testdb2" ];
|
|
|
|
ensureUsers = [{
|
|
|
|
name = "testuser";
|
|
|
|
ensurePermissions = {
|
|
|
|
"testdb.*" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
} {
|
|
|
|
name = "testuser2";
|
|
|
|
ensurePermissions = {
|
|
|
|
"testdb2.*" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
package = package;
|
|
|
|
settings = {
|
|
|
|
mysqld = {
|
|
|
|
plugin-load-add = lib.optional hasMroonga "ha_mroonga.so"
|
|
|
|
++ lib.optional hasRocksDB "ha_rocksdb.so";
|
|
|
|
};
|
|
|
|
};
|
2020-06-18 07:06:33 +00:00
|
|
|
};
|
2022-01-23 02:10:13 +00:00
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-01-23 02:10:13 +00:00
|
|
|
testScript = ''
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
machine = ${name}
|
|
|
|
machine.wait_for_unit("mysql")
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; insert into tests values (42);' | sudo -u testuser mysql -u testuser"
|
|
|
|
)
|
|
|
|
# Ensure testuser2 is not able to insert into testdb as mysql testuser2
|
|
|
|
machine.fail(
|
|
|
|
"echo 'use testdb; insert into tests values (23);' | sudo -u testuser2 mysql -u testuser2"
|
|
|
|
)
|
|
|
|
# Ensure testuser2 is not able to authenticate as mysql testuser
|
|
|
|
machine.fail(
|
|
|
|
"echo 'use testdb; insert into tests values (23);' | sudo -u testuser2 mysql -u testuser"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 42"
|
|
|
|
)
|
|
|
|
|
|
|
|
${lib.optionalString hasMroonga ''
|
|
|
|
# Check if Mroonga plugin works
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; create table mroongadb (test_id INT, PRIMARY KEY (test_id)) ENGINE = Mroonga;' | sudo -u testuser mysql -u testuser"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; insert into mroongadb values (25);' | sudo -u testuser mysql -u testuser"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; select test_id from mroongadb;' | sudo -u testuser mysql -u testuser -N | grep 25"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; drop table mroongadb;' | sudo -u testuser mysql -u testuser"
|
|
|
|
)
|
|
|
|
''}
|
|
|
|
|
|
|
|
${lib.optionalString hasRocksDB ''
|
|
|
|
# Check if RocksDB plugin works
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; create table rocksdb (test_id INT, PRIMARY KEY (test_id)) ENGINE = RocksDB;' | sudo -u testuser mysql -u testuser"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; insert into rocksdb values (28);' | sudo -u testuser mysql -u testuser"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; select test_id from rocksdb;' | sudo -u testuser mysql -u testuser -N | grep 28"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"echo 'use testdb; drop table rocksdb;' | sudo -u testuser mysql -u testuser"
|
|
|
|
)
|
|
|
|
''}
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-01-23 02:10:13 +00:00
|
|
|
in
|
|
|
|
lib.mapAttrs (_: package: makeMySQLTest {
|
|
|
|
inherit package;
|
2022-02-10 20:34:41 +00:00
|
|
|
hasRocksDB = false; hasMroonga = false; useSocketAuth = false;
|
2022-01-23 02:10:13 +00:00
|
|
|
}) mysqlPackages
|
|
|
|
// (lib.mapAttrs (_: package: makeMySQLTest {
|
|
|
|
inherit package;
|
|
|
|
}) mariadbPackages)
|
2023-11-16 04:20:00 +00:00
|
|
|
// (lib.mapAttrs (_: package: makeMySQLTest {
|
|
|
|
inherit package;
|
2024-06-05 15:53:02 +00:00
|
|
|
name = builtins.replaceStrings ["-"] ["_"] package.pname;
|
2023-11-16 04:20:00 +00:00
|
|
|
hasMroonga = false; useSocketAuth = false;
|
|
|
|
}) perconaPackages)
|