'config-missing-db-host' => 'You must enter a value for "Database host"',
'config-missing-db-server-oracle' => 'You must enter a value for "Database TNS"',
'config-invalid-db-server-oracle' => 'Invalid database TNS "$1".
-Use only ASCII letters (a-z, A-Z), numbers (0-9), underscores (_) and dots (.).',
+Use either "TNS Name" or an "Easy Connect" string ([http://docs.oracle.com/cd/E11882_01/network.112/e10836/naming.htm Oracle Naming Methods])',
'config-invalid-db-name' => 'Invalid database name "$1".
Use only ASCII letters (a-z, A-Z), numbers (0-9), underscores (_) and hyphens (-).',
'config-invalid-db-prefix' => 'Invalid database prefix "$1".
$status = Status::newGood();
if ( !strlen( $newValues['wgDBserver'] ) ) {
$status->fatal( 'config-missing-db-server-oracle' );
- } elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
+ } elseif ( !self::checkConnectStringFormat( $newValues['wgDBserver'] ) ) {
$status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
}
if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
";
}
+ /**
+ * Function checks the format of Oracle connect string
+ * The actual validity of the string is checked by attempting to connect
+ *
+ * Regex should be able to validate all connect string formats
+ * [//](host|tns_name)[:port][/service_name][:POOLED]
+ * http://www.orafaq.com/wiki/EZCONNECT
+ *
+ * @since 1.22
+ *
+ * @param string $connect_string
+ *
+ * @return bool Whether the connection string is valid.
+ */
+ public static function checkConnectStringFormat( $connect_string ) {
+ $isValid = preg_match( '/^[[:alpha:]][\w\-]*(?:\.[[:alpha:]][\w\-]*){0,2}$/', $connect_string ); // TNS name
+ $isValid |= preg_match( '/^(?:\/\/)?[\w\-\.]+(?::[\d]+)?(?:\/(?:[\w\-\.]+(?::(pooled|dedicated|shared))?)?(?:\/[\w\-\.]+)?)?$/', $connect_string ); // EZConnect
+ return (bool)$isValid;
+ }
+
}
--- /dev/null
+<?php
+
+/**
+ * Tests for OracleInstaller
+ *
+ * @group Database
+ * @group Installer
+ */
+
+class OracleInstallerTest extends MediaWikiTestCase {
+
+ /**
+ * @dataProvider provideOracleConnectStrings
+ */
+ function testCheckConnectStringFormat( $expected, $connectString, $msg = '' ) {
+ $validity = $expected ? 'should be valid' : 'should NOT be valid';
+ $msg = "'$connectString' ($msg) $validity.";
+ $this->assertEquals( $expected,
+ OracleInstaller::checkConnectStringFormat( $connectString ),
+ $msg
+ );
+ }
+
+ /**
+ * Provider to test OracleInstaller::checkConnectStringFormat()
+ */
+ function provideOracleConnectStrings() {
+ // expected result, connectString[, message]
+ return array(
+ array( true, 'simple_01', 'Simple TNS name' ),
+ array( true, 'simple_01.world', 'TNS name with domain' ),
+ array( true, 'simple_01.domain.net', 'TNS name with domain' ),
+ array( true, 'host123', 'Host only' ),
+ array( true, 'host123.domain.net', 'FQDN only' ),
+ array( true, '//host123.domain.net', 'FQDN URL only' ),
+ array( true, '123.223.213.132', 'Host IP only' ),
+ array( true, 'host:1521', 'Host and port' ),
+ array( true, 'host:1521/service', 'Host, port and service' ),
+ array( true, 'host:1521/service:shared', 'Host, port, service and shared server type' ),
+ array( true, 'host:1521/service:dedicated', 'Host, port, service and dedicated server type' ),
+ array( true, 'host:1521/service:pooled', 'Host, port, service and pooled server type' ),
+ array( true, 'host:1521/service:shared/instance1', 'Host, port, service, server type and instance' ),
+ array( true, 'host:1521//instance1', 'Host, port and instance' ),
+ );
+ }
+
+}