Skip to content
Snippets Groups Projects
Commit 98014786 authored by Michael Lee's avatar Michael Lee
Browse files

Merge branch 'honeypot' into lee5151

parents f8064a21 a71aa6c3
No related branches found
No related tags found
No related merge requests found
......@@ -4665,17 +4665,17 @@
},
{
"name": "drupal/honeypot",
"version": "2.1.0",
"version": "2.1.2",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/honeypot.git",
"reference": "2.1.0"
"reference": "2.1.2"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/honeypot-2.1.0.zip",
"reference": "2.1.0",
"shasum": "7ddb2d0bfeaa65d55823d82bdf01c9c330a1e12f"
"url": "https://ftp.drupal.org/files/projects/honeypot-2.1.2.zip",
"reference": "2.1.2",
"shasum": "9511fd6db37c153f2290950bf79611b27510cede"
},
"require": {
"drupal/core": "^9.2 || ^10"
......@@ -4686,8 +4686,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "2.1.0",
"datestamp": "1654198317",
"version": "2.1.2",
"datestamp": "1664658244",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......
......@@ -4816,18 +4816,18 @@
},
{
"name": "drupal/honeypot",
"version": "2.1.0",
"version_normalized": "2.1.0.0",
"version": "2.1.2",
"version_normalized": "2.1.2.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/honeypot.git",
"reference": "2.1.0"
"reference": "2.1.2"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/honeypot-2.1.0.zip",
"reference": "2.1.0",
"shasum": "7ddb2d0bfeaa65d55823d82bdf01c9c330a1e12f"
"url": "https://ftp.drupal.org/files/projects/honeypot-2.1.2.zip",
"reference": "2.1.2",
"shasum": "9511fd6db37c153f2290950bf79611b27510cede"
},
"require": {
"drupal/core": "^9.2 || ^10"
......@@ -4838,8 +4838,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "2.1.0",
"datestamp": "1651894953",
"version": "2.1.2",
"datestamp": "1664658244",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -4857,16 +4857,16 @@
"authors": [
{
"name": "Jeff Geerling",
"homepage": "https://www.drupal.org/user/213194",
"homepage": "https://www.drupal.org/user/389011",
"email": "geerlingguy@mac.com"
},
{
"name": "TR",
"homepage": "https://www.drupal.org/user/202830"
"name": "Manuel Garcia",
"homepage": "https://www.drupal.org/user/213194"
},
{
"name": "geerlingguy",
"homepage": "https://www.drupal.org/user/389011"
"name": "TR",
"homepage": "https://www.drupal.org/user/202830"
},
{
"name": "vijaycs85",
......
......@@ -848,9 +848,9 @@
'dev_requirement' => false,
),
'drupal/honeypot' => array(
'pretty_version' => '2.1.0',
'version' => '2.1.0.0',
'reference' => '2.1.0',
'pretty_version' => '2.1.2',
'version' => '2.1.2.0',
'reference' => '2.1.2',
'type' => 'drupal-module',
'install_path' => __DIR__ . '/../../web/modules/honeypot',
'aliases' => array(),
......
......@@ -11,7 +11,7 @@ tips:
label: Honeypot
weight: -10
body: "Congratulations on installing Honeypot on your site! With just a few clicks, you can have your site well-protected against automated spam bots.\r\n\r\nClick Next to be guided through this configuration page."
location: top-start
position: top-start
protect-all-forms:
id: protect-all-forms
plugin: text
......@@ -19,7 +19,7 @@ tips:
weight: -9
selector: '#edit-protect-all-forms'
body: "Protecting all the forms is the easiest way to quickly cut down on spam on your site, but doing this disables Drupal's caching for every page where a form is displayed.\r\n\r\nNote: If you have the honeypot time limit enabled, this option may cause issues with Drupal Commerce product forms or similarly-sparse forms that are able to be completed in a very short time."
location: bottom-start
position: bottom-start
log-blocked-form-submissions:
id: log-blocked-form-submissions
plugin: text
......@@ -27,7 +27,7 @@ tips:
weight: -8
selector: '#edit-log'
body: 'Check this box to log every form submission using watchdog. If you have Database Logging enabled, you can view these log entries in the Recent log messages page under Reports.'
location: bottom-start
position: bottom-start
honeypot-element-name:
id: honeypot-element-name
plugin: text
......@@ -35,7 +35,7 @@ tips:
weight: -7
selector: '#edit-element-name'
body: 'Spam bots typically fill out any field they believe will help get links back to their site, so tempting them with a field named something like ''url'', ''homepage'', or ''link'' makes it hard for them to resist filling in the field—and easy to catch them in the trap and reject their submissions!'
location: top-start
position: top-start
honeypot-time-limit:
id: honeypot-time-limit
plugin: text
......@@ -43,7 +43,7 @@ tips:
weight: -6
selector: '#edit-time-limit'
body: 'If you enter a positive value, Honeypot will require that all protected forms take at least that many seconds long to fill out. Most forms take at least 5-10 seconds to complete (if you''re a human), so setting this to a value < 5 will help protect against spam bots. Set to 0 to disable.'
location: top-start
position: top-start
honeypot-expire:
id: honeypot-expire
plugin: text
......@@ -51,7 +51,7 @@ tips:
weight: -5
selector: '#edit-expire'
body: 'If you enter a positive value, Honeypot will require that all protected forms take at least that many seconds long to fill out. Most forms take at least 5-10 seconds to complete (if you''re a human), so setting this to a value < 5 will help protect against spam bots. Set to 0 to disable.'
location: top-start
position: top-start
honeypot-form-specific-settings:
id: honeypot-form-specific-settings
plugin: text
......@@ -59,4 +59,4 @@ tips:
weight: -4
selector: '#edit-form-settings'
body: 'If you would like to choose particular forms to be protected by Honeypot, check the forms you wish to protect in this section. Most common types of forms are available for protection.'
location: top-start
position: top-start
......@@ -8,7 +8,7 @@ test_dependencies:
configure: honeypot.config
# Information added by Drupal.org packaging script on 2022-05-07
version: '2.1.0'
# Information added by Drupal.org packaging script on 2022-10-01
version: '2.1.2'
project: 'honeypot'
datestamp: 1651894956
datestamp: 1664658206
......@@ -46,6 +46,9 @@ function honeypot_schema() {
*/
function honeypot_install() {
if (PHP_SAPI !== 'cli') {
// Rebuild so that routes defined in honeypot.routing.yml become available.
\Drupal::service("router.builder")->rebuild();
// Prompt the user to configure Honeypot.
\Drupal::messenger()->addMessage(t('Honeypot installed successfully. Please <a href=":url">configure Honeypot</a> to protect your forms from spam bots.', [
':url' => Url::fromRoute('honeypot.config')->toString(),
]));
......
<?php
/**
* @file
* Post update functions for Honeypot.
*/
use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\tour\Entity\Tour;
/**
* Convert deprecated Joyride 'location' properties to 'position' properties.
*/
function honeypot_post_update_joyride_location_to_position(array &$sandbox = NULL): void {
if (\Drupal::moduleHandler()->moduleExists('tour')) {
$config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
$config_entity_updater->update($sandbox, 'tour', function (Tour $tour) {
return honeypot_tour_update_joyride($tour);
});
}
}
/**
* Updates 'honeypot' tour to correct use of the deprecated location property.
*
* @param \Drupal\tour\Entity\Tour $tour
* The tour to update.
*
* @return bool
* Whether or not the entity needs saving.
*
* @see honeypot_post_update_joyride_location_to_position()
*
* @internal
*/
function honeypot_tour_update_joyride(Tour $tour): bool {
$needs_save = FALSE;
// Only change the 'honeypot' tour.
$id = $tour->get('id');
if ($id === 'honeypot') {
$tips = $tour->get('tips');
foreach ($tips as &$tip) {
// The tour module will automatically change a 'location' property to a
// position property in some circumstances. If the tour module does this,
// the value of the property will have an extra '-start' appended.
if (isset($tip['position'])) {
$tip['position'] = str_replace('-start-start', '-start', $tip['position']);
$needs_save = TRUE;
}
// If the tour module doesn't change the 'location' property, we have to
// do it ourselves.
if (isset($tip['location'])) {
$needs_save = TRUE;
$tip['position'] = $tip['location'];
unset($tip['location']);
}
}
if ($needs_save) {
$tour->set('tips', $tips);
}
}
return $needs_save;
}
/**
* Rebuild the service container after adding new 'honeypot' service.
*/
function honeypot_post_update_rebuild_service_container(): void {
// An empty update will flush all caches.
}
......@@ -7,6 +7,7 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Database\Connection;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\KeyValueStore\KeyValueExpirableFactory;
......@@ -21,6 +22,7 @@
* Provides a service to append Honeypot protection to forms.
*/
class HoneypotService implements HoneypotServiceInterface {
use DependencySerializationTrait;
use StringTranslationTrait;
/**
......@@ -66,11 +68,11 @@ class HoneypotService implements HoneypotServiceInterface {
protected $connection;
/**
* The Honeypot logger channel.
* The Honeypot logger channel factory.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $logger;
protected $loggerFactory;
/**
* The datetime.time service.
......@@ -126,7 +128,7 @@ public function __construct(AccountProxyInterface $account, ModuleHandlerInterfa
$this->keyValue = $key_value->get('honeypot_time_restriction');
$this->killSwitch = $kill_switch;
$this->connection = $connection;
$this->logger = $logger_factory->get('honeypot');
$this->loggerFactory = $logger_factory;
$this->timeService = $time_service;
$this->stringTranslation = $string_translation;
$this->cacheBackend = $cache_backend;
......@@ -323,7 +325,7 @@ public function validateTimeRestriction(array &$element, FormStateInterface $for
$triggering_element = $form_state->getTriggeringElement();
// Don't do anything if the triggering element is a preview button.
if ($triggering_element['#value'] == $this->t('Preview')) {
if ($triggering_element['#value'] == (string) $this->t('Preview')) {
return;
}
......@@ -361,7 +363,8 @@ protected function log(string $form_id, string $type): void {
'%form' => $form_id,
'@cause' => ($type == 'honeypot') ? $this->t('submission of a value in the honeypot field') : $this->t('submission of the form in less than minimum required time'),
];
$this->logger->notice('Blocked submission of %form due to @cause.', $variables);
$this->loggerFactory->get('honeypot')
->notice('Blocked submission of %form due to @cause.', $variables);
}
}
......
......@@ -3,7 +3,7 @@ type: module
description: Support module for Honeypot internal testing purposes.
package: Testing
# Information added by Drupal.org packaging script on 2022-05-07
version: '2.1.0'
# Information added by Drupal.org packaging script on 2022-10-01
version: '2.1.2'
project: 'honeypot'
datestamp: 1651894956
datestamp: 1664658206
<?php
namespace Drupal\Tests\honeypot\FunctionalJavascript;
use Drupal\Tests\file\FunctionalJavascript\FileFieldWidgetTest;
/**
* Tests the file field widget with the Honeypot module enabled.
*
* @group honeypot
*/
class HoneypotFileFieldTest extends FileFieldWidgetTest {
/**
* {@inheritdoc}
*/
protected static $modules = [
'honeypot',
'node',
'file',
'file_module_test',
'field_ui',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Set up required Honeypot configuration.
$honeypot_config = \Drupal::configFactory()->getEditable('honeypot.settings');
$honeypot_config->set('element_name', 'url');
// Disable time_limit protection.
$honeypot_config->set('time_limit', 0);
// Test protecting all forms.
$honeypot_config->set('protect_all_forms', TRUE);
$honeypot_config->set('log', FALSE);
$honeypot_config->save();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment