diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-10 19:38:52 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-10 19:38:52 +0200 |
commit | 836dfebf723afc264868da69021c89221d02aa18 (patch) | |
tree | ae5274151345a13f65488bb6562fe1db0da41244 | |
parent | 5befce51ef9f38609b713cfbc6095a3b60b1d574 (diff) |
build http basic auth rather than requiring it from the user to write the correct auth string into the config
-rw-r--r-- | README.rst | 9 | ||||
-rw-r--r-- | tests/unit/utility/ConfigTest.php | 25 | ||||
-rw-r--r-- | utility/config.php | 31 |
3 files changed, 49 insertions, 16 deletions
diff --git a/README.rst b/README.rst index e78cb3761..7dd89199b 100644 --- a/README.rst +++ b/README.rst @@ -178,13 +178,10 @@ The configuration is in **INI** format and looks like this: * **simplePieCacheDuration**: Amount of seconds to cache feeds * **feedFetcherTimeout**: Maximum number of seconds to wait for an RSS or Atom feed to load. If a feed takes longer than that number of seconds to update, the update will be aborted * **useCronUpdates**: To use a custom update/cron script you need to disable the cronjob which is run by ownCloud by default by setting this to false -* **proxHost**: The adress of the proxy. Leave empty if no proxy should be used +* **proxHost**: The adress of the proxy. Leave blank if no proxy should be used * **proxyPort**: The proxy port, defaults to 8080 -* **proxyAuth**: The proxy auth details. Provide these in HTTP basic auth format: - - user:password - - +* **proxyUser**: The proxy user name for the login. Must not container colons. Leave blank if there is none. +* **proxyPassword**: The proxy user password for the login diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php index 9cea0acf0..a2b871c76 100644 --- a/tests/unit/utility/ConfigTest.php +++ b/tests/unit/utility/ConfigTest.php @@ -57,7 +57,9 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility { $this->assertEquals(true, $this->config->getUseCronUpdates()); $this->assertEquals(8080, $this->config->getProxyPort()); $this->assertEquals('', $this->config->getProxyHost()); - $this->assertEquals('', $this->config->getProxyAuth()); + $this->assertEquals(null, $this->config->getProxyAuth()); + $this->assertEquals('', $this->config->getProxyUser()); + $this->assertEquals('', $this->config->getProxyPassword()); } @@ -124,11 +126,13 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility { "useCronUpdates = true\n" . "proxyHost = yo man\n" . "proxyPort = 12\n" . - "proxyAuth = this is a test"; + "proxyUser = this is a test\n". + "proxyPassword = se"; $this->config->setAutoPurgeCount(3); $this->config->setProxyHost("yo man"); $this->config->setProxyPort(12); - $this->config->setProxyAuth("this is a test"); + $this->config->setProxyUser("this is a test"); + $this->config->setProxyPassword("se"); $this->fileSystem->expects($this->once()) ->method('file_put_contents') @@ -139,6 +143,11 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility { } + public function testNoProxyAuthReturnsNull() { + $this->assertNull($this->config->getProxyAuth()); + } + + public function testReadingNonExistentConfigWillWriteDefaults() { $this->fileSystem->expects($this->once()) ->method('file_exists') @@ -154,7 +163,8 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility { "useCronUpdates = false\n" . "proxyHost = \n" . "proxyPort = 8080\n" . - "proxyAuth = "; + "proxyUser = \n" . + "proxyPassword = "; $this->fileSystem->expects($this->once()) ->method('file_put_contents') @@ -164,4 +174,11 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility { $this->config->read($this->configPath, true); } + + public function testEncodesUserAndPasswordInHTTPBasicAuth() { + $this->config->setProxyUser("this is a test"); + $this->config->setProxyPassword("se"); + + $this->assertEquals('this is a test:se', $this->config->getProxyAuth()); + } }
\ No newline at end of file diff --git a/utility/config.php b/utility/config.php index 0fa636ea8..d415595b7 100644 --- a/utility/config.php +++ b/utility/config.php @@ -41,7 +41,8 @@ class Config { private $useCronUpdates; // turn off updates run by owncloud cronjob private $proxyHost; private $proxyPort; - private $proxyAuth; + private $proxyUser; + private $proxyPassword; private $api; @@ -55,7 +56,8 @@ class Config { $this->api = $api; $this->proxyHost = ''; $this->proxyPort = 8080; - $this->proxyAuth = ''; + $this->proxyUser = ''; + $this->proxyPassword = ''; } public function getProxyPort() { @@ -67,7 +69,19 @@ class Config { } public function getProxyAuth() { - return $this->proxyAuth; + if($this->proxyUser === '') { + return null; + } else { + return $this->proxyUser . ':' . $this->proxyPassword; + } + } + + public function getProxyUser() { + return $this->proxyUser; + } + + public function getProxyPassword() { + return $this->proxyPassword; } public function getAutoPurgeMinimumInterval() { @@ -128,8 +142,12 @@ class Config { $this->proxyHost = $value; } - public function setProxyAuth($value) { - $this->proxyAuth = $value; + public function setProxyUser($value) { + $this->proxyUser = $value; + } + + public function setProxyPassword($value) { + $this->proxyPassword = $value; } @@ -172,7 +190,8 @@ class Config { "useCronUpdates = " . var_export($this->useCronUpdates, true) . "\n" . "proxyHost = " . $this->proxyHost . "\n" . "proxyPort = " . $this->proxyPort . "\n" . - "proxyAuth = " . $this->proxyAuth; + "proxyUser = " . $this->proxyUser . "\n" . + "proxyPassword = " . $this->proxyPassword; ; $this->fileSystem->file_put_contents($configPath, $ini); |