From 9116c39a829ef10745acea5f3e9a4d47433ffa47 Mon Sep 17 00:00:00 2001
From: Vincent Petry <pvince81@owncloud.com>
Date: Wed, 19 Mar 2014 17:56:36 +0100
Subject: [PATCH] Fixed ext storage password field order issue

The old password field is now preserved in the JSON structure to make
sure that the order is preserved.
This is a quick fix until the UI is fixed to not rely on the PHP array
key order.
---
 apps/files_external/lib/config.php        | 5 ++++-
 apps/files_external/tests/mountconfig.php | 8 ++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 6de7c91358..9b2cb0d0b0 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -50,6 +50,7 @@ class OC_Mount_Config {
 	*/
 	public static function getBackends() {
 
+		// FIXME: do not rely on php key order for the options order in the UI
 		$backends['\OC\Files\Storage\Local']=array(
 				'backend' => 'Local',
 				'configuration' => array(
@@ -649,7 +650,9 @@ class OC_Mount_Config {
 	private static function encryptPasswords($options) {
 		if (isset($options['password'])) {
 			$options['password_encrypted'] = self::encryptPassword($options['password']);
-			unset($options['password']);
+			// do not unset the password, we want to keep the keys order
+			// on load... because that's how the UI currently works
+			$options['password'] = '';
 		}
 		return $options;
 	}
diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php
index 144aad4f64..bf43bb31c3 100644
--- a/apps/files_external/tests/mountconfig.php
+++ b/apps/files_external/tests/mountconfig.php
@@ -245,6 +245,8 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase {
 		$this->assertEquals('\OC\Files\Storage\SMB', $config['ext']['class']);
 		$savedMountConfig = $config['ext']['configuration'];
 		$this->assertEquals($mountConfig, $savedMountConfig);
+		// key order needs to be preserved for the UI...
+		$this->assertEquals(array_keys($mountConfig), array_keys($savedMountConfig));
 	}
 
 	/**
@@ -281,6 +283,8 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase {
 		$this->assertEquals('\OC\Files\Storage\SMB', $config['ext']['class']);
 		$savedMountConfig = $config['ext']['configuration'];
 		$this->assertEquals($mountConfig, $savedMountConfig);
+		// key order needs to be preserved for the UI...
+		$this->assertEquals(array_keys($mountConfig), array_keys($savedMountConfig));
 	}
 
 	/**
@@ -316,8 +320,8 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase {
 		$config = $this->readUserConfig();
 		$savedConfig = $config[$mountType][$applicable]['/' . self::TEST_USER1 . '/files/ext']['options'];
 
-		// no more clear text password in file
-		$this->assertFalse(isset($savedConfig['password']));
+		// no more clear text password in file (kept because of key order)
+		$this->assertEquals('', $savedConfig['password']);
 
 		// encrypted password is present
 		$this->assertNotEquals($mountConfig['password'], $savedConfig['password_encrypted']);
-- 
GitLab