diff --git a/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php b/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php index 3d95cc8..647463a 100644 --- a/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php +++ b/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php @@ -64,9 +64,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { } // Decide on a default backend. - if ($authorize_filetransfer_default = $form_state->getValue(array('connection_settings', 'authorize_filetransfer_default'))); - elseif ($authorize_filetransfer_default = $this->config('system.authorize')->get('filetransfer_default')); - else { + $authorize_filetransfer_default = $form_state->getValue(array('connection_settings', 'authorize_filetransfer_default')); + if (!$authorize_filetransfer_default) { $authorize_filetransfer_default = key($available_backends); } @@ -198,29 +197,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // likely) be called during the installation process, before the // database is set up. try { - $connection_settings = array(); - foreach ($form_connection_settings[$filetransfer_backend] as $key => $value) { - // We do *not* want to store passwords in the database, unless the - // backend explicitly says so via the magic #filetransfer_save form - // property. Otherwise, we store everything that's not explicitly - // marked with #filetransfer_save set to FALSE. - if (!isset($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save'])) { - if ($form['connection_settings'][$filetransfer_backend][$key]['#type'] != 'password') { - $connection_settings[$key] = $value; - } - } - // The attribute is defined, so only save if set to TRUE. - elseif ($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save']) { - $connection_settings[$key] = $value; - } - } - // Set this one as the default authorize method and - // save the connection settings minus the password. - $this->configFactory()->getEditable('system.authorize') - ->set('filetransfer_default', $filetransfer_backend) - ->set('filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings) - ->save(); - $filetransfer = $this->getFiletransfer($filetransfer_backend, $form_connection_settings[$filetransfer_backend]); // Now run the operation. @@ -282,8 +258,7 @@ protected function getFiletransfer($backend, $settings = array()) { * @see hook_filetransfer_backends() */ protected function addConnectionSettings($backend) { - $auth_connection_config = $this->config('system.authorize')->get('filetransfer_connection_settings_' . $backend); - $defaults = $auth_connection_config ? $auth_connection_config : array(); + $defaults = array(); $form = array(); // Create an instance of the file transfer class to get its settings form. diff --git a/core/modules/update/src/Form/UpdateManagerInstall.php b/core/modules/update/src/Form/UpdateManagerInstall.php index 5524f9e..fcd8de5 100644 --- a/core/modules/update/src/Form/UpdateManagerInstall.php +++ b/core/modules/update/src/Form/UpdateManagerInstall.php @@ -219,12 +219,17 @@ public function submitForm(array &$form, FormStateInterface $form_state) { 'local_url' => $project_real_location, ); + // This process is inherently difficult to test therefore use a state flag. + $test_authorize = FALSE; + if (drupal_valid_test_ua()) { + $test_authorize = \Drupal::state()->get('test_uploaders_via_prompt', FALSE); + } // If the owner of the directory we extracted is the same as the owner of // our configuration directory (e.g. sites/default) where we're trying to // install the code, there's no need to prompt for FTP/SSH credentials. // Instead, we instantiate a Drupal\Core\FileTransfer\Local and invoke // update_authorize_run_install() directly. - if (fileowner($project_real_location) == fileowner($this->sitePath)) { + if (fileowner($project_real_location) == fileowner($this->sitePath) && !$test_authorize) { $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize'); $filetransfer = new Local($this->root); $response = call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments)); diff --git a/core/modules/update/src/Tests/UpdateViaAuthorizeTest.php b/core/modules/update/src/Tests/UpdateViaAuthorizeTest.php new file mode 100644 index 0000000..7f7fe6e --- /dev/null +++ b/core/modules/update/src/Tests/UpdateViaAuthorizeTest.php @@ -0,0 +1,44 @@ +drupalCreateUser(array('administer modules', 'administer software updates', 'administer site configuration')); + $this->drupalLogin($admin_user); + } + + /** + * Tests the Update Manager module upload via authorize.php functionality. + */ + public function testViaAuthorize() { + // Ensure the that we can select which file transfer backend to use. + \Drupal::state()->set('test_uploaders_via_prompt', TRUE); + + $edit = [ + 'project_url' => 'https://ftp.drupal.org/files/projects/config_inspector-8.x-1.0-beta1.tar.gz', + ]; + $this->drupalPostForm('http://drupal8alt.dev/admin/modules/install', $edit, t('Install')); + $edit = [ + 'connection_settings[authorize_filetransfer_default]' => 'system_test', + 'connection_settings[system_test][update_test_username]' => $this->randomMachineName(), + ]; + $this->drupalPostForm(NULL, $edit, t('Continue')); + $this->assertText(t('Installation was completed successfully.')); + } + +} diff --git a/core/modules/update/tests/modules/update_test/src/MockFileTransfer.php b/core/modules/update/tests/modules/update_test/src/MockFileTransfer.php index 9e40b65..3873d6b 100644 --- a/core/modules/update/tests/modules/update_test/src/MockFileTransfer.php +++ b/core/modules/update/tests/modules/update_test/src/MockFileTransfer.php @@ -2,10 +2,17 @@ namespace Drupal\update_test; +use Drupal\Core\FileTransfer\Local; + /** * Mocks a FileTransfer object to test the settings form functionality. + * + * This class extends \Drupal\Core\FileTransfer\Local to make module install + * testing via authorize.php possible. + * + * @see \Drupal\update\Tests\UpdateViaAuthorizeTest */ -class MockFileTransfer { +class MockFileTransfer extends Local { /** * Returns a Drupal\update_test\MockFileTransfer object. @@ -13,8 +20,8 @@ class MockFileTransfer { * @return \Drupal\update_test\MockFileTransfer * A new Drupal\update_test\MockFileTransfer object. */ - public static function factory() { - return new FileTransfer(); + public static function factory($jail, $settings) { + return new static($jail); } /**