Skip to content

Commit 02f1b88

Browse files
committed
add debug mode
1 parent 7c6eb9a commit 02f1b88

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

inc/Bounce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public function safelyBounce(): void
326326
'file' => $e->getFile(),
327327
'line' => $e->getLine(),
328328
]);
329-
if (WP_DEBUG) {
329+
if ($this->debug) {
330330
throw $e;
331331
}
332332
}

inc/admin/advanced-settings.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,16 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
261261
// Field "crowdsec_standalone_mode"
262262
addFieldCheckbox('crowdsec_standalone_mode', 'Enable standalone mode', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_standalone', function () {}, function () {}, '
263263
<p>This process allows the bouncer to bounce IPs before running any PHP script in the project. <a href="https://wordpress.org/support/topic/standalone-mode-how-it-works" target="_blank">Discover how to setup with this guide</a>.</p><p>Enable this option only if you set the "<em>auto_prepend_file</em>" PHP flag following the guide, else the bouncer will not bounce.</p>');
264+
265+
/*******************************
266+
** Section "Debug mode" **
267+
******************************/
268+
269+
add_settings_section('crowdsec_admin_advanced_debug', 'Debug mode', function () {
270+
echo 'Configure the debug mode.';
271+
}, 'crowdsec_advanced_settings');
272+
273+
// Field "crowdsec_debug_mode"
274+
addFieldCheckbox('crowdsec_debug_mode', 'Enable debug mode', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_debug', function () {}, function () {}, '
275+
<p>Do not use in production. When this mode is enabled, you will see every unexpected bouncing errors in the browser and debug log will be written.</p>');
264276
}

tests/e2e/__tests__/1-setup-plugin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
onAdminGoToAdvancedPage,
1515
onAdminSaveSettings,
1616
onLoginPageLoginAsAdmin,
17+
onAdvancedPageEnableDebugMode,
1718
onAdminAdvancedSettingsPageSetCleanIpCacheDurationTo,
1819
onAdminAdvancedSettingsPageSetBadIpCacheDurationTo,
1920
fillInput,
@@ -52,6 +53,12 @@ describe(`Setup CrowdSec plugin`, () => {
5253
await onAdminSaveSettings();
5354
});
5455

56+
it('Should enable the debug mode"', async () => {
57+
await onAdminGoToAdvancedPage();
58+
await onAdvancedPageEnableDebugMode();
59+
await onAdminSaveSettings();
60+
});
61+
5562
it('Should reduce the live mode cache durations"', async () => {
5663
await onAdminGoToAdvancedPage();
5764
await onAdminAdvancedSettingsPageSetCleanIpCacheDurationTo(1);

tests/e2e/utils/helpers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ const onAdvancedPageDisableStandAloneMode = async () => {
120120
await setToggle("crowdsec_standalone_mode", false);
121121
};
122122

123+
const onAdvancedPageEnableDebugMode = async () => {
124+
await setToggle("crowdsec_debug_mode", true);
125+
};
126+
127+
const onAdvancedPageDisableDebugMode = async () => {
128+
await setToggle("crowdsec_debug_mode", false);
129+
};
130+
123131
const onAdminAdvancedSettingsPageSetCleanIpCacheDurationTo = async (
124132
seconds
125133
) => {
@@ -365,4 +373,6 @@ module.exports = {
365373
loadCookies,
366374
enableAutoPrependFileInHtaccess,
367375
disableAutoPrependFileInHtaccess,
376+
onAdvancedPageEnableDebugMode,
377+
onAdvancedPageDisableDebugMode
368378
};

0 commit comments

Comments
 (0)