JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

[5.0] Remove outdated captcha for new installation #407

Closed joomlapl-bot closed 7 months ago

joomlapl-bot commented 1 year ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/41530 Poniżej zmiany w oryginale:

Click to expand the diff! ```diff diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index b203c6eac6cb2..83f6a49785763 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -231,6 +231,7 @@ protected function uninstallExtensions() */ ['type' => 'plugin', 'element' => 'demotasks', 'folder' => 'task', 'client_id' => 0, 'pre_function' => null], ['type' => 'plugin', 'element' => 'compat', 'folder' => 'system', 'client_id' => 0, 'pre_function' => 'migrateCompatPlugin'], + ['type' => 'plugin', 'element' => 'recaptcha', 'folder' => 'captcha', 'client_id' => 0, 'pre_function' => null], ]; $db = Factory::getDbo(); diff --git a/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-08-30.sql b/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-08-30.sql new file mode 100644 index 0000000000000..8b144004d1147 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-08-30.sql @@ -0,0 +1,3 @@ +UPDATE `#__extensions` + SET `locked` = 0 + WHERE `type` = 'plugin' AND `element` = 'recaptcha_invisible' AND `folder` = 'captcha'; diff --git a/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-08-30.sql b/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-08-30.sql new file mode 100644 index 0000000000000..6cdba7c66ee3c --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-08-30.sql @@ -0,0 +1,3 @@ +UPDATE "#__extensions" + SET "locked" = 0 + WHERE "type" = 'plugin' AND "element" = 'recaptcha_invisible' AND "folder" = 'captcha'; diff --git a/administrator/language/en-GB/plg_captcha_recaptcha.ini b/administrator/language/en-GB/plg_captcha_recaptcha.ini deleted file mode 100644 index 7a58d08416895..0000000000000 --- a/administrator/language/en-GB/plg_captcha_recaptcha.ini +++ /dev/null @@ -1,30 +0,0 @@ -; Joomla! Project -; (C) 2011 Open Source Matters, Inc. -; License GNU General Public License version 2 or later; see LICENSE.txt -; Note : All ini files need to be saved as UTF-8 - -PLG_CAPTCHA_RECAPTCHA="CAPTCHA - reCAPTCHA" -PLG_CAPTCHA_RECAPTCHA_XML_DESCRIPTION="This CAPTCHA plugin uses the reCAPTCHA service to prevent spammers while it helps to digitize books, newspapers and old radio shows. To get a site and secret key for your domain, go to https://www.google.com/recaptcha. To use this for new account registration, go to Options in the User Manager and select CAPTCHA - reCAPTCHA as the CAPTCHA." -PLG_RECAPTCHA_CALLBACK_DESC="(Optional) JavaScript callback, executed after successful reCAPTCHA response." -PLG_RECAPTCHA_CALLBACK_LABEL="Callback" -PLG_RECAPTCHA_ERROR_CALLBACK_DESC="(Optional) JavaScript callback, executed when the reCAPTCHA encounters an error." -PLG_RECAPTCHA_ERROR_CALLBACK_LABEL="Error Callback" -PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION="Please complete the CAPTCHA." -PLG_RECAPTCHA_ERROR_NO_IP="For security reasons, you must pass the remote IP address to reCAPTCHA." -PLG_RECAPTCHA_ERROR_NO_PRIVATE_KEY="reCAPTCHA plugin needs a secret key to be set in its parameters. Please contact a site administrator." -PLG_RECAPTCHA_ERROR_NO_PUBLIC_KEY="reCAPTCHA plugin needs a site key to be set in its parameters. Please contact a site administrator." -PLG_RECAPTCHA_EXPIRED_CALLBACK_DESC="(Optional) JavaScript callback, executed when the reCAPTCHA expired." -PLG_RECAPTCHA_EXPIRED_CALLBACK_LABEL="Expired Callback" -PLG_RECAPTCHA_PRIVACY_CAPABILITY_IP_ADDRESS="The reCAPTCHA plugin integrates with Google's reCAPTCHA system as a spam protection service. As part of this service, the IP address of the user answering the captcha challenge is transmitted to Google." -PLG_RECAPTCHA_PRIVATE_KEY_LABEL="Secret Key" -PLG_RECAPTCHA_PUBLIC_KEY_LABEL="Site Key" -PLG_RECAPTCHA_SIZE_LABEL="Size" -PLG_RECAPTCHA_TABINDEX_DESC="The tabindex of the reCAPTCHA widget." -PLG_RECAPTCHA_TABINDEX_LABEL="Tabindex" -PLG_RECAPTCHA_THEME_COMPACT="Compact" -PLG_RECAPTCHA_THEME_DARK="Dark" -PLG_RECAPTCHA_THEME_LABEL="Theme" -PLG_RECAPTCHA_THEME_LIGHT="Light" -PLG_RECAPTCHA_THEME_NORMAL="Normal" -PLG_RECAPTCHA_VERSION_LABEL="Version" -PLG_RECAPTCHA_VERSION_V2="2.0" diff --git a/administrator/language/en-GB/plg_captcha_recaptcha.sys.ini b/administrator/language/en-GB/plg_captcha_recaptcha.sys.ini deleted file mode 100644 index d639ba46ba74c..0000000000000 --- a/administrator/language/en-GB/plg_captcha_recaptcha.sys.ini +++ /dev/null @@ -1,7 +0,0 @@ -; Joomla! Project -; (C) 2011 Open Source Matters, Inc. -; License GNU General Public License version 2 or later; see LICENSE.txt -; Note : All ini files need to be saved as UTF-8 - -PLG_CAPTCHA_RECAPTCHA="CAPTCHA - reCAPTCHA" -PLG_CAPTCHA_RECAPTCHA_XML_DESCRIPTION="This CAPTCHA plugin uses the reCAPTCHA service to prevent spammers while it helps to digitize books, newspapers and old radio shows. To get a site and secret key for your domain, go to https://www.google.com/recaptcha. To use this for new account registration, go to Options in the User Manager and select CAPTCHA - reCAPTCHA as the CAPTCHA." diff --git a/administrator/language/en-GB/plg_captcha_recaptcha_invisible.ini b/administrator/language/en-GB/plg_captcha_recaptcha_invisible.ini deleted file mode 100644 index 7ce712231dd2a..0000000000000 --- a/administrator/language/en-GB/plg_captcha_recaptcha_invisible.ini +++ /dev/null @@ -1,29 +0,0 @@ -; Joomla! Project -; (C) 2018 Open Source Matters, Inc. -; License GNU General Public License version 2 or later; see LICENSE.txt -; Note : All ini files need to be saved as UTF-8 - -PLG_CAPTCHA_RECAPTCHA_INVISIBLE="CAPTCHA - Invisible reCAPTCHA" -PLG_CAPTCHA_RECAPTCHA_INVISIBLE_XML_DESCRIPTION="This CAPTCHA plugin uses the Invisible reCAPTCHA service. To get a site and secret key for your domain, go to https://www.google.com/recaptcha." -PLG_RECAPTCHA_INVISIBLE_BADGE_BOTTOMLEFT="Bottom left" -PLG_RECAPTCHA_INVISIBLE_BADGE_BOTTOMRIGHT="Bottom right" -PLG_RECAPTCHA_INVISIBLE_BADGE_DESC="Positioning of the reCAPTCHA badge." -PLG_RECAPTCHA_INVISIBLE_BADGE_INLINE="Inline" -PLG_RECAPTCHA_INVISIBLE_BADGE_LABEL="Badge" -PLG_RECAPTCHA_INVISIBLE_CALLBACK_DESC="(Optional) JavaScript callback, executed after successful reCAPTCHA response." -PLG_RECAPTCHA_INVISIBLE_CALLBACK_LABEL="Callback" -PLG_RECAPTCHA_INVISIBLE_ERROR_CALLBACK_DESC="(Optional) JavaScript callback, executed when the reCAPTCHA encounters an error." -PLG_RECAPTCHA_INVISIBLE_ERROR_CALLBACK_LABEL="Error Callback" -PLG_RECAPTCHA_INVISIBLE_ERROR_EMPTY_SOLUTION="Empty solution not allowed." -PLG_RECAPTCHA_INVISIBLE_ERROR_NO_IP="For security reasons, you must pass the remote IP address to reCAPTCHA." -PLG_RECAPTCHA_INVISIBLE_ERROR_NO_PRIVATE_KEY="reCAPTCHA plugin needs a secret key to be set in its parameters. Please contact a site administrator." -PLG_RECAPTCHA_INVISIBLE_ERROR_NO_PUBLIC_KEY="reCAPTCHA plugin needs a site key to be set in its parameters. Please contact a site administrator." -PLG_RECAPTCHA_INVISIBLE_EXPIRED_CALLBACK_DESC="(Optional) JavaScript callback, executed when the reCAPTCHA expired." -PLG_RECAPTCHA_INVISIBLE_EXPIRED_CALLBACK_LABEL="Expired Callback" -PLG_RECAPTCHA_INVISIBLE_PRIVACY_CAPABILITY_IP_ADDRESS="The Invisible reCAPTCHA plugin integrates with Google's reCAPTCHA system as a spam protection service. As part of this service, the IP address of the user answering the captcha challenge is transmitted to Google." -PLG_RECAPTCHA_INVISIBLE_PRIVATE_KEY_DESC="Used in the communication between your server and the reCAPTCHA server. Be sure to keep it a secret." -PLG_RECAPTCHA_INVISIBLE_PRIVATE_KEY_LABEL="Secret Key" -PLG_RECAPTCHA_INVISIBLE_PUBLIC_KEY_DESC="Used in the JavaScript code that is served to your users." -PLG_RECAPTCHA_INVISIBLE_PUBLIC_KEY_LABEL="Site Key" -PLG_RECAPTCHA_INVISIBLE_TABINDEX_DESC="The tabindex of the challenge." -PLG_RECAPTCHA_INVISIBLE_TABINDEX_LABEL="Tabindex" diff --git a/administrator/language/en-GB/plg_captcha_recaptcha_invisible.sys.ini b/administrator/language/en-GB/plg_captcha_recaptcha_invisible.sys.ini deleted file mode 100644 index e4416144b6f2b..0000000000000 --- a/administrator/language/en-GB/plg_captcha_recaptcha_invisible.sys.ini +++ /dev/null @@ -1,7 +0,0 @@ -; Joomla! Project -; (C) 2018 Open Source Matters, Inc. -; License GNU General Public License version 2 or later; see LICENSE.txt -; Note : All ini files need to be saved as UTF-8 - -PLG_CAPTCHA_RECAPTCHA_INVISIBLE="CAPTCHA - Invisible reCAPTCHA" -PLG_CAPTCHA_RECAPTCHA_INVISIBLE_XML_DESCRIPTION="This CAPTCHA plugin uses the Invisible reCAPTCHA service. To get a site and secret key for your domain, go to https://www.google.com/recaptcha." diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index dabb7df1d50e2..83570fa9b5bb7 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -261,8 +261,6 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_behaviour_compat', 'plugin', 'compat', 'behaviour', 0, 0, 1, 0, 1, '', '{"classes_aliases":"1","es5_assets":"1"}', '', 1, 0), (0, 'plg_behaviour_taggable', 'plugin', 'taggable', 'behaviour', 0, 1, 1, 0, 1, '', '{}', '', 2, 0), (0, 'plg_behaviour_versionable', 'plugin', 'versionable', 'behaviour', 0, 1, 1, 0, 1, '', '{}', '', 3, 0), -(0, 'plg_captcha_recaptcha', 'plugin', 'recaptcha', 'captcha', 0, 0, 1, 0, 1, '', '{"public_key":"","private_key":"","theme":"clean"}', '', 1, 0), -(0, 'plg_captcha_recaptcha_invisible', 'plugin', 'recaptcha_invisible', 'captcha', 0, 0, 1, 0, 1, '', '{"public_key":"","private_key":"","theme":"clean"}', '', 2, 0), (0, 'plg_content_confirmconsent', 'plugin', 'confirmconsent', 'content', 0, 0, 1, 0, 1, '', '{}', '', 1, 0), (0, 'plg_content_contact', 'plugin', 'contact', 'content', 0, 1, 1, 0, 1, '', '', '', 2, 0), (0, 'plg_content_emailcloak', 'plugin', 'emailcloak', 'content', 0, 1, 1, 0, 1, '', '{"mode":"1"}', '', 3, 0), diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index ad499e6738bc5..3024bf2fa5660 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -267,8 +267,6 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_behaviour_compat', 'plugin', 'compat', 'behaviour', 0, 0, 1, 0, 1, '', '{"classes_aliases":"1","es5_assets":"1"}', '', 1, 0), (0, 'plg_behaviour_taggable', 'plugin', 'taggable', 'behaviour', 0, 1, 1, 0, 1, '', '{}', '', 2, 0), (0, 'plg_behaviour_versionable', 'plugin', 'versionable', 'behaviour', 0, 1, 1, 0, 1, '', '{}', '', 3, 0), -(0, 'plg_captcha_recaptcha', 'plugin', 'recaptcha', 'captcha', 0, 0, 1, 0, 1, '', '{"public_key":"","private_key":"","theme":"clean"}', '', 1, 0), -(0, 'plg_captcha_recaptcha_invisible', 'plugin', 'recaptcha_invisible', 'captcha', 0, 0, 1, 0, 1, '', '{"public_key":"","private_key":"","theme":"clean"}', '', 2, 0), (0, 'plg_content_confirmconsent', 'plugin', 'confirmconsent', 'content', 0, 0, 1, 0, 1, '', '{}', '', 1, 0), (0, 'plg_content_contact', 'plugin', 'contact', 'content', 0, 1, 1, 0, 1, '', '', '', 2, 0), (0, 'plg_content_emailcloak', 'plugin', 'emailcloak', 'content', 0, 1, 1, 0, 1, '', '{"mode":"1"}', '', 3, 0), diff --git a/plugins/captcha/index.html b/plugins/captcha/index.html new file mode 100644 index 0000000000000..2efb97f319a35 --- /dev/null +++ b/plugins/captcha/index.html @@ -0,0 +1 @@ + diff --git a/plugins/captcha/recaptcha/recaptcha.xml b/plugins/captcha/recaptcha/recaptcha.xml deleted file mode 100644 index 48859249ebdc8..0000000000000 --- a/plugins/captcha/recaptcha/recaptcha.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - plg_captcha_recaptcha - 3.4.0 - 2011-12 - Joomla! Project - admin@joomla.org - www.joomla.org - (C) 2011 Open Source Matters, Inc. - GNU General Public License version 2 or later; see LICENSE.txt - PLG_CAPTCHA_RECAPTCHA_XML_DESCRIPTION - Joomla\Plugin\Captcha\ReCaptcha - - services - src - - - language/en-GB/plg_captcha_recaptcha.ini - language/en-GB/plg_captcha_recaptcha.sys.ini - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
diff --git a/plugins/captcha/recaptcha/services/provider.php b/plugins/captcha/recaptcha/services/provider.php deleted file mode 100644 index b93654389f3d8..0000000000000 --- a/plugins/captcha/recaptcha/services/provider.php +++ /dev/null @@ -1,48 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\Captcha\Google\HttpBridgePostRequestMethod; -use Joomla\CMS\Extension\PluginInterface; -use Joomla\CMS\Factory; -use Joomla\CMS\Plugin\PluginHelper; -use Joomla\DI\Container; -use Joomla\DI\ServiceProviderInterface; -use Joomla\Event\DispatcherInterface; -use Joomla\Plugin\Captcha\ReCaptcha\Extension\ReCaptcha; - -return new class () implements ServiceProviderInterface { - /** - * Registers the service provider with a DI container. - * - * @param Container $container The DI container. - * - * @return void - * - * @since 4.3.0 - */ - public function register(Container $container) - { - $container->set( - PluginInterface::class, - function (Container $container) { - $plugin = new ReCaptcha( - $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('captcha', 'recaptcha'), - new HttpBridgePostRequestMethod() - ); - $plugin->setApplication(Factory::getApplication()); - - return $plugin; - } - ); - } -}; diff --git a/plugins/captcha/recaptcha/src/Extension/ReCaptcha.php b/plugins/captcha/recaptcha/src/Extension/ReCaptcha.php deleted file mode 100644 index f1f661f74257a..0000000000000 --- a/plugins/captcha/recaptcha/src/Extension/ReCaptcha.php +++ /dev/null @@ -1,223 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\Plugin\Captcha\ReCaptcha\Extension; - -use Joomla\CMS\Application\CMSWebApplicationInterface; -use Joomla\CMS\Plugin\CMSPlugin; -use Joomla\Event\DispatcherInterface; -use Joomla\Utilities\IpHelper; -use ReCaptcha\ReCaptcha as Captcha; -use ReCaptcha\RequestMethod; - -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - -/** - * Recaptcha Plugin - * Based on the official recaptcha library( https://packagist.org/packages/google/recaptcha ) - * - * @since 2.5 - */ -final class ReCaptcha extends CMSPlugin -{ - /** - * Load the language file on instantiation. - * - * @var boolean - * @since 3.1 - */ - protected $autoloadLanguage = true; - - /** - * The http request method - * - * @var RequestMethod - * @since 4.3.0 - */ - private $requestMethod; - - /** - * Constructor. - * - * @param DispatcherInterface $dispatcher The dispatcher - * @param array $config An optional associative array of configuration settings - * @param RequestMethod $requestMethod The http request method - * - * @since 4.3.0 - */ - public function __construct(DispatcherInterface $dispatcher, array $config, RequestMethod $requestMethod) - { - parent::__construct($dispatcher, $config); - - $this->requestMethod = $requestMethod; - } - - /** - * Reports the privacy related capabilities for this plugin to site administrators. - * - * @return array - * - * @since 3.9.0 - */ - public function onPrivacyCollectAdminCapabilities() - { - return [ - $this->getApplication()->getLanguage()->_('PLG_CAPTCHA_RECAPTCHA') => [ - $this->getApplication()->getLanguage()->_('PLG_RECAPTCHA_PRIVACY_CAPABILITY_IP_ADDRESS'), - ], - ]; - } - - /** - * Initializes the captcha - * - * @param string $id The id of the field. - * - * @return Boolean True on success, false otherwise - * - * @since 2.5 - * @throws \RuntimeException - */ - public function onInit($id = 'dynamic_recaptcha_1') - { - $app = $this->getApplication(); - - if (!$app instanceof CMSWebApplicationInterface) { - return false; - } - - $pubkey = $this->params->get('public_key', ''); - - if ($pubkey === '') { - throw new \RuntimeException($app->getLanguage()->_('PLG_RECAPTCHA_ERROR_NO_PUBLIC_KEY')); - } - - $apiSrc = 'https://www.google.com/recaptcha/api.js?onload=JoomlainitReCaptcha2&render=explicit&hl=' - . $app->getLanguage()->getTag(); - - // Load assets, the callback should be first - $app->getDocument()->getWebAssetManager() - ->registerAndUseScript('plg_captcha_recaptcha', 'plg_captcha_recaptcha/recaptcha.min.js', [], ['defer' => true]) - ->registerAndUseScript('plg_captcha_recaptcha.api', $apiSrc, [], ['defer' => true], ['plg_captcha_recaptcha']); - - return true; - } - - /** - * Gets the challenge HTML - * - * @param string $name The name of the field. Not Used. - * @param string $id The id of the field. - * @param string $class The class of the field. - * - * @return string The HTML to be embedded in the form. - * - * @since 2.5 - */ - public function onDisplay($name = null, $id = 'dynamic_recaptcha_1', $class = '') - { - $dom = new \DOMDocument('1.0', 'UTF-8'); - $ele = $dom->createElement('div'); - $ele->setAttribute('id', $id); - - $ele->setAttribute('class', ((trim($class) == '') ? 'g-recaptcha' : ($class . ' g-recaptcha'))); - $ele->setAttribute('data-sitekey', $this->params->get('public_key', '')); - $ele->setAttribute('data-theme', $this->params->get('theme2', 'light')); - $ele->setAttribute('data-size', $this->params->get('size', 'normal')); - $ele->setAttribute('data-tabindex', $this->params->get('tabindex', '0')); - $ele->setAttribute('data-callback', $this->params->get('callback', '')); - $ele->setAttribute('data-expired-callback', $this->params->get('expired_callback', '')); - $ele->setAttribute('data-error-callback', $this->params->get('error_callback', '')); - - $dom->appendChild($ele); - - return $dom->saveHTML($ele); - } - - /** - * Calls an HTTP POST function to verify if the user's guess was correct - * - * @param string $code Answer provided by user. Not needed for the Recaptcha implementation - * - * @return True if the answer is correct, false otherwise - * - * @since 2.5 - * @throws \RuntimeException - */ - public function onCheckAnswer($code = null) - { - $input = $this->getApplication()->getInput(); - $privatekey = $this->params->get('private_key'); - $version = $this->params->get('version', '2.0'); - $remoteip = IpHelper::getIp(); - $response = null; - $spam = false; - - switch ($version) { - case '2.0': - $response = $code ?: $input->get('g-recaptcha-response', '', 'string'); - $spam = ($response === ''); - break; - } - - // Check for Private Key - if (empty($privatekey)) { - throw new \RuntimeException($this->getApplication()->getLanguage()->_('PLG_RECAPTCHA_ERROR_NO_PRIVATE_KEY'), 500); - } - - // Check for IP - if (empty($remoteip)) { - throw new \RuntimeException($this->getApplication()->getLanguage()->_('PLG_RECAPTCHA_ERROR_NO_IP'), 500); - } - - // Discard spam submissions - if ($spam) { - throw new \RuntimeException($this->getApplication()->getLanguage()->_('PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION'), 500); - } - - return $this->getResponse($privatekey, $remoteip, $response); - } - - /** - * Get the reCaptcha response. - * - * @param string $privatekey The private key for authentication. - * @param string $remoteip The remote IP of the visitor. - * @param string $response The response received from Google. - * - * @return bool True if response is good | False if response is bad. - * - * @since 3.4 - * @throws \RuntimeException - */ - private function getResponse(string $privatekey, string $remoteip, string $response) - { - $version = $this->params->get('version', '2.0'); - - switch ($version) { - case '2.0': - $apiResponse = (new Captcha($privatekey, $this->requestMethod))->verify($response, $remoteip); - - if (!$apiResponse->isSuccess()) { - foreach ($apiResponse->getErrorCodes() as $error) { - throw new \RuntimeException($error, 403); - } - - return false; - } - - break; - } - - return true; - } -} diff --git a/plugins/captcha/recaptcha_invisible/recaptcha_invisible.xml b/plugins/captcha/recaptcha_invisible/recaptcha_invisible.xml deleted file mode 100644 index d3480198a6d8d..0000000000000 --- a/plugins/captcha/recaptcha_invisible/recaptcha_invisible.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - plg_captcha_recaptcha_invisible - 3.8 - 2017-11 - Joomla! Project - admin@joomla.org - www.joomla.org - (C) 2017 Open Source Matters, Inc. - GNU General Public License version 2 or later; see LICENSE.txt - PLG_CAPTCHA_RECAPTCHA_INVISIBLE_XML_DESCRIPTION - Joomla\Plugin\Captcha\InvisibleReCaptcha - - services - src - - - language/en-GB/plg_captcha_recaptcha_invisible.ini - language/en-GB/plg_captcha_recaptcha_invisible.sys.ini - - - -
- - - - - - - - - - - - - - - - - - -
-
-
-
diff --git a/plugins/captcha/recaptcha_invisible/services/provider.php b/plugins/captcha/recaptcha_invisible/services/provider.php deleted file mode 100644 index 1d0bcbb820135..0000000000000 --- a/plugins/captcha/recaptcha_invisible/services/provider.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\Extension\PluginInterface; -use Joomla\CMS\Factory; -use Joomla\CMS\Plugin\PluginHelper; -use Joomla\DI\Container; -use Joomla\DI\ServiceProviderInterface; -use Joomla\Event\DispatcherInterface; -use Joomla\Plugin\Captcha\InvisibleReCaptcha\Extension\InvisibleReCaptcha; - -return new class () implements ServiceProviderInterface { - /** - * Registers the service provider with a DI container. - * - * @param Container $container The DI container. - * - * @return void - * - * @since 4.3.0 - */ - public function register(Container $container) - { - $container->set( - PluginInterface::class, - function (Container $container) { - $dispatcher = $container->get(DispatcherInterface::class); - $plugin = new InvisibleReCaptcha( - $dispatcher, - (array) PluginHelper::getPlugin('captcha', 'recaptcha_invisible'), - ); - $plugin->setApplication(Factory::getApplication()); - - return $plugin; - } - ); - } -}; diff --git a/plugins/captcha/recaptcha_invisible/src/Extension/InvisibleReCaptcha.php b/plugins/captcha/recaptcha_invisible/src/Extension/InvisibleReCaptcha.php index e4694822e07f6..e69de29bb2d1d 100644 --- a/plugins/captcha/recaptcha_invisible/src/Extension/InvisibleReCaptcha.php +++ b/plugins/captcha/recaptcha_invisible/src/Extension/InvisibleReCaptcha.php @@ -1,78 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\Plugin\Captcha\InvisibleReCaptcha\Extension; - -use Joomla\CMS\Event\Captcha\CaptchaSetupEvent; -use Joomla\CMS\Event\Privacy\CollectCapabilitiesEvent; -use Joomla\CMS\Language\Text; -use Joomla\CMS\Plugin\CMSPlugin; -use Joomla\Event\SubscriberInterface; -use Joomla\Plugin\Captcha\InvisibleReCaptcha\Provider\InvisibleReCaptchaProvider; - -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - -/** - * Invisible reCAPTCHA Plugin. - * - * @since 3.9.0 - */ -final class InvisibleReCaptcha extends CMSPlugin implements SubscriberInterface -{ - /** - * Returns an array of events this subscriber will listen to. - * - * @return array - * - * @since 4.3.0 - */ - public static function getSubscribedEvents(): array - { - return [ - 'onCaptchaSetup' => 'onCaptchaSetup', - 'onPrivacyCollectAdminCapabilities' => 'onPrivacyCollectAdminCapabilities', - ]; - } - - /** - * Register Captcha instance - * - * @param CaptchaSetupEvent $event - * - * @return void - * @since 5.0.0 - */ - public function onCaptchaSetup(CaptchaSetupEvent $event) - { - $this->loadLanguage(); - - $event->getCaptchaRegistry()->add(new InvisibleReCaptchaProvider($this->params, $this->getApplication())); - } - - /** - * Reports the privacy related capabilities for this plugin to site administrators. - * - * @param CollectCapabilitiesEvent $event - * - * @since 3.9.0 - */ - public function onPrivacyCollectAdminCapabilities(CollectCapabilitiesEvent $event) - { - $this->loadLanguage(); - - $event->addResult([ - Text::_('PLG_CAPTCHA_RECAPTCHA_INVISIBLE') => [ - Text::_('PLG_RECAPTCHA_INVISIBLE_PRIVACY_CAPABILITY_IP_ADDRESS'), - ], - ]); - } -} diff --git a/plugins/captcha/recaptcha_invisible/src/Provider/InvisibleReCaptchaProvider.php b/plugins/captcha/recaptcha_invisible/src/Provider/InvisibleReCaptchaProvider.php deleted file mode 100644 index c1da23d11ac5b..0000000000000 --- a/plugins/captcha/recaptcha_invisible/src/Provider/InvisibleReCaptchaProvider.php +++ /dev/null @@ -1,228 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\Plugin\Captcha\InvisibleReCaptcha\Provider; - -use Joomla\CMS\Application\CMSApplicationInterface; -use Joomla\CMS\Captcha\CaptchaProviderInterface; -use Joomla\CMS\Captcha\Google\HttpBridgePostRequestMethod; -use Joomla\CMS\Form\FormField; -use Joomla\CMS\Language\Text; -use Joomla\Registry\Registry; -use Joomla\Utilities\IpHelper; -use ReCaptcha\RequestMethod; - -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - -/** - * Provider for Invisible Captcha - * @since 5.0.0 - */ -final class InvisibleReCaptchaProvider implements CaptchaProviderInterface -{ - /** - * A Registry object holding the parameters for the plugin - * - * @var Registry - * @since 5.0.0 - */ - protected $params; - - /** - * The application object - * - * @var CMSApplicationInterface - * - * @since 5.0.0 - */ - protected $application; - - /** - * The http request method - * - * @var RequestMethod - * @since 5.0.0 - */ - protected $requestMethod; - - /** - * Class constructor - * - * @param Registry $params - * @param CMSApplicationInterface $application - * @param RequestMethod|null $requestMethod The http request method - * - * @since 5.0.0 - */ - public function __construct(Registry $params, CMSApplicationInterface $application, RequestMethod $requestMethod = null) - { - $this->params = $params; - $this->application = $application; - $this->requestMethod = $requestMethod; - } - - /** - * Return Captcha name, CMD string. - * - * @return string - * @since 5.0.0 - */ - public function getName(): string - { - return 'recaptcha_invisible'; - } - - /** - * Gets the challenge HTML - * - * @param string $name Input name - * @param array $attributes The class of the field - * - * @return string The HTML to be embedded in the form - * - * @since 5.0.0 - * - * @throws \RuntimeException - */ - public function display(string $name = '', array $attributes = []): string - { - $this->loadAssets(); - - $id = $attributes['id'] ?? ''; - $class = $attributes['class'] ?? ''; - - $dom = new \DOMDocument('1.0', 'UTF-8'); - $ele = $dom->createElement('div'); - $ele->setAttribute('id', $id); - $ele->setAttribute('class', (!$class ? 'g-recaptcha' : ($class . ' g-recaptcha'))); - $ele->setAttribute('data-sitekey', $this->params->get('public_key', '')); - $ele->setAttribute('data-badge', $this->params->get('badge', 'bottomright')); - $ele->setAttribute('data-size', 'invisible'); - $ele->setAttribute('data-tabindex', $this->params->get('tabindex', '0')); - $ele->setAttribute('data-callback', $this->params->get('callback', '')); - $ele->setAttribute('data-expired-callback', $this->params->get('expired_callback', '')); - $ele->setAttribute('data-error-callback', $this->params->get('error_callback', '')); - $dom->appendChild($ele); - - return $dom->saveHTML($ele); - } - - /** - * Load captcha assets - * - * @return void - * @since 5.0.0 - */ - private function loadAssets() - { - $pubkey = $this->params->get('public_key', ''); - - if ($pubkey === '') { - throw new \RuntimeException(Text::_('PLG_RECAPTCHA_INVISIBLE_ERROR_NO_PUBLIC_KEY')); - } - - $apiSrc = 'https://www.google.com/recaptcha/api.js?onload=JoomlainitReCaptchaInvisible&render=explicit&hl=' - . $this->application->getLanguage()->getTag(); - - // Load assets, the callback should be first - $this->application->getDocument()->getWebAssetManager() - ->registerAndUseScript('plg_captcha_recaptchainvisible', 'plg_captcha_recaptcha_invisible/recaptcha.min.js', [], ['defer' => true]) - ->registerAndUseScript('plg_captcha_recaptchainvisible.api', $apiSrc, [], ['defer' => true], ['plg_captcha_recaptchainvisible']) - ->registerAndUseStyle('plg_captcha_recaptchainvisible', 'plg_captcha_recaptcha_invisible/recaptcha_invisible.css'); - } - - /** - * Calls an HTTP POST function to verify if the user's guess was correct. - * - * @param string $code Answer provided by user - * - * @return bool If the answer is correct, false otherwise - * - * @since 5.0.0 - * - * @throws \RuntimeException - */ - public function checkAnswer(string $code = null): bool - { - $privatekey = $this->params->get('private_key'); - $remoteip = IpHelper::getIp(); - - if ($code) { - $response = $code; - } else { - $response = $this->application->getInput()->get('g-recaptcha-response', '', 'string'); - } - - // Check for Private Key - if (empty($privatekey)) { - throw new \RuntimeException(Text::_('PLG_RECAPTCHA_INVISIBLE_ERROR_NO_PRIVATE_KEY')); - } - - // Check for IP - if (empty($remoteip)) { - throw new \RuntimeException(Text::_('PLG_RECAPTCHA_INVISIBLE_ERROR_NO_IP')); - } - - // Discard spam submissions - if (trim($response) == '') { - throw new \RuntimeException(Text::_('PLG_RECAPTCHA_INVISIBLE_ERROR_EMPTY_SOLUTION')); - } - - return $this->getResponse($privatekey, $remoteip, $response); - } - - /** - * Method to react on the setup of a captcha field. Gives the possibility - * to change the field and/or the XML element for the field. - * - * @param FormField $field Captcha field instance - * @param \SimpleXMLElement $element XML form definition - * - * @return void - * - * @since 5.0.0 - * - * @throws \RuntimeException - */ - public function setupField(FormField $field, \SimpleXMLElement $element): void - { - // Hide the label for the invisible recaptcha type - $element['hiddenLabel'] = 'true'; - } - - /** - * Get the reCaptcha response. - * - * @param string $privatekey The private key for authentication. - * @param string $remoteip The remote IP of the visitor. - * @param string $response The response received from Google. - * - * @return boolean True if response is good | False if response is bad. - * - * @since 5.0.0 - * @throws \RuntimeException - */ - private function getResponse($privatekey, $remoteip, $response) - { - $reCaptcha = new \ReCaptcha\ReCaptcha($privatekey, $this->requestMethod ?? new HttpBridgePostRequestMethod()); - $response = $reCaptcha->verify($response, $remoteip); - - if (!$response->isSuccess()) { - foreach ($response->getErrorCodes() as $error) { - throw new \RuntimeException($error); - } - - return false; - } - - return true; - } -} diff --git a/tests/Unit/Plugin/Captcha/InvisibleRecaptcha/Extension/InvisibleRecaptchaPluginTest.php b/tests/Unit/Plugin/Captcha/InvisibleRecaptcha/Extension/InvisibleRecaptchaPluginTest.php index c834f0981f531..e69de29bb2d1d 100644 --- a/tests/Unit/Plugin/Captcha/InvisibleRecaptcha/Extension/InvisibleRecaptchaPluginTest.php +++ b/tests/Unit/Plugin/Captcha/InvisibleRecaptcha/Extension/InvisibleRecaptchaPluginTest.php @@ -1,290 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\Tests\Unit\Plugin\Captcha\InvisibleRecaptcha\Extension; - -use Joomla\CMS\Application\CMSWebApplicationInterface; -use Joomla\CMS\Captcha\CaptchaRegistry; -use Joomla\CMS\Document\HtmlDocument; -use Joomla\CMS\Event\Captcha\CaptchaSetupEvent; -use Joomla\CMS\Event\Privacy\CollectCapabilitiesEvent; -use Joomla\CMS\Form\Field\CaptchaField; -use Joomla\CMS\Language\Language; -use Joomla\Event\Dispatcher; -use Joomla\Input\Input; -use Joomla\Plugin\Captcha\InvisibleReCaptcha\Extension\InvisibleReCaptcha; -use Joomla\Plugin\Captcha\InvisibleReCaptcha\Provider\InvisibleReCaptchaProvider; -use Joomla\Registry\Registry; -use Joomla\Tests\Unit\UnitTestCase; -use ReCaptcha\RequestMethod; - -/** - * Test class for InvisibleReCaptcha plugin - * - * @package Joomla.UnitTest - * @subpackage InvisibleReCaptcha - * - * @testdox The InvisibleReCaptcha plugin - * - * @since 4.3.0 - */ -class InvisibleRecaptchaPluginTest extends UnitTestCase -{ - /** - * Setup - * - * @return void - * - * @since 4.3.0 - */ - public function setUp(): void - { - if (empty($_SERVER['REMOTE_ADDR'])) { - $_SERVER['REMOTE_ADDR'] = 'unit.test'; - } - } - - /** - * Cleanup - * - * @return void - * - * @since 4.3.0 - */ - public function tearDown(): void - { - if (!empty($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] === 'unit.test') { - unset($_SERVER['REMOTE_ADDR']); - } - } - - /** - * @testdox Captcha Setup event test - * - * @return void - * - * @since 5.0.0 - */ - public function testOnSetUpEvent(): void - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - - $dispatcher = new Dispatcher(); - $registry = new CaptchaRegistry(); - $event = new CaptchaSetupEvent('onCaptchaSetup', ['subject' => $registry]); - - $plugin = new InvisibleReCaptcha($dispatcher, ['name' => 'test', 'params' => []]); - $plugin->setApplication($app); - $plugin->onCaptchaSetup($event); - - $this->assertTrue($registry->has('recaptcha_invisible'), 'The captcha provider are registered.'); - } - - /** - * @testdox can display the captcha - * - * @return void - * - * @since 4.3.0 - */ - public function testDisplay() - { - $document = new HtmlDocument(); - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getDocument')->willReturn($document); - $app->method('getLanguage')->willReturn($language); - - $params = new Registry(['public_key' => 'test']); - $captcha = new InvisibleReCaptchaProvider($params, $app); - - $html = $captcha->display(); - - $this->assertNotEmpty($html); - $this->assertNotEquals($html, strip_tags($html)); - - $this->assertNotEmpty($document->getWebAssetManager()->getAsset('script', 'plg_captcha_recaptchainvisible')); - $this->assertNotEmpty($document->getWebAssetManager()->getAsset('script', 'plg_captcha_recaptchainvisible.api')); - } - - /** - * @testdox can init the captcha with an empty public key - * - * @return void - * - * @since 5.0.0 - */ - public function testDisplayEmptyPublicKey() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - - $params = new Registry(['public_key' => '']); - $captcha = new InvisibleReCaptchaProvider($params, $app); - - $this->expectException(\RuntimeException::class); - - $captcha->display(); - } - - /** - * @testdox can check successful answer - * - * @return void - * - * @since 4.3.0 - */ - public function testResponse() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - $app->method('getInput')->willReturn(new Input(['g-recaptcha-response' => 'test'])); - - $method = $this->createStub(RequestMethod::class); - $method->method('submit')->willReturn(json_encode(['success' => true])); - - $params = new Registry(['private_key' => 'test']); - $captcha = new InvisibleReCaptchaProvider($params, $app, $method); - - $this->assertTrue($captcha->checkAnswer()); - $this->assertTrue($captcha->checkAnswer('test')); - } - - /** - * @testdox can check answer with an empty private key - * - * @return void - * - * @since 4.3.0 - */ - public function testResponseEmptyPrivateKey() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - - $params = new Registry(['private_key' => '']); - $captcha = new InvisibleReCaptchaProvider($params, $app); - - $this->expectException(\RuntimeException::class); - - $captcha->checkAnswer('test'); - } - - /** - * @testdox can detect spam - * - * @return void - * - * @since 4.3.0 - */ - public function testResponseSpam() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - $app->method('getInput')->willReturn(new Input(['g-recaptcha-response' => ''])); - - $params = new Registry(['private_key' => 'test']); - $captcha = new InvisibleReCaptchaProvider($params, $app, $this->createStub(RequestMethod::class)); - - $this->expectException(\RuntimeException::class); - - $captcha->checkAnswer(); - } - - /** - * @testdox can check successful answer - * - * @return void - * - * @since 4.3.0 - */ - public function testFailedResponse() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - $app->method('getInput')->willReturn(new Input(['g-recaptcha-response' => 'test'])); - - $method = $this->createStub(RequestMethod::class); - $method->method('submit')->willReturn(json_encode(['success' => false])); - - $params = new Registry(['private_key' => 'test']); - $captcha = new InvisibleReCaptchaProvider($params, $app, $method); - - $this->expectException(\RuntimeException::class); - - $captcha->checkAnswer(); - $captcha->checkAnswer('test'); - } - - /** - * @testdox can setup field - * - * @return void - * - * @since 4.3.0 - */ - public function testSetupField() - { - $params = new Registry(['private_key' => 'test']); - $captcha = new InvisibleReCaptchaProvider($params, $this->createStub(CMSWebApplicationInterface::class)); - - $fieldXml = new \SimpleXMLElement(''); - $captcha->setupField(new CaptchaField(), $fieldXml); - - $this->assertEquals('true', (string) $fieldXml['hiddenLabel'], 'setupField() method should set correct attribute.'); - } - - /** - * @testdox can return admin capabilities - * - * @return void - * - * @since 4.3.0 - */ - public function testPrivacy() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - - $dispatcher = new Dispatcher(); - - $plugin = new InvisibleReCaptcha($dispatcher, ['name' => 'test', 'params' => []]); - $plugin->setApplication($app); - - $event = new CollectCapabilitiesEvent('onPrivacyCollectAdminCapabilities'); - $plugin->onPrivacyCollectAdminCapabilities($event); - - $this->assertNotEmpty($event['result']); - } -} diff --git a/tests/Unit/Plugin/Captcha/Recaptcha/Extension/RecaptchaPluginTest.php b/tests/Unit/Plugin/Captcha/Recaptcha/Extension/RecaptchaPluginTest.php deleted file mode 100644 index 5f5f1b9f6dea7..0000000000000 --- a/tests/Unit/Plugin/Captcha/Recaptcha/Extension/RecaptchaPluginTest.php +++ /dev/null @@ -1,289 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\Tests\Unit\Plugin\Captcha\Recaptcha\Extension; - -use Joomla\CMS\Application\CMSApplicationInterface; -use Joomla\CMS\Application\CMSWebApplicationInterface; -use Joomla\CMS\Document\HtmlDocument; -use Joomla\CMS\Language\Language; -use Joomla\Event\Dispatcher; -use Joomla\Input\Input; -use Joomla\Plugin\Captcha\ReCaptcha\Extension\ReCaptcha; -use Joomla\Tests\Unit\UnitTestCase; -use ReCaptcha\RequestMethod; - -/** - * Test class for ReCaptcha plugin - * - * @package Joomla.UnitTest - * @subpackage ReCaptcha - * - * @testdox The ReCaptcha plugin - * - * @since 4.3.0 - */ -class RecaptchaPluginTest extends UnitTestCase -{ - /** - * Setup - * - * @return void - * - * @since 4.3.0 - */ - public function setUp(): void - { - if (empty($_SERVER['REMOTE_ADDR'])) { - $_SERVER['REMOTE_ADDR'] = 'unit.test'; - } - } - - /** - * Cleanup - * - * @return void - * - * @since 4.3.0 - */ - public function tearDown(): void - { - if (!empty($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] === 'unit.test') { - unset($_SERVER['REMOTE_ADDR']); - } - } - - /** - * @testdox can init the captcha - * - * @return void - * - * @since 4.3.0 - */ - public function testInit() - { - $document = new HtmlDocument(); - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getDocument')->willReturn($document); - $app->method('getLanguage')->willReturn($language); - - $plugin = new ReCaptcha(new Dispatcher(), ['params' => ['public_key' => 'test']], $this->createStub(RequestMethod::class)); - $plugin->setApplication($app); - - $this->assertTrue($plugin->onInit()); - $this->assertNotEmpty($document->getWebAssetManager()->getAsset('script', 'plg_captcha_recaptcha')); - $this->assertNotEmpty($document->getWebAssetManager()->getAsset('script', 'plg_captcha_recaptcha.api')); - } - - /** - * @testdox can init the captcha with a wrong application - * - * @return void - * - * @since 4.3.0 - */ - public function testInitWrongApplication() - { - $plugin = new ReCaptcha(new Dispatcher(), ['params' => ['public_key' => 'test']], $this->createStub(RequestMethod::class)); - $plugin->setApplication($this->createStub(CMSApplicationInterface::class)); - - $this->assertFalse($plugin->onInit()); - } - - /** - * @testdox can init the captcha with an empty public key - * - * @return void - * - * @since 4.3.0 - */ - public function testInitEmptyPublicKey() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - - $plugin = new ReCaptcha(new Dispatcher(), ['params' => []], $this->createStub(RequestMethod::class)); - $plugin->setApplication($app); - - $this->expectException(\RuntimeException::class); - - $plugin->onInit(); - } - - /** - * @testdox can display the captcha - * - * @return void - * - * @since 4.3.0 - */ - public function testDisplay() - { - $plugin = new ReCaptcha(new Dispatcher(), ['params' => []], $this->createStub(RequestMethod::class)); - $plugin->setApplication($this->createStub(CMSWebApplicationInterface::class)); - - $html = $plugin->onDisplay(); - - $this->assertNotEmpty($html); - $this->assertNotEquals($html, strip_tags($html)); - } - - /** - * @testdox can check successful answer - * - * @return void - * - * @since 4.3.0 - */ - public function testResponse() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - $app->method('getInput')->willReturn(new Input(['g-recaptcha-response' => 'test'])); - - $method = $this->createStub(RequestMethod::class); - $method->method('submit')->willReturn(json_encode(['success' => true])); - - $plugin = new ReCaptcha(new Dispatcher(), ['params' => ['private_key' => 'test']], $method); - $plugin->setApplication($app); - - $this->assertTrue($plugin->onCheckAnswer()); - } - - /** - * @testdox can check successful answer - * - * @return void - * - * @since 4.3.0 - */ - public function testResponseWithCode() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - - $method = $this->createStub(RequestMethod::class); - $method->method('submit')->willReturn(json_encode(['success' => true])); - - $plugin = new ReCaptcha(new Dispatcher(), ['params' => ['private_key' => 'test']], $method); - $plugin->setApplication($app); - - $this->assertTrue($plugin->onCheckAnswer('test')); - } - - /** - * @testdox can check answer with an empty private key - * - * @return void - * - * @since 4.3.0 - */ - public function testResponseEmptyPrivateKey() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - - $plugin = new ReCaptcha(new Dispatcher(), ['params' => []], $this->createStub(RequestMethod::class)); - $plugin->setApplication($app); - - $this->expectException(\RuntimeException::class); - - $plugin->onCheckAnswer(); - } - - /** - * @testdox can detect spam - * - * @return void - * - * @since 4.3.0 - */ - public function testResponseSpam() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - $app->method('getInput')->willReturn(new Input(['g-recaptcha-response' => ''])); - - $plugin = new ReCaptcha(new Dispatcher(), ['params' => ['private_key' => 'test']], $this->createStub(RequestMethod::class)); - $plugin->setApplication($app); - - $this->expectException(\RuntimeException::class); - - $plugin->onCheckAnswer(); - } - - /** - * @testdox can check successful answer - * - * @return void - * - * @since 4.3.0 - */ - public function testFailedResponse() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - $app->method('getInput')->willReturn(new Input(['g-recaptcha-response' => 'test'])); - - $method = $this->createStub(RequestMethod::class); - $method->method('submit')->willReturn(json_encode(['success' => false])); - - $plugin = new ReCaptcha(new Dispatcher(), ['params' => ['private_key' => 'test']], $method); - $plugin->setApplication($app); - - $this->expectException(\RuntimeException::class); - - $plugin->onCheckAnswer(); - } - - /** - * @testdox can return admin capabilities - * - * @return void - * - * @since 4.3.0 - */ - public function testPrivacy() - { - $language = $this->createStub(Language::class); - $language->method('_')->willReturn('test'); - - $app = $this->createStub(CMSWebApplicationInterface::class); - $app->method('getLanguage')->willReturn($language); - - $plugin = new ReCaptcha(new Dispatcher(), ['params' => ['private_key' => 'test']], $this->createStub(RequestMethod::class)); - $plugin->setApplication($app); - - $caps = $plugin->onPrivacyCollectAdminCapabilities(); - - $this->assertNotEmpty($caps); - } -} ```