about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2020-01-02 21:30:55 +0100
committerGitHub <noreply@github.com>2020-01-02 21:30:55 +0100
commit03212a7f0324598c578485c16d53224c2fd4e60b (patch)
tree73114e08d5366f9b74761104144a72b5f7ea234b /nixos
parent0e31950cb41167553e74b98de8ba8c32b11c2449 (diff)
parentbf7841aae18eb113c2439d439a28747bbec26ee0 (diff)
downloadnixlib-03212a7f0324598c578485c16d53224c2fd4e60b.tar
nixlib-03212a7f0324598c578485c16d53224c2fd4e60b.tar.gz
nixlib-03212a7f0324598c578485c16d53224c2fd4e60b.tar.bz2
nixlib-03212a7f0324598c578485c16d53224c2fd4e60b.tar.lz
nixlib-03212a7f0324598c578485c16d53224c2fd4e60b.tar.xz
nixlib-03212a7f0324598c578485c16d53224c2fd4e60b.tar.zst
nixlib-03212a7f0324598c578485c16d53224c2fd4e60b.zip
Merge pull request #76606 from flokli/mysql-tests
nixosTests.mysql: add more tests
Diffstat (limited to 'nixos')
-rw-r--r--nixos/tests/mysql.nix18
1 files changed, 16 insertions, 2 deletions
diff --git a/nixos/tests/mysql.nix b/nixos/tests/mysql.nix
index 2c0d212c2f1d..924bac84e26c 100644
--- a/nixos/tests/mysql.nix
+++ b/nixos/tests/mysql.nix
@@ -27,6 +27,7 @@ import ./make-test-python.nix ({ pkgs, ...} : {
 
       {
         users.users.testuser = { };
+        users.users.testuser2 = { };
         services.mysql.enable = true;
         services.mysql.initialScript = pkgs.writeText "mariadb-init.sql" ''
           ALTER USER root@localhost IDENTIFIED WITH unix_socket;
@@ -34,12 +35,17 @@ import ./make-test-python.nix ({ pkgs, ...} : {
           DELETE FROM mysql.user WHERE user = ''';
           FLUSH PRIVILEGES;
         '';
-        services.mysql.ensureDatabases = [ "testdb" ];
+        services.mysql.ensureDatabases = [ "testdb" "testdb2" ];
         services.mysql.ensureUsers = [{
           name = "testuser";
           ensurePermissions = {
             "testdb.*" = "ALL PRIVILEGES";
           };
+        } {
+          name = "testuser2";
+          ensurePermissions = {
+            "testdb2.*" = "ALL PRIVILEGES";
+          };
         }];
         services.mysql.package = pkgs.mariadb;
       };
@@ -47,7 +53,7 @@ import ./make-test-python.nix ({ pkgs, ...} : {
   };
 
   testScript = ''
-    start_all
+    start_all()
 
     mysql.wait_for_unit("mysql")
     mysql.succeed("echo 'use empty_testdb;' | mysql -u root")
@@ -62,6 +68,14 @@ import ./make-test-python.nix ({ pkgs, ...} : {
     mariadb.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
+    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(
         "echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 42"
     )