mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-13 03:10:03 -05:00
amend bats tests and entrypoint logs
This commit is contained in:
+41
-24
@@ -143,7 +143,7 @@ create_default_database_from_env() {
|
||||
password=$(get_env_var "PASSWORD")
|
||||
|
||||
if [ -n "$database" ]; then
|
||||
mysql_note "Creating database ${database}"
|
||||
mysql_note "Creating database '${database}'"
|
||||
local db_output
|
||||
if ! db_output=$(dolt sql -q "CREATE DATABASE IF NOT EXISTS \`$database\`;" 2>&1); then
|
||||
mysql_error "Failed to create database '$database'. Error: $db_output"
|
||||
@@ -167,20 +167,22 @@ EOF
|
||||
fi
|
||||
|
||||
if [ -n "$user" ]; then
|
||||
mysql_note "Creating user ${user}"
|
||||
if ! dolt sql -q "CREATE USER IF NOT EXISTS '$user'@'%' IDENTIFIED BY '$password';" 2>&1; then
|
||||
# Use the same host as the root user for consistency
|
||||
local user_host="${DOLT_ROOT_HOST:-localhost}"
|
||||
mysql_note "Creating user '${user}'"
|
||||
if ! dolt sql -q "CREATE USER IF NOT EXISTS '$user'@'$user_host' IDENTIFIED BY '$password';" >/dev/null 2>&1; then
|
||||
mysql_error "Failed to create user '$user'. Check if user already exists or if there are permission issues."
|
||||
fi
|
||||
|
||||
# Grant basic server access
|
||||
mysql_note "Granting server access to user ${user}"
|
||||
if ! dolt sql -q "GRANT USAGE ON *.* TO '$user'@'%';" 2>&1; then
|
||||
mysql_note "Granting server access to user '${user}'"
|
||||
if ! dolt sql -q "GRANT USAGE ON *.* TO '$user'@'$user_host';" >/dev/null 2>&1; then
|
||||
mysql_error "Failed to grant server access to user '$user'"
|
||||
fi
|
||||
|
||||
if [ -n "$database" ]; then
|
||||
mysql_note "Giving user ${user} access to schema ${database}"
|
||||
if ! dolt sql -q "GRANT ALL ON \`$database\`.* TO '$user'@'%';" 2>&1; then
|
||||
mysql_note "Giving user '${user}' access to schema '${database}'"
|
||||
if ! dolt sql -q "GRANT ALL ON \`$database\`.* TO '$user'@'$user_host';" >/dev/null 2>&1; then
|
||||
mysql_error "Failed to grant permissions to user '$user' on database '$database'"
|
||||
fi
|
||||
fi
|
||||
@@ -193,7 +195,7 @@ _main() {
|
||||
|
||||
local dolt_version
|
||||
dolt_version=$(dolt version | grep 'dolt version' | cut -f3 -d " ")
|
||||
mysql_note "Entrypoint script for Dolt Server $dolt_version starting."
|
||||
mysql_note "Entrypoint script for Dolt Server $dolt_version starting..."
|
||||
|
||||
declare -g CONFIG_PROVIDED
|
||||
|
||||
@@ -211,9 +213,6 @@ _main() {
|
||||
# TODO: add support for MYSQL_ROOT_HOST and MYSQL_ROOT_PASSWORD
|
||||
# Note: User creation will happen after server starts to avoid conflicts with default users
|
||||
|
||||
# If DOLT_DATABASE or MYSQL_DATABASE has been specified, create the database if it does not exist
|
||||
create_default_database_from_env
|
||||
|
||||
if [[ ! -f $INIT_COMPLETED ]]; then
|
||||
# run any file provided in /docker-entrypoint-initdb.d directory before the server starts
|
||||
if ls /docker-entrypoint-initdb.d/* >/dev/null 2>&1; then
|
||||
@@ -222,34 +221,52 @@ _main() {
|
||||
touch $INIT_COMPLETED
|
||||
fi
|
||||
|
||||
# Start the server in the background to create users
|
||||
mysql_note "Starting Dolt server in background for user creation"
|
||||
dolt sql-server --host=0.0.0.0 --port=3306 "$@" &
|
||||
# Start server in background for user setup
|
||||
mysql_note "Starting Dolt server in background..."
|
||||
dolt sql-server --host=0.0.0.0 --port=3306 "$@" > /tmp/server.log 2>&1 &
|
||||
local server_pid=$!
|
||||
|
||||
# Wait for server to be ready
|
||||
sleep 3
|
||||
local max_attempts=30
|
||||
local attempt=0
|
||||
while [ $attempt -lt $max_attempts ]; do
|
||||
if dolt sql -q "SELECT 1;" >/dev/null 2>&1; then
|
||||
mysql_note "Server initialization complete!"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
if [ $attempt -eq $max_attempts ]; then
|
||||
mysql_error "Server failed to start within 30 seconds"
|
||||
fi
|
||||
|
||||
# Create root user with the specified host (defaults to localhost if not specified)
|
||||
local root_host="${DOLT_ROOT_HOST:-localhost}"
|
||||
mysql_note "Ensuring root@${root_host} superuser exists with password"
|
||||
|
||||
# Remove existing root users to avoid conflicts
|
||||
mysql_note "Cleaning up existing root users"
|
||||
dolt sql -q "DROP USER IF EXISTS 'root'@'localhost'; DROP USER IF EXISTS 'root'@'%';" 2>&1 || mysql_warn "Could not clean up existing root users"
|
||||
# Ensure root user exists with correct password and permissions
|
||||
mysql_note "Configuring root@${root_host} user"
|
||||
dolt sql -q "CREATE USER IF NOT EXISTS 'root'@'${root_host}' IDENTIFIED BY '${DOLT_ROOT_PASSWORD}'; ALTER USER 'root'@'${root_host}' IDENTIFIED BY '${DOLT_ROOT_PASSWORD}'; GRANT ALL ON *.* TO 'root'@'${root_host}' WITH GRANT OPTION;" >/dev/null 2>&1 || mysql_error "Failed to configure root@${root_host} user. Check logs for details."
|
||||
|
||||
# Create the new root user
|
||||
dolt sql -q "CREATE USER 'root'@'${root_host}' IDENTIFIED BY '${DOLT_ROOT_PASSWORD}'; GRANT ALL ON *.* TO 'root'@'${root_host}' WITH GRANT OPTION;" 2>&1 || mysql_error "Failed to create root@${root_host} user. Check logs for details."
|
||||
# If DOLT_DATABASE or MYSQL_DATABASE has been specified, create the database if it does not exist
|
||||
create_default_database_from_env
|
||||
|
||||
# Show what users exist for debugging
|
||||
mysql_note "Current users in the system:"
|
||||
dolt sql -q "SELECT User, Host FROM mysql.user;" 2>&1 || mysql_warn "Could not list users"
|
||||
dolt sql -q "SELECT User, Host FROM mysql.user;" 2>&1 | grep -v "^$" || mysql_warn "Could not list users"
|
||||
|
||||
# Stop the background server
|
||||
# This contains the server "ready for connections" message which tests use to detect server is ready
|
||||
# We only show the logs at this stage since the users are available now for testing
|
||||
mysql_note "Reattaching to server process..."
|
||||
cat /tmp/server.log
|
||||
|
||||
# Kill the background process and restart in foreground to show live output
|
||||
kill $server_pid 2>/dev/null || true
|
||||
wait $server_pid 2>/dev/null || true
|
||||
|
||||
# switch this process over to executing dolt sql-server
|
||||
|
||||
# Start server in foreground to show live output
|
||||
exec dolt sql-server --host=0.0.0.0 --port=3306 "$@"
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
# docker/serverDockerfile in the repo root. They follow existing integration test conventions.
|
||||
|
||||
setup() {
|
||||
skiponwindows
|
||||
|
||||
setup_no_dolt_init
|
||||
|
||||
# Compute repo root from integration-tests/bats directory
|
||||
@@ -133,7 +131,7 @@ wait_for_log() {
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: reserved keyword database name support" {
|
||||
@test "docker-entrypoint: reserved keyword 'versioning' database name support" {
|
||||
cname="${TEST_PREFIX}versioning"
|
||||
kw_db="versioning"
|
||||
usr="testuser"
|
||||
@@ -202,9 +200,9 @@ wait_for_log() {
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: setup simplicity with minimal configuration" {
|
||||
@test "docker-entrypoint: setup with no configuration" {
|
||||
cname="${TEST_PREFIX}setup"
|
||||
run_container "$cname" -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=%
|
||||
run_container "$cname"
|
||||
|
||||
# Root user can execute queries immediately
|
||||
run docker exec "$cname" dolt sql -q "SHOW DATABASES;"
|
||||
@@ -216,7 +214,7 @@ wait_for_log() {
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: root user functionality and privileges" {
|
||||
@test "docker-entrypoint: root functionality and privileges" {
|
||||
cname="${TEST_PREFIX}root-fallback"
|
||||
run_container "$cname" -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=%
|
||||
|
||||
@@ -230,121 +228,6 @@ wait_for_log() {
|
||||
[ $status -eq 0 ]
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: permission validation and database operations" {
|
||||
cname="${TEST_PREFIX}perms"
|
||||
db="testdb"
|
||||
usr="testuser"
|
||||
pwd="testpass"
|
||||
|
||||
# Run container with port mapping
|
||||
run_container_with_port "$cname" 3311 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -e DOLT_DATABASE="$db" -e DOLT_USER="$usr" -e DOLT_PASSWORD="$pwd"
|
||||
|
||||
# Test that the created user can perform database operations
|
||||
run docker exec "$cname" dolt sql -q "USE \`$db\`; CREATE TABLE test_table (id INT, name VARCHAR(50));"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that the created user can insert data
|
||||
run docker exec "$cname" dolt sql -q "USE \`$db\`; INSERT INTO test_table VALUES (1, 'test');"
|
||||
[ $status -eq 0 ]
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: default user permissions and operations" {
|
||||
cname="${TEST_PREFIX}default-user"
|
||||
|
||||
# Run container without any user parameters (default behavior)
|
||||
run_container "$cname" -e DOLT_ROOT_PASSWORD=rootpass
|
||||
|
||||
# Test that the default root user can connect and perform operations
|
||||
run docker exec "$cname" dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that the default user can create databases
|
||||
run docker exec "$cname" dolt sql -q "CREATE DATABASE testdb;"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that the default user can create tables
|
||||
run docker exec "$cname" dolt sql -q "USE testdb; CREATE TABLE user_table (id INT PRIMARY KEY, data VARCHAR(100));"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that the default user can insert data
|
||||
run docker exec "$cname" dolt sql -q "USE testdb; INSERT INTO user_table VALUES (1, 'test data');"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that the default user can query data
|
||||
run docker exec "$cname" dolt sql -q "USE testdb; SELECT * FROM user_table;"
|
||||
[ $status -eq 0 ]
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: MySQL client connectivity via TCP" {
|
||||
cname="${TEST_PREFIX}mysql-client"
|
||||
db="testdb"
|
||||
usr="testuser"
|
||||
pwd="testpass"
|
||||
|
||||
# Run container with port mapping
|
||||
run_container_with_port "$cname" 3313 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -e DOLT_DATABASE="$db" -e DOLT_USER="$usr" -e DOLT_PASSWORD="$pwd"
|
||||
|
||||
# Test root user connection via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
echo "$output" | grep -Fx "$db" >/dev/null
|
||||
|
||||
# Test custom user connection via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
echo "$output" | grep -Fx "$db" >/dev/null
|
||||
|
||||
# Test that custom user can perform operations via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; CREATE TABLE mysql_test (id INT PRIMARY KEY, name VARCHAR(50));"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test data insertion via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; INSERT INTO mysql_test VALUES (1, 'mysql_test_data');"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test data query via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; SELECT * FROM mysql_test;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "mysql_test_data" ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: MySQL client with reserved keywords" {
|
||||
cname="${TEST_PREFIX}mysql-kw"
|
||||
kw_db="select"
|
||||
kw_user="from"
|
||||
pwd="testpass"
|
||||
|
||||
# Run container with port mapping
|
||||
run_container_with_port "$cname" 3314 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -e DOLT_DATABASE="$kw_db" -e DOLT_USER="$kw_user" -e DOLT_PASSWORD="$pwd"
|
||||
|
||||
# Test root user can see the reserved keyword database
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
echo "$output" | grep -Fx "$kw_db" >/dev/null
|
||||
|
||||
# Test custom user with reserved keyword name can connect
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u "$kw_user" --password="$pwd" -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
echo "$output" | grep -Fx "$kw_db" >/dev/null
|
||||
|
||||
# Test operations with reserved keyword database name
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u "$kw_user" --password="$pwd" -e "USE \`$kw_db\`; CREATE TABLE test_table (id INT);"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test data operations
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u "$kw_user" --password="$pwd" -e "USE \`$kw_db\`; INSERT INTO test_table VALUES (1);"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test query
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u "$kw_user" --password="$pwd" -e "USE \`$kw_db\`; SELECT * FROM test_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: SQL error reporting without suppression" {
|
||||
cname="${TEST_PREFIX}sql-error-reporting"
|
||||
@@ -375,18 +258,6 @@ wait_for_log() {
|
||||
[[ "$output" =~ "information_schema" ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: no DOLT_ROOT_PASSWORD is allowed" {
|
||||
cname="${TEST_PREFIX}no-password-allowed"
|
||||
# Run container without DOLT_ROOT_PASSWORD set at all
|
||||
run_container "$cname"
|
||||
|
||||
# Test that we can connect without password (this should work even without explicit root user)
|
||||
run docker exec "$cname" dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "information_schema" ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: valid server config file handling" {
|
||||
cname="${TEST_PREFIX}valid-server-config"
|
||||
@@ -406,7 +277,7 @@ cfg_dir: .doltcfg
|
||||
EOF
|
||||
|
||||
# Run container with valid server config file
|
||||
run_container "$cname" -e DOLT_ROOT_PASSWORD="" -v /tmp/test-config:/etc/dolt/servercfg.d:ro
|
||||
run_container "$cname" -v /tmp/test-config:/etc/dolt/servercfg.d:ro
|
||||
|
||||
# Cleanup
|
||||
rm -rf /tmp/test-config
|
||||
@@ -420,7 +291,7 @@ EOF
|
||||
echo '{"user": {"name": "test"}}' > /tmp/test-config/test.json
|
||||
|
||||
# Run container with invalid config file (should fail)
|
||||
run docker run -d --name "$cname" -e DOLT_ROOT_PASSWORD="" -v /tmp/test-config:/etc/dolt/doltcfg.d:ro "$TEST_IMAGE"
|
||||
run docker run -d --name "$cname" -v /tmp/test-config:/etc/dolt/doltcfg.d:ro "$TEST_IMAGE"
|
||||
|
||||
# Wait a bit for container to start
|
||||
sleep 5
|
||||
@@ -437,3 +308,228 @@ EOF
|
||||
# Cleanup
|
||||
rm -rf /tmp/test-config
|
||||
}
|
||||
|
||||
@test "docker-entrypoint: wrong password authentication" {
|
||||
cname="${TEST_PREFIX}wrong-pass"
|
||||
usr="testuser"
|
||||
pwd="testpass"
|
||||
|
||||
# Run container with custom user
|
||||
run_container_with_port "$cname" 3315 \
|
||||
-e DOLT_ROOT_PASSWORD=rootpass \
|
||||
-e DOLT_ROOT_HOST=% \
|
||||
-e DOLT_USER="$usr" \
|
||||
-e DOLT_PASSWORD="$pwd"
|
||||
|
||||
# Test wrong password fails with Dolt client
|
||||
run docker exec "$cname" dolt -u "$usr" -p "wrongpass" sql -q "SHOW DATABASES;"
|
||||
[ $status -ne 0 ]
|
||||
[[ "$output" =~ "Error 1045 (28000): Access denied for user 'testuser'" ]] || false
|
||||
|
||||
# Test wrong password fails with MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3315 -u "$usr" --password="wrongpass" -e "SHOW DATABASES;"
|
||||
[ $status -ne 0 ]
|
||||
[[ "$output" =~ "ERROR 1045 (28000): Access denied for user 'testuser'" ]] || false
|
||||
|
||||
run docker exec "$cname" dolt -u root -p wrongpass sql -q "SHOW DATABASES;"
|
||||
[ $status -ne 0 ]
|
||||
[[ "$output" =~ "Error 1045 (28000): Access denied for user 'root'" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3315 -u root --password=wrongpass -e "SHOW DATABASES;"
|
||||
[ $status -ne 0 ]
|
||||
[[ "$output" =~ "ERROR 1045 (28000): Access denied for user 'root'" ]] || false
|
||||
}
|
||||
|
||||
@test "docker-entrypoint: custom database with root and user access" {
|
||||
cname="${TEST_PREFIX}dolt-auth"
|
||||
db="testdb"
|
||||
usr="testuser"
|
||||
pwd="testpass"
|
||||
|
||||
# Run container with custom database and user
|
||||
run_container_with_port "$cname" 3314 \
|
||||
-e DOLT_ROOT_PASSWORD=rootpass \
|
||||
-e DOLT_ROOT_HOST=% \
|
||||
-e DOLT_DATABASE="$db" \
|
||||
-e DOLT_USER="$usr" \
|
||||
-e DOLT_PASSWORD="$pwd"
|
||||
|
||||
# Test that root user can access the custom database using dolt client
|
||||
run docker exec "$cname" dolt -u root -p rootpass sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "$db" ]] || false
|
||||
|
||||
# Test that root user can create tables in the custom database
|
||||
run docker exec "$cname" dolt -u root -p rootpass sql -q "USE \`$db\`; CREATE TABLE root_table (id INT PRIMARY KEY, data VARCHAR(100));"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that root user can insert data
|
||||
run docker exec "$cname" dolt -u root -p rootpass sql -q "USE \`$db\`; INSERT INTO root_table VALUES (1, 'root data');"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that custom user can access the custom database using dolt client
|
||||
run docker exec "$cname" dolt -u "$usr" -p "$pwd" sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "$db" ]] || false
|
||||
|
||||
# Test that custom user can create tables in the custom database
|
||||
run docker exec "$cname" dolt -u "$usr" -p "$pwd" sql -q "USE \`$db\`; CREATE TABLE user_table (id INT PRIMARY KEY, data VARCHAR(100));"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that custom user can insert data
|
||||
run docker exec "$cname" dolt -u "$usr" -p "$pwd" sql -q "USE \`$db\`; INSERT INTO user_table VALUES (1, 'user data');"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that custom user can query data
|
||||
run docker exec "$cname" dolt -u "$usr" -p "$pwd" sql -q "USE \`$db\`; SELECT * FROM user_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "user data" ]] || false
|
||||
|
||||
# Test that custom user can see root's table (both have access to the same database)
|
||||
run docker exec "$cname" dolt -u "$usr" -p "$pwd" sql -q "USE \`$db\`; SELECT * FROM root_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "root data" ]] || false
|
||||
|
||||
# Test that root can see user's table
|
||||
run docker exec "$cname" dolt -u root -p rootpass sql -q "USE \`$db\`; SELECT * FROM user_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "user data" ]] || false
|
||||
|
||||
# Test that custom user cannot access other databases (if any exist)
|
||||
run docker exec "$cname" dolt -u "$usr" -p "$pwd" sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
# Should only see the custom database and information_schema
|
||||
db_count=$(echo "$output" | grep -c "testdb\|information_schema" || true)
|
||||
[ "$db_count" -eq 2 ] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: MySQL client connectivity via TCP" {
|
||||
cname="${TEST_PREFIX}mysql-client"
|
||||
db="testdb"
|
||||
usr="testuser"
|
||||
pwd="testpass"
|
||||
|
||||
# Run container with port mapping
|
||||
run_container_with_port "$cname" 3313 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -e DOLT_DATABASE="$db" -e DOLT_USER="$usr" -e DOLT_PASSWORD="$pwd"
|
||||
|
||||
# Test root user connection via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
echo "$output" | grep -Fx "$db" >/dev/null
|
||||
|
||||
# Test custom user connection via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
echo "$output" | grep -Fx "$db" >/dev/null
|
||||
|
||||
# Test that custom user can perform operations via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; CREATE TABLE mysql_test (id INT PRIMARY KEY, name VARCHAR(50));"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test data insertion via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; INSERT INTO mysql_test VALUES (1, 'mysql_test_data');"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test data query via MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; SELECT * FROM mysql_test;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "mysql_test_data" ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: MySQL client with reserved keywords" {
|
||||
cname="${TEST_PREFIX}mysql-kw"
|
||||
kw_db="select"
|
||||
kw_user="from"
|
||||
pwd="testpass"
|
||||
|
||||
# Run container with port mapping
|
||||
run_container_with_port "$cname" 3314 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -e DOLT_DATABASE="$kw_db" -e DOLT_USER="$kw_user" -e DOLT_PASSWORD="$pwd"
|
||||
|
||||
# Test root user can see the reserved keyword database
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
echo "$output" | grep -Fx "$kw_db" >/dev/null
|
||||
|
||||
# Test custom user with reserved keyword name can connect
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u "$kw_user" --password="$pwd" -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
echo "$output" | grep -Fx "$kw_db" >/dev/null
|
||||
|
||||
# Test operations with reserved keyword database name
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u "$kw_user" --password="$pwd" -e "USE \`$kw_db\`; CREATE TABLE test_table (id INT);"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test data operations
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u "$kw_user" --password="$pwd" -e "USE \`$kw_db\`; INSERT INTO test_table VALUES (1);"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test query
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3314 -u "$kw_user" --password="$pwd" -e "USE \`$kw_db\`; SELECT * FROM test_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
}
|
||||
|
||||
@test "docker-entrypoint: MySQL client custom database with root and user access" {
|
||||
cname="${TEST_PREFIX}custom-db"
|
||||
db="testdb"
|
||||
usr="testuser"
|
||||
pwd="testpass"
|
||||
|
||||
# Run container with custom database and user
|
||||
run_container_with_port "$cname" 3313 \
|
||||
-e DOLT_ROOT_PASSWORD=rootpass \
|
||||
-e DOLT_ROOT_HOST=% \
|
||||
-e DOLT_DATABASE="$db" \
|
||||
-e DOLT_USER="$usr" \
|
||||
-e DOLT_PASSWORD="$pwd"
|
||||
|
||||
# Test that root user can access the custom database using external MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "$db" ]] || false
|
||||
|
||||
# Test that root user can create tables in the custom database
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u root --password=rootpass -e "USE \`$db\`; CREATE TABLE root_table (id INT PRIMARY KEY, data VARCHAR(100));"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that root user can insert data
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u root --password=rootpass -e "USE \`$db\`; INSERT INTO root_table VALUES (1, 'root data');"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that custom user can access the custom database using external MySQL client
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "$db" ]] || false
|
||||
|
||||
# Test that custom user can create tables in the custom database
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; CREATE TABLE user_table (id INT PRIMARY KEY, data VARCHAR(100));"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that custom user can insert data
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; INSERT INTO user_table VALUES (1, 'user data');"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Test that custom user can query data
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; SELECT * FROM user_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "user data" ]] || false
|
||||
|
||||
# Test that custom user can see root's table (both have access to the same database)
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "USE \`$db\`; SELECT * FROM root_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "root data" ]] || false
|
||||
|
||||
# Test that root can see user's table
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u root --password=rootpass -e "USE \`$db\`; SELECT * FROM user_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "user data" ]] || false
|
||||
|
||||
# Test that custom user cannot access other databases (if any exist)
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3313 -u "$usr" --password="$pwd" -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
# Should only see the custom database and information_schema
|
||||
db_count=$(echo "$output" | grep -c "testdb\|information_schema" || true)
|
||||
[ "$db_count" -eq 2 ] || false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user