From 88dc7f4199476adb0de748f1c7a58d3916493dfe Mon Sep 17 00:00:00 2001 From: Jonathan Labreuille Date: Tue, 21 Jun 2016 16:45:08 +0200 Subject: [PATCH 1/3] removing DKIM and useless classes --- assets/js/src/settings/tabs.js | 5 +- composer.lock | 83 ++++++++++--------- lib/Config/Menu.php | 16 ---- lib/Util/DKIM.php | 28 ------- lib/Util/Security.php | 8 +- lib/Util/Url.php | 3 - lib/WP/Option.php | 17 ---- .../Util/{UtilCSSTest.php => CSSTest.php} | 2 +- tests/unit/Util/SecurityTest.php | 32 +++++++ tests/unit/Util/UrlTest.php | 9 ++ tests/unit/Util/UtilDKIMTest.php | 17 ---- tests/unit/WP/DateTimeTest.php | 2 +- views/settings/mta.html | 81 ------------------ 13 files changed, 89 insertions(+), 214 deletions(-) delete mode 100644 lib/Util/DKIM.php delete mode 100644 lib/WP/Option.php rename tests/unit/Util/{UtilCSSTest.php => CSSTest.php} (79%) create mode 100644 tests/unit/Util/SecurityTest.php create mode 100644 tests/unit/Util/UrlTest.php delete mode 100644 tests/unit/Util/UtilDKIMTest.php diff --git a/assets/js/src/settings/tabs.js b/assets/js/src/settings/tabs.js index a851fb215d..79fade136a 100644 --- a/assets/js/src/settings/tabs.js +++ b/assets/js/src/settings/tabs.js @@ -34,16 +34,13 @@ define( // show sending methods jQuery('.mailpoet_sending_methods').fadeIn(); } else { - // toggle SPF/DKIM (hidden if the sending method is MailPoet) + // toggle SPF (hidden if the sending method is MailPoet) jQuery('#mailpoet_mta_spf')[ (group === 'mailpoet') ? 'hide' : 'show' ](); - // (HIDDEN FOR BETA) - jQuery('#mailpoet_mta_dkim').hide(); - // hide sending methods jQuery('.mailpoet_sending_methods').hide(); diff --git a/composer.lock b/composer.lock index 2c4b1bc658..3461e0d07e 100644 --- a/composer.lock +++ b/composer.lock @@ -1847,16 +1847,16 @@ }, { "name": "phpunit/phpunit", - "version": "5.4.4", + "version": "5.4.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "02d5b64aa0837a038a5a4faeeefa5ef44bdcb928" + "reference": "2f1fc94b77ea6418bd6a06c64a1dac0645fbce59" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/02d5b64aa0837a038a5a4faeeefa5ef44bdcb928", - "reference": "02d5b64aa0837a038a5a4faeeefa5ef44bdcb928", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2f1fc94b77ea6418bd6a06c64a1dac0645fbce59", + "reference": "2f1fc94b77ea6418bd6a06c64a1dac0645fbce59", "shasum": "" }, "require": { @@ -1875,7 +1875,7 @@ "phpunit/phpunit-mock-objects": "^3.2", "sebastian/comparator": "~1.1", "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", + "sebastian/environment": "^1.3 || ^2.0", "sebastian/exporter": "~1.2", "sebastian/global-state": "~1.0", "sebastian/object-enumerator": "~1.0", @@ -1921,7 +1921,7 @@ "testing", "xunit" ], - "time": "2016-06-09 09:09:27" + "time": "2016-06-16 06:01:15" }, { "name": "phpunit/phpunit-mock-objects", @@ -2295,16 +2295,16 @@ }, { "name": "sebastian/exporter", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e" + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", "shasum": "" }, "require": { @@ -2312,12 +2312,13 @@ "sebastian/recursion-context": "~1.0" }, "require-dev": { + "ext-mbstring": "*", "phpunit/phpunit": "~4.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { @@ -2357,7 +2358,7 @@ "export", "exporter" ], - "time": "2015-06-21 07:55:53" + "time": "2016-06-17 09:04:28" }, { "name": "sebastian/global-state", @@ -2596,7 +2597,7 @@ }, { "name": "symfony/browser-kit", - "version": "v3.1.0", + "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/symfony/browser-kit.git", @@ -2706,16 +2707,16 @@ }, { "name": "symfony/console", - "version": "v3.1.0", + "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "f62db5b8afec27073a4609b8c84b1f9936652259" + "reference": "64a4d43b045f07055bb197650159769604cb2a92" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/f62db5b8afec27073a4609b8c84b1f9936652259", - "reference": "f62db5b8afec27073a4609b8c84b1f9936652259", + "url": "https://api.github.com/repos/symfony/console/zipball/64a4d43b045f07055bb197650159769604cb2a92", + "reference": "64a4d43b045f07055bb197650159769604cb2a92", "shasum": "" }, "require": { @@ -2762,20 +2763,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-05-30 06:58:39" + "time": "2016-06-14 11:18:07" }, { "name": "symfony/css-selector", - "version": "v3.1.0", + "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "e17f386efef7258ac671c24e727673abd086b0cf" + "reference": "c526d7b3cb4fe1673c6a34e13be2ff63f519df99" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/e17f386efef7258ac671c24e727673abd086b0cf", - "reference": "e17f386efef7258ac671c24e727673abd086b0cf", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/c526d7b3cb4fe1673c6a34e13be2ff63f519df99", + "reference": "c526d7b3cb4fe1673c6a34e13be2ff63f519df99", "shasum": "" }, "require": { @@ -2815,11 +2816,11 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2016-03-04 07:56:56" + "time": "2016-06-06 11:42:41" }, { "name": "symfony/dom-crawler", - "version": "v3.1.0", + "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", @@ -2984,7 +2985,7 @@ }, { "name": "symfony/finder", - "version": "v3.1.0", + "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -3294,16 +3295,16 @@ }, { "name": "symfony/process", - "version": "v3.1.0", + "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "1574f3451b40fa9bbae518ef71d19a56f409cac0" + "reference": "6350e63ed9c232da50e00f00a7e0330f066387a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/1574f3451b40fa9bbae518ef71d19a56f409cac0", - "reference": "1574f3451b40fa9bbae518ef71d19a56f409cac0", + "url": "https://api.github.com/repos/symfony/process/zipball/6350e63ed9c232da50e00f00a7e0330f066387a2", + "reference": "6350e63ed9c232da50e00f00a7e0330f066387a2", "shasum": "" }, "require": { @@ -3339,7 +3340,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-04-12 19:11:33" + "time": "2016-06-06 11:42:41" }, { "name": "symfony/property-access", @@ -3559,16 +3560,16 @@ }, { "name": "symfony/yaml", - "version": "v3.1.0", + "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "eca51b7b65eb9be6af88ad7cc91685f1556f5c9a" + "reference": "c5a7e7fc273c758b92b85dcb9c46149ccda89623" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/eca51b7b65eb9be6af88ad7cc91685f1556f5c9a", - "reference": "eca51b7b65eb9be6af88ad7cc91685f1556f5c9a", + "url": "https://api.github.com/repos/symfony/yaml/zipball/c5a7e7fc273c758b92b85dcb9c46149ccda89623", + "reference": "c5a7e7fc273c758b92b85dcb9c46149ccda89623", "shasum": "" }, "require": { @@ -3604,7 +3605,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-05-26 21:46:24" + "time": "2016-06-14 11:18:07" }, { "name": "twig/extensions", @@ -3709,16 +3710,16 @@ }, { "name": "vlucas/phpdotenv", - "version": "v2.2.1", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "63f37b9395e8041cd4313129c08ece896d06ca8e" + "reference": "9ca5644c536654e9509b9d257f53c58630eb2a6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/63f37b9395e8041cd4313129c08ece896d06ca8e", - "reference": "63f37b9395e8041cd4313129c08ece896d06ca8e", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/9ca5644c536654e9509b9d257f53c58630eb2a6a", + "reference": "9ca5644c536654e9509b9d257f53c58630eb2a6a", "shasum": "" }, "require": { @@ -3730,7 +3731,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-master": "2.3-dev" } }, "autoload": { @@ -3755,7 +3756,7 @@ "env", "environment" ], - "time": "2016-04-15 10:48:49" + "time": "2016-06-14 14:14:52" }, { "name": "webmozart/assert", diff --git a/lib/Config/Menu.php b/lib/Config/Menu.php index 06b545704d..9f437970d8 100644 --- a/lib/Config/Menu.php +++ b/lib/Config/Menu.php @@ -12,7 +12,6 @@ use MailPoet\Settings\Charsets; use MailPoet\Settings\Hosts; use MailPoet\Settings\Pages; use MailPoet\Subscribers\ImportExport\ImportExportFactory; -use MailPoet\Util\DKIM; use MailPoet\Util\Permissions; use MailPoet\Listing; use MailPoet\WP\DateTime; @@ -294,21 +293,6 @@ class Menu { $settings = Setting::getAll(); $flags = $this->_getFlags(); - // dkim: check if public/private keys have been generated - if( - empty($settings['dkim']) - or empty($settings['dkim']['public_key']) - or empty($settings['dkim']['private_key']) - ) { - // generate public/private keys - $keys = DKIM::generateKeys(); - $settings['dkim'] = array( - 'public_key' => $keys['public'], - 'private_key' => $keys['private'], - 'domain' => preg_replace('/^www\./', '', $_SERVER['SERVER_NAME']) - ); - } - $data = array( 'settings' => $settings, 'segments' => Segment::getPublic()->findArray(), diff --git a/lib/Util/DKIM.php b/lib/Util/DKIM.php deleted file mode 100644 index 75c5e63ca0..0000000000 --- a/lib/Util/DKIM.php +++ /dev/null @@ -1,28 +0,0 @@ -createKey(); - - return array( - 'public' => self::trimKey($rsa_keys['publickey']), - 'private' => self::trimKey($rsa_keys['privatekey']) - ); - } catch(\Exception $e) { - return false; - } - } - - private static function trimKey($key) { - $lines = explode("\n", trim($key)); - // remove first line - array_shift($lines); - // remove last line - array_pop($lines); - return join('', $lines); - } -} \ No newline at end of file diff --git a/lib/Util/Security.php b/lib/Util/Security.php index 72ea638fd7..177eb04729 100644 --- a/lib/Util/Security.php +++ b/lib/Util/Security.php @@ -11,11 +11,9 @@ class Security { static function generateRandomString($length = 5) { // non-cryptographically strong random generator return substr( - md5( - uniqid( - mt_rand(), true) - ), + md5(uniqid(mt_rand(), true)), 0, - (!is_int($length) || $length <= 5 || $length >= 32) ? 5 : $length); + min(max(5, (int)$length), 32) + ); } } \ No newline at end of file diff --git a/lib/Util/Url.php b/lib/Util/Url.php index 5d7d34bbd7..4036383889 100644 --- a/lib/Util/Url.php +++ b/lib/Util/Url.php @@ -2,9 +2,6 @@ namespace MailPoet\Util; class Url { - function __construct() { - } - static function getCurrentUrl() { return home_url(add_query_arg(null, null)); } diff --git a/lib/WP/Option.php b/lib/WP/Option.php deleted file mode 100644 index a77d9c8227..0000000000 --- a/lib/WP/Option.php +++ /dev/null @@ -1,17 +0,0 @@ -prefix = 'mailpoet_'; - } - - function get($name) { - return get_option($this->prefix . $name); - } - - function set($name, $value) { - return update_option($this->prefix .$name, $value); - } -} diff --git a/tests/unit/Util/UtilCSSTest.php b/tests/unit/Util/CSSTest.php similarity index 79% rename from tests/unit/Util/UtilCSSTest.php rename to tests/unit/Util/CSSTest.php index c2d0d662a3..8c3be85172 100644 --- a/tests/unit/Util/UtilCSSTest.php +++ b/tests/unit/Util/CSSTest.php @@ -1,6 +1,6 @@ css = new \MailPoet\Util\CSS(); } diff --git a/tests/unit/Util/SecurityTest.php b/tests/unit/Util/SecurityTest.php new file mode 100644 index 0000000000..da7ba6fd97 --- /dev/null +++ b/tests/unit/Util/SecurityTest.php @@ -0,0 +1,32 @@ +equals(10); + // expect only alphanumerical characters + expect(ctype_alnum($wp_nonce))->true(); + } + + function testItCanGenerateARandomString() { + // it has a default length of 5 + $hash = Security::generateRandomString(); + expect(strlen($hash))->equals(5); + + // it has a min length of 5 + $short_hash = Security::generateRandomString(1); + expect(strlen($short_hash))->equals(5); + + // it has a max length of 32 + $long_hash = Security::generateRandomString(64); + expect(strlen($long_hash))->equals(32); + + // expect only alphanumerical characters + expect(ctype_alnum($hash))->true(); + expect(ctype_alnum($short_hash))->true(); + expect(ctype_alnum($long_hash))->true(); + } +} \ No newline at end of file diff --git a/tests/unit/Util/UrlTest.php b/tests/unit/Util/UrlTest.php new file mode 100644 index 0000000000..8333707215 --- /dev/null +++ b/tests/unit/Util/UrlTest.php @@ -0,0 +1,9 @@ +startsWith('http'); + } +} \ No newline at end of file diff --git a/tests/unit/Util/UtilDKIMTest.php b/tests/unit/Util/UtilDKIMTest.php deleted file mode 100644 index 2e4dd7fb84..0000000000 --- a/tests/unit/Util/UtilDKIMTest.php +++ /dev/null @@ -1,17 +0,0 @@ -notEmpty(); - expect($keys['private'])->notEmpty(); - - expect($keys['public'])->notContains($public_header); - expect($keys['private'])->notContains($private_header); - } -} diff --git a/tests/unit/WP/DateTimeTest.php b/tests/unit/WP/DateTimeTest.php index 2620de3735..41878811cd 100644 --- a/tests/unit/WP/DateTimeTest.php +++ b/tests/unit/WP/DateTimeTest.php @@ -77,6 +77,6 @@ class DateTimeTest extends MailPoetTest { } function _afterStep() { - WordPress::releaseAllFunctions(); + WordPressHelper::releaseAllFunctions(); } } diff --git a/views/settings/mta.html b/views/settings/mta.html index 365ad74daa..8a8daf1b4c 100644 --- a/views/settings/mta.html +++ b/views/settings/mta.html @@ -38,23 +38,6 @@ name="mta[frequency][interval]" value="<%= settings.mta.frequency.interval %>" /> - - - - -