$options = &PEAR::getStaticProperty('DB_DataObject', 'options');
$options['database'] = $dsn;
$options['quote_identifiers'] = TRUE;
- if (self::isSSLDSN($dsn)) {
+ if (CRM_Utils_SQL::isSSLDSN($dsn)) {
// There are two different options arrays.
$other_options = &PEAR::getStaticProperty('DB', 'options');
$other_options['ssl'] = TRUE;
}
}
- /**
- * Does the DSN indicate the connection should use ssl.
- *
- * @param string $dsn
- *
- * @return bool
- */
- public static function isSSLDSN(string $dsn):bool {
- // Note that ssl= below is not an official PEAR::DB option. It doesn't know
- // what to do with it. We made it up because it's not required
- // to have client-side certificates to use ssl, so here you can specify
- // you want that by putting ssl=1 in the DSN string.
- //
- // Cast to bool in case of error which we interpret as no ssl.
- return (bool) preg_match('/[\?&](key|cert|ca|capath|cipher|ssl)=/', $dsn);
- }
-
}
return CRM_Core_DAO::singleValueQuery('SELECT VERSION()');
}
+ /**
+ * Does the DSN indicate the connection should use ssl.
+ *
+ * @param string $dsn
+ *
+ * @return bool
+ */
+ public static function isSSLDSN(string $dsn):bool {
+ // Note that ssl= below is not an official PEAR::DB option. It doesn't know
+ // what to do with it. We made it up because it's not required
+ // to have client-side certificates to use ssl, so here you can specify
+ // you want that by putting ssl=1 in the DSN string.
+ //
+ // Cast to bool in case of error which we interpret as no ssl.
+ return (bool) preg_match('/[\?&](key|cert|ca|capath|cipher|ssl)=/', $dsn);
+ }
+
}
}
}
+ /**
+ * Test isSSLDSN
+ * @dataProvider dsnProvider
+ * @param string $input
+ * @param bool $expected
+ */
+ public function testIsSSLDSN(string $input, bool $expected) {
+ $this->assertSame($expected, CRM_Utils_SQL::isSSLDSN($input));
+ }
+
+ /**
+ * Data provider for testIsSSLDSN
+ * @return array
+ */
+ public function dsnProvider():array {
+ return [
+ ['', FALSE],
+ ['mysqli://user:pass@localhost/drupal', FALSE],
+ ['mysqli://user:pass@localhost:3306/drupal', FALSE],
+ ['mysql://user:pass@localhost:3306/drupal', FALSE],
+ ['mysql://user:pass@localhost:3306/drupal', FALSE],
+ ['mysql://user:pass@localhost:3306/drupal?new_link=true', FALSE],
+ ['mysqli://user:pass@localhost:3306/drupal?ssl', FALSE],
+ ['mysqli://user:pass@localhost:3306/drupal?ssl=1', TRUE],
+ ['mysqli://user:pass@localhost:3306/drupal?new_link=true&ssl=1', TRUE],
+ ['mysql://user:pass@localhost:3306/drupal?ssl=1', TRUE],
+ ['mysqli://user:pass@localhost:3306/drupal?ca=%2Ftmp%2Fcacert.crt', TRUE],
+ ['mysqli://user:pass@localhost/drupal?ca=%2Ftmp%2Fcacert.crt&cert=%2Ftmp%2Fcert.crt&key=%2Ftmp%2F', TRUE],
+ ['mysqli://user:pass@localhost/drupal?ca=%2Fpath%20with%20spaces%2Fcacert.crt', TRUE],
+ ['mysqli://user:pass@localhost:3306/drupal?cipher=aes', TRUE],
+ ['mysqli://user:pass@localhost:3306/drupal?capath=%2Ftmp', TRUE],
+ ['mysqli://user:pass@localhost:3306/drupal?cipher=aes&capath=%2Ftmp&food=banana', TRUE],
+ ['mysqli://user:pass@localhost:3306/drupal?food=banana&cipher=aes', TRUE],
+ ];
+ }
+
}