at 21.11-pre 7.0 kB view raw
1import ./../make-test-python.nix ({ pkgs, ...} : { 2 name = "mysql"; 3 meta = with pkgs.lib.maintainers; { 4 maintainers = [ eelco shlevy ]; 5 }; 6 7 nodes = { 8 mysql57 = 9 { pkgs, ... }: 10 11 { 12 users.users.testuser = { isSystemUser = true; }; 13 users.users.testuser2 = { isSystemUser = true; }; 14 services.mysql.enable = true; 15 services.mysql.initialDatabases = [ 16 { name = "testdb3"; schema = ./testdb.sql; } 17 ]; 18 # note that using pkgs.writeText here is generally not a good idea, 19 # as it will store the password in world-readable /nix/store ;) 20 services.mysql.initialScript = pkgs.writeText "mysql-init.sql" '' 21 CREATE USER 'testuser3'@'localhost' IDENTIFIED BY 'secure'; 22 GRANT ALL PRIVILEGES ON testdb3.* TO 'testuser3'@'localhost'; 23 ''; 24 services.mysql.ensureDatabases = [ "testdb" "testdb2" ]; 25 services.mysql.ensureUsers = [{ 26 name = "testuser"; 27 ensurePermissions = { 28 "testdb.*" = "ALL PRIVILEGES"; 29 }; 30 } { 31 name = "testuser2"; 32 ensurePermissions = { 33 "testdb2.*" = "ALL PRIVILEGES"; 34 }; 35 }]; 36 services.mysql.package = pkgs.mysql57; 37 }; 38 39 mysql80 = 40 { pkgs, ... }: 41 42 { 43 # prevent oom: 44 # Kernel panic - not syncing: Out of memory: compulsory panic_on_oom is enabled 45 virtualisation.memorySize = 1024; 46 47 users.users.testuser = { isSystemUser = true; }; 48 users.users.testuser2 = { isSystemUser = true; }; 49 services.mysql.enable = true; 50 services.mysql.initialDatabases = [ 51 { name = "testdb3"; schema = ./testdb.sql; } 52 ]; 53 # note that using pkgs.writeText here is generally not a good idea, 54 # as it will store the password in world-readable /nix/store ;) 55 services.mysql.initialScript = pkgs.writeText "mysql-init.sql" '' 56 CREATE USER 'testuser3'@'localhost' IDENTIFIED BY 'secure'; 57 GRANT ALL PRIVILEGES ON testdb3.* TO 'testuser3'@'localhost'; 58 ''; 59 services.mysql.ensureDatabases = [ "testdb" "testdb2" ]; 60 services.mysql.ensureUsers = [{ 61 name = "testuser"; 62 ensurePermissions = { 63 "testdb.*" = "ALL PRIVILEGES"; 64 }; 65 } { 66 name = "testuser2"; 67 ensurePermissions = { 68 "testdb2.*" = "ALL PRIVILEGES"; 69 }; 70 }]; 71 services.mysql.package = pkgs.mysql80; 72 }; 73 74 mariadb = 75 { pkgs, ... }: 76 77 { 78 users.users.testuser = { isSystemUser = true; }; 79 users.users.testuser2 = { isSystemUser = true; }; 80 services.mysql.enable = true; 81 services.mysql.initialScript = pkgs.writeText "mariadb-init.sql" '' 82 ALTER USER root@localhost IDENTIFIED WITH unix_socket; 83 DELETE FROM mysql.user WHERE password = ''' AND plugin = '''; 84 DELETE FROM mysql.user WHERE user = '''; 85 FLUSH PRIVILEGES; 86 ''; 87 services.mysql.ensureDatabases = [ "testdb" "testdb2" ]; 88 services.mysql.ensureUsers = [{ 89 name = "testuser"; 90 ensurePermissions = { 91 "testdb.*" = "ALL PRIVILEGES"; 92 }; 93 } { 94 name = "testuser2"; 95 ensurePermissions = { 96 "testdb2.*" = "ALL PRIVILEGES"; 97 }; 98 }]; 99 services.mysql.settings = { 100 mysqld = { 101 plugin-load-add = [ "ha_rocksdb.so" ]; 102 }; 103 }; 104 services.mysql.package = pkgs.mariadb; 105 }; 106 107 }; 108 109 testScript = '' 110 start_all() 111 112 mysql57.wait_for_unit("mysql") 113 mysql57.succeed( 114 "echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser" 115 ) 116 mysql57.succeed( 117 "echo 'use testdb; insert into tests values (41);' | sudo -u testuser mysql -u testuser" 118 ) 119 # Ensure testuser2 is not able to insert into testdb as mysql testuser2 120 mysql57.fail( 121 "echo 'use testdb; insert into tests values (22);' | sudo -u testuser2 mysql -u testuser2" 122 ) 123 # Ensure testuser2 is not able to authenticate as mysql testuser 124 mysql57.fail( 125 "echo 'use testdb; insert into tests values (22);' | sudo -u testuser2 mysql -u testuser" 126 ) 127 mysql57.succeed( 128 "echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 41" 129 ) 130 mysql57.succeed( 131 "echo 'use testdb3; select * from tests;' | mysql -u testuser3 --password=secure -N | grep 4" 132 ) 133 134 mysql80.wait_for_unit("mysql") 135 mysql80.succeed( 136 "echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser" 137 ) 138 mysql80.succeed( 139 "echo 'use testdb; insert into tests values (41);' | sudo -u testuser mysql -u testuser" 140 ) 141 # Ensure testuser2 is not able to insert into testdb as mysql testuser2 142 mysql80.fail( 143 "echo 'use testdb; insert into tests values (22);' | sudo -u testuser2 mysql -u testuser2" 144 ) 145 # Ensure testuser2 is not able to authenticate as mysql testuser 146 mysql80.fail( 147 "echo 'use testdb; insert into tests values (22);' | sudo -u testuser2 mysql -u testuser" 148 ) 149 mysql80.succeed( 150 "echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 41" 151 ) 152 mysql80.succeed( 153 "echo 'use testdb3; select * from tests;' | mysql -u testuser3 --password=secure -N | grep 4" 154 ) 155 156 mariadb.wait_for_unit("mysql") 157 mariadb.succeed( 158 "echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser" 159 ) 160 mariadb.succeed( 161 "echo 'use testdb; insert into tests values (42);' | sudo -u testuser mysql -u testuser" 162 ) 163 # Ensure testuser2 is not able to insert into testdb as mysql testuser2 164 mariadb.fail( 165 "echo 'use testdb; insert into tests values (23);' | sudo -u testuser2 mysql -u testuser2" 166 ) 167 # Ensure testuser2 is not able to authenticate as mysql testuser 168 mariadb.fail( 169 "echo 'use testdb; insert into tests values (23);' | sudo -u testuser2 mysql -u testuser" 170 ) 171 mariadb.succeed( 172 "echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 42" 173 ) 174 175 # Check if RocksDB plugin works 176 mariadb.succeed( 177 "echo 'use testdb; create table rocksdb (test_id INT, PRIMARY KEY (test_id)) ENGINE = RocksDB;' | sudo -u testuser mysql -u testuser" 178 ) 179 mariadb.succeed( 180 "echo 'use testdb; insert into rocksdb values (28);' | sudo -u testuser mysql -u testuser" 181 ) 182 mariadb.succeed( 183 "echo 'use testdb; select test_id from rocksdb;' | sudo -u testuser mysql -u testuser -N | grep 28" 184 ) 185 mariadb.succeed( 186 "echo 'use testdb; drop table rocksdb;' | sudo -u testuser mysql -u testuser" 187 ) 188 ''; 189})