Merge pull request #76606 from flokli/mysql-tests

nixosTests.mysql: add more tests
This commit is contained in:
Florian Klink 2020-01-02 21:30:55 +01:00 committed by GitHub
commit 03212a7f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,7 @@ import ./make-test-python.nix ({ pkgs, ...} : {
{ {
users.users.testuser = { }; users.users.testuser = { };
users.users.testuser2 = { };
services.mysql.enable = true; services.mysql.enable = true;
services.mysql.initialScript = pkgs.writeText "mariadb-init.sql" '' services.mysql.initialScript = pkgs.writeText "mariadb-init.sql" ''
ALTER USER root@localhost IDENTIFIED WITH unix_socket; ALTER USER root@localhost IDENTIFIED WITH unix_socket;
@ -34,12 +35,17 @@ import ./make-test-python.nix ({ pkgs, ...} : {
DELETE FROM mysql.user WHERE user = '''; DELETE FROM mysql.user WHERE user = ''';
FLUSH PRIVILEGES; FLUSH PRIVILEGES;
''; '';
services.mysql.ensureDatabases = [ "testdb" ]; services.mysql.ensureDatabases = [ "testdb" "testdb2" ];
services.mysql.ensureUsers = [{ services.mysql.ensureUsers = [{
name = "testuser"; name = "testuser";
ensurePermissions = { ensurePermissions = {
"testdb.*" = "ALL PRIVILEGES"; "testdb.*" = "ALL PRIVILEGES";
}; };
} {
name = "testuser2";
ensurePermissions = {
"testdb2.*" = "ALL PRIVILEGES";
};
}]; }];
services.mysql.package = pkgs.mariadb; services.mysql.package = pkgs.mariadb;
}; };
@ -47,7 +53,7 @@ import ./make-test-python.nix ({ pkgs, ...} : {
}; };
testScript = '' testScript = ''
start_all start_all()
mysql.wait_for_unit("mysql") mysql.wait_for_unit("mysql")
mysql.succeed("echo 'use empty_testdb;' | mysql -u root") mysql.succeed("echo 'use empty_testdb;' | mysql -u root")
@ -62,6 +68,14 @@ import ./make-test-python.nix ({ pkgs, ...} : {
mariadb.succeed( mariadb.succeed(
"echo 'use testdb; insert into tests values (42);' | sudo -u testuser mysql -u testuser" "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
mariadb.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
mariadb.fail(
"echo 'use testdb; insert into tests values (23);' | sudo -u testuser2 mysql -u testuser"
)
mariadb.succeed( mariadb.succeed(
"echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 42" "echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 42"
) )