From cbfdcff2615e901bdc434d06f38a3da8eecbdf8b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 31 Jul 2016 10:46:17 +0200 Subject: Prepare settings for the API in the admin page and during the install API settings: - api.enabled - api.secret The API settings will be initialized (and the secret generated) with an update method. --- tests/Updater/UpdaterTest.php | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 4948fe52..0171daad 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -271,7 +271,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; public function testEscapeConfig() { $sandbox = 'sandbox/config'; - copy(self::$configFile .'.json.php', $sandbox .'.json.php'); + copy(self::$configFile . '.json.php', $sandbox . '.json.php'); $this->conf = new ConfigManager($sandbox); $title = ''; $headerLink = ''; @@ -286,7 +286,43 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertEquals(escape($title), $this->conf->get('general.title')); $this->assertEquals(escape($headerLink), $this->conf->get('general.header_link')); $this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url')); - unlink($sandbox .'.json.php'); + unlink($sandbox . '.json.php'); + } + + /** + * Test updateMethodApiSettings(): create default settings for the API (enabled + secret). + */ + public function testUpdateApiSettings() + { + $confFile = 'sandbox/config'; + copy(self::$configFile .'.json.php', $confFile .'.json.php'); + $conf = new ConfigManager($confFile); + $updater = new Updater(array(), array(), $conf, true); + + $this->assertFalse($conf->exists('api.enabled')); + $this->assertFalse($conf->exists('api.secret')); + $updater->updateMethodApiSettings(); + $conf->reload(); + $this->assertTrue($conf->get('api.enabled')); + $this->assertTrue($conf->exists('api.secret')); + unlink($confFile .'.json.php'); + } + + /** + * Test updateMethodApiSettings(): already set, do nothing. + */ + public function testUpdateApiSettingsNothingToDo() + { + $confFile = 'sandbox/config'; + copy(self::$configFile .'.json.php', $confFile .'.json.php'); + $conf = new ConfigManager($confFile); + $conf->set('api.enabled', false); + $conf->set('api.secret', ''); + $updater = new Updater(array(), array(), $conf, true); + $updater->updateMethodApiSettings(); + $this->assertFalse($conf->get('api.enabled')); + $this->assertEmpty($conf->get('api.secret')); + unlink($confFile .'.json.php'); } /** -- cgit v1.2.3 From a0df06517bada0f811b464017ce385290e02c2bf Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 3 Jan 2017 11:42:21 +0100 Subject: Minor improvements regarding #705 (coding style, unit tests, etc.) --- tests/Updater/UpdaterTest.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 0171daad..a1530996 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -2,6 +2,7 @@ require_once 'application/config/ConfigManager.php'; require_once 'tests/Updater/DummyUpdater.php'; +require_once 'inc/rain.tpl.class.php'; /** * Class UpdaterTest. -- cgit v1.2.3 From 04a0e8ea34c241fdf6bd30b11f5242656f9cd1c2 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 3 Jan 2017 12:01:25 +0100 Subject: Updater: keep custom theme preference with the new theme setting --- tests/Updater/UpdaterTest.php | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index a1530996..1d15cfaa 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -422,4 +422,48 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertTrue($updater->updateMethodDatastoreIds()); $this->assertEquals($checksum, hash_file('sha1', self::$testDatastore)); } + + /** + * Test defaultTheme update with default settings: nothing to do. + */ + public function testDefaultThemeWithDefaultSettings() + { + $sandbox = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandbox . '.json.php'); + $this->conf = new ConfigManager($sandbox); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodDefaultTheme()); + + $this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl')); + $this->assertEquals('default', $this->conf->get('resource.theme')); + $this->conf = new ConfigManager($sandbox); + $this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl')); + $this->assertEquals('default', $this->conf->get('resource.theme')); + unlink($sandbox . '.json.php'); + } + + /** + * Test defaultTheme update with a custom theme in a subfolder + */ + public function testDefaultThemeWithCustomTheme() + { + $theme = 'iamanartist'; + $sandbox = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandbox . '.json.php'); + $this->conf = new ConfigManager($sandbox); + mkdir('sandbox/'. $theme); + touch('sandbox/'. $theme .'/linklist.html'); + $this->conf->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/'); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodDefaultTheme()); + + $this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl')); + $this->assertEquals($theme, $this->conf->get('resource.theme')); + $this->conf = new ConfigManager($sandbox); + $this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl')); + $this->assertEquals($theme, $this->conf->get('resource.theme')); + unlink($sandbox . '.json.php'); + unlink('sandbox/'. $theme .'/linklist.html'); + rmdir('sandbox/'. $theme); + } } -- cgit v1.2.3 From 7dcbfde5ffbc057a44f710e3be7e4856d235e90b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 27 Feb 2017 20:20:53 +0100 Subject: Set the vintage theme by default for the time being --- tests/Updater/UpdaterTest.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 1d15cfaa..de330ae2 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -466,4 +466,44 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; unlink('sandbox/'. $theme .'/linklist.html'); rmdir('sandbox/'. $theme); } + + /** + * Test updateMethodDefaultThemeVintage with the default theme enabled. + */ + public function testSetDefaultThemeToVintage() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + + $this->conf->set('resource.theme', 'default'); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodDefaultThemeVintage()); + $this->assertEquals('vintage', $this->conf->get('resource.theme')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertEquals('vintage', $this->conf->get('resource.theme')); + } + + /** + * Test updateMethodDefaultThemeVintage with custom theme enabled => nothing to do. + */ + public function testSetDefaultThemeNothingToDo() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + + $theme = 'myawesometheme'; + $this->conf->set('resource.theme', $theme); + $this->conf->write(true); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodDefaultThemeVintage()); + $this->assertEquals($theme, $this->conf->get('resource.theme')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertEquals($theme, $this->conf->get('resource.theme')); + } } -- cgit v1.2.3 From e03761011521929a375ebb56f21adacb226a3a8d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 27 Feb 2017 19:45:55 +0100 Subject: Add markdown_escape setting This setting allows to escape HTML in markdown rendering or not. The goal behind it is to avoid XSS issue in shared instances. More info: * the setting is set to true by default * it is set to false for anyone who already have the plugin enabled (avoid breaking existing entries) * improve the HTML sanitization when the setting is set to false - but don't consider it XSS proof * mention the setting in the plugin README --- tests/Updater/UpdaterTest.php | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index de330ae2..39be88f9 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -506,4 +506,70 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->conf = new ConfigManager($sandboxConf); $this->assertEquals($theme, $this->conf->get('resource.theme')); } + + /** + * Test updateMethodEscapeMarkdown with markdown plugin enabled + * => setting markdown_escape set to false. + */ + public function testEscapeMarkdownSettingToFalse() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + + $this->conf->set('general.enabled_plugins', ['markdown']); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodEscapeMarkdown()); + $this->assertFalse($this->conf->get('security.markdown_escape')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertFalse($this->conf->get('security.markdown_escape')); + } + + + /** + * Test updateMethodEscapeMarkdown with markdown plugin disabled + * => setting markdown_escape set to true. + */ + public function testEscapeMarkdownSettingToTrue() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + + $this->conf->set('general.enabled_plugins', []); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodEscapeMarkdown()); + $this->assertTrue($this->conf->get('security.markdown_escape')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertTrue($this->conf->get('security.markdown_escape')); + } + + /** + * Test updateMethodEscapeMarkdown with nothing to do (setting already enabled) + */ + public function testEscapeMarkdownSettingNothingToDoEnabled() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $this->conf->set('security.markdown_escape', true); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodEscapeMarkdown()); + $this->assertTrue($this->conf->get('security.markdown_escape')); + } + + /** + * Test updateMethodEscapeMarkdown with nothing to do (setting already disabled) + */ + public function testEscapeMarkdownSettingNothingToDoDisabled() + { + $this->conf->set('security.markdown_escape', false); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodEscapeMarkdown()); + $this->assertFalse($this->conf->get('security.markdown_escape')); + } } -- cgit v1.2.3 From 3c66e56435359dc678048193e8ee239d06f79b64 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Fri, 3 Mar 2017 23:06:12 +0100 Subject: application: introduce the Shaarli\Config namespace Namespaces have been introduced with the REST API, and should be generalized to the whole codebase to manage object scope and benefit from autoloading. See: - https://secure.php.net/manual/en/language.namespaces.php - http://www.php-fig.org/psr/psr-4/ Signed-off-by: VirtualTam --- tests/Updater/UpdaterTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 39be88f9..448405a3 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -1,6 +1,8 @@ Date: Thu, 9 Mar 2017 20:51:28 +0100 Subject: Fix #773: set Piwik URL protocol --- tests/Updater/UpdaterTest.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 448405a3..b522d616 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -574,4 +574,45 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertTrue($updater->updateMethodEscapeMarkdown()); $this->assertFalse($this->conf->get('security.markdown_escape')); } + + /** + * Test updateMethodPiwikUrl with valid data + */ + public function testUpdatePiwikUrlValid() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $url = 'mypiwik.tld'; + $this->conf->set('plugins.PIWIK_URL', $url); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodPiwikUrl()); + $this->assertEquals('http://'. $url, $this->conf->get('plugins.PIWIK_URL')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertEquals('http://'. $url, $this->conf->get('plugins.PIWIK_URL')); + } + + /** + * Test updateMethodPiwikUrl without setting + */ + public function testUpdatePiwikUrlEmpty() + { + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodPiwikUrl()); + $this->assertEmpty($this->conf->get('plugins.PIWIK_URL')); + } + + /** + * Test updateMethodPiwikUrl: valid URL, nothing to do + */ + public function testUpdatePiwikUrlNothingToDo() + { + $url = 'https://mypiwik.tld'; + $this->conf->set('plugins.PIWIK_URL', $url); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodPiwikUrl()); + $this->assertEquals($url, $this->conf->get('plugins.PIWIK_URL')); + } } -- cgit v1.2.3 From 2ea89aba4faa5509ca68c7e9b6b9ab71c1929935 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 11 Mar 2017 14:11:06 +0100 Subject: Fixes #304: use atom feed as default RSS feed is still available with the setting set to false --- tests/Updater/UpdaterTest.php | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index b522d616..11b6444a 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -615,4 +615,49 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertTrue($updater->updateMethodPiwikUrl()); $this->assertEquals($url, $this->conf->get('plugins.PIWIK_URL')); } + + /** + * Test updateMethodAtomDefault with show_atom set to false + * => update to true. + */ + public function testUpdateMethodAtomDefault() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $this->conf->set('feed.show_atom', false); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodAtomDefault()); + $this->assertTrue($this->conf->get('feed.show_atom')); + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertTrue($this->conf->get('feed.show_atom')); + } + /** + * Test updateMethodAtomDefault with show_atom not set. + * => nothing to do + */ + public function testUpdateMethodAtomDefaultNoExist() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodAtomDefault()); + $this->assertTrue($this->conf->get('feed.show_atom')); + } + /** + * Test updateMethodAtomDefault with show_atom set to true. + * => nothing to do + */ + public function testUpdateMethodAtomDefaultAlreadyTrue() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $this->conf->set('feed.show_atom', true); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodAtomDefault()); + $this->assertTrue($this->conf->get('feed.show_atom')); + } } -- cgit v1.2.3 From 845810a8d3c2ad5836f12516a6f38e7720bb0f4d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 9 May 2017 18:22:31 +0200 Subject: Use the new 'default' theme... as default Fixes #866 --- tests/Updater/UpdaterTest.php | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'tests/Updater') diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 11b6444a..fed175df 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -469,46 +469,6 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; rmdir('sandbox/'. $theme); } - /** - * Test updateMethodDefaultThemeVintage with the default theme enabled. - */ - public function testSetDefaultThemeToVintage() - { - $sandboxConf = 'sandbox/config'; - copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); - $this->conf = new ConfigManager($sandboxConf); - - $this->conf->set('resource.theme', 'default'); - $updater = new Updater([], [], $this->conf, true); - $this->assertTrue($updater->updateMethodDefaultThemeVintage()); - $this->assertEquals('vintage', $this->conf->get('resource.theme')); - - // reload from file - $this->conf = new ConfigManager($sandboxConf); - $this->assertEquals('vintage', $this->conf->get('resource.theme')); - } - - /** - * Test updateMethodDefaultThemeVintage with custom theme enabled => nothing to do. - */ - public function testSetDefaultThemeNothingToDo() - { - $sandboxConf = 'sandbox/config'; - copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); - $this->conf = new ConfigManager($sandboxConf); - - $theme = 'myawesometheme'; - $this->conf->set('resource.theme', $theme); - $this->conf->write(true); - $updater = new Updater([], [], $this->conf, true); - $this->assertTrue($updater->updateMethodDefaultThemeVintage()); - $this->assertEquals($theme, $this->conf->get('resource.theme')); - - // reload from file - $this->conf = new ConfigManager($sandboxConf); - $this->assertEquals($theme, $this->conf->get('resource.theme')); - } - /** * Test updateMethodEscapeMarkdown with markdown plugin enabled * => setting markdown_escape set to false. -- cgit v1.2.3