Skip to content

Commit

Permalink
Merge pull request #21059 from realcharmer/ref-mysql
Browse files Browse the repository at this point in the history
Expand MariaDB test coverage
  • Loading branch information
realcharmer authored Jan 28, 2025
2 parents 5196225 + 1421993 commit 55b8c60
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions tests/security/mariadb/mariadb_ssl_client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,42 @@ sub run {
zypper_call('in mariadb');
mutex_wait('MARIADB_SERVER_READY');

# Try to connect mysql server
assert_script_run("ping -c 3 $server_ip");
validate_script_output("mysql --ssl -h $server_ip -u root -p$password -e \"show databases;\";", sub { m/Database/ });
# Run MySQL tests
perform_mariadb_test($server_ip, $password);

# Delete the ip that we added if arch is s390x
assert_script_run("ip addr del $client_ip/24 dev $netdev") if (is_s390x);
}

sub perform_mariadb_test {
my ($server_ip, $password) = @_;

# Test server connection
assert_script_run("ping -c 3 $server_ip");
validate_script_output("mysql --ssl -h $server_ip -u root -p$password -e \"show databases;\";", sub { m/Database/ });

# Validate SSL connection
validate_script_output("mysql --ssl -h $server_ip -u root -p$password -e \"SHOW STATUS LIKE 'Ssl_cipher';\";", sub { not m/DISABLED/ });

# Create new database
assert_script_run("mysql --ssl -h $server_ip -u root -p$password -e \"CREATE DATABASE test_db;\"");

# Create new user
assert_script_run("mysql --ssl -h $server_ip -u root -p$password -e \"CREATE USER 'test_user' IDENTIFIED BY 'test_password';\"");

# Grant privileges to new user
assert_script_run("mysql --ssl -h $server_ip -u root -p$password -e \"GRANT ALL PRIVILEGES ON test_db.* TO 'test_user';\"");

# Validate user permissions
assert_script_run("mysql --ssl -h $server_ip -u test_user -ptest_password -e \"USE test_db;\"");

# Test data manipulation as the new user
validate_script_output("mysql --ssl -h $server_ip -u test_user -ptest_password -e \"
CREATE TABLE test_db.test_table (id INT, value VARCHAR(255));
INSERT INTO test_db.test_table (id, value) VALUES (1, 'test_value');
SELECT * FROM test_db.test_table;
\";", sub { m/1\s+test_value/ }
);
}

1;

0 comments on commit 55b8c60

Please sign in to comment.