Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Illuminate/Database/Schema/MySqlSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,20 @@ protected function connectionString()
$value .= ' --ssl-ca="${:LARAVEL_LOAD_SSL_CA}"';
}

// if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]) &&
// $config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] === false) {
// $value .= ' --ssl=off';
// }
if (! $this->connection->isMaria()) {
if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_CERT])) {
$value .= ' --ssl-cert="${:LARAVEL_LOAD_SSL_CERT}"';
}

if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_KEY])) {
$value .= ' --ssl-key="${:LARAVEL_LOAD_SSL_KEY}"';
}

if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]) &&
$config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] === false) {
$value .= ' --ssl-verify-server-cert=OFF';
}
}

return $value;
}
Expand All @@ -142,6 +152,8 @@ protected function baseVariables(array $config)
'LARAVEL_LOAD_PASSWORD' => $config['password'] ?? '',
'LARAVEL_LOAD_DATABASE' => $config['database'],
'LARAVEL_LOAD_SSL_CA' => $config['options'][PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA] ?? '', // @phpstan-ignore class.notFound
'LARAVEL_LOAD_SSL_CERT' => $config['options'][\PDO::MYSQL_ATTR_SSL_CERT] ?? '',
'LARAVEL_LOAD_SSL_KEY' => $config['options'][\PDO::MYSQL_ATTR_SSL_KEY] ?? '',
];
}

Expand Down
46 changes: 28 additions & 18 deletions tests/Database/DatabaseMySqlSchemaStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public static function provider(): Generator
'LARAVEL_LOAD_PASSWORD' => '',
'LARAVEL_LOAD_DATABASE' => 'forge',
'LARAVEL_LOAD_SSL_CA' => '',
'LARAVEL_LOAD_SSL_CERT' => '',
'LARAVEL_LOAD_SSL_KEY' => '',
], [
'username' => 'root',
'host' => '127.0.0.1',
Expand All @@ -53,40 +55,46 @@ public static function provider(): Generator
];

yield 'ssl_ca' => [
' --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --ssl-ca="${:LARAVEL_LOAD_SSL_CA}"', [
' --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --ssl-ca="${:LARAVEL_LOAD_SSL_CA}" --ssl-cert="${:LARAVEL_LOAD_SSL_CERT}" --ssl-key="${:LARAVEL_LOAD_SSL_KEY}"', [
'LARAVEL_LOAD_SOCKET' => '',
'LARAVEL_LOAD_HOST' => '',
'LARAVEL_LOAD_PORT' => '',
'LARAVEL_LOAD_USER' => 'root',
'LARAVEL_LOAD_PASSWORD' => '',
'LARAVEL_LOAD_DATABASE' => 'forge',
'LARAVEL_LOAD_SSL_CA' => 'ssl.ca',
'LARAVEL_LOAD_SSL_CERT' => 'cert.pem',
'LARAVEL_LOAD_SSL_KEY' => 'key.pem',
], [
'username' => 'root',
'database' => 'forge',
'options' => [
PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA => 'ssl.ca',
\PDO::MYSQL_ATTR_SSL_CERT => 'cert.pem',
\PDO::MYSQL_ATTR_SSL_KEY => 'key.pem',
],
],
];

// yield 'no_ssl' => [
// ' --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --ssl=off', [
// 'LARAVEL_LOAD_SOCKET' => '',
// 'LARAVEL_LOAD_HOST' => '',
// 'LARAVEL_LOAD_PORT' => '',
// 'LARAVEL_LOAD_USER' => 'root',
// 'LARAVEL_LOAD_PASSWORD' => '',
// 'LARAVEL_LOAD_DATABASE' => 'forge',
// 'LARAVEL_LOAD_SSL_CA' => '',
// ], [
// 'username' => 'root',
// 'database' => 'forge',
// 'options' => [
// \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
// ],
// ],
// ];
yield 'no_ssl' => [
' --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --ssl-verify-server-cert=OFF', [
'LARAVEL_LOAD_SOCKET' => '',
'LARAVEL_LOAD_HOST' => '',
'LARAVEL_LOAD_PORT' => '',
'LARAVEL_LOAD_USER' => 'root',
'LARAVEL_LOAD_PASSWORD' => '',
'LARAVEL_LOAD_DATABASE' => 'forge',
'LARAVEL_LOAD_SSL_CA' => '',
'LARAVEL_LOAD_SSL_CERT' => '',
'LARAVEL_LOAD_SSL_KEY' => '',
], [
'username' => 'root',
'database' => 'forge',
'options' => [
\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
],
],
];

yield 'unix socket' => [
' --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --socket="${:LARAVEL_LOAD_SOCKET}"', [
Expand All @@ -97,6 +105,8 @@ public static function provider(): Generator
'LARAVEL_LOAD_PASSWORD' => '',
'LARAVEL_LOAD_DATABASE' => 'forge',
'LARAVEL_LOAD_SSL_CA' => '',
'LARAVEL_LOAD_SSL_CERT' => '',
'LARAVEL_LOAD_SSL_KEY' => '',
], [
'username' => 'root',
'database' => 'forge',
Expand Down
Loading