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