Skip to content

Commit

Permalink
feat(*): Remove fallback setting and prepare release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
julienloizelet committed Aug 21, 2023
1 parent e1e537e commit 7f59a44
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 116 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

---

## [1.0.0](https://github.com/crowdsecurity/magento-cs-extension/releases/tag/v1.0.0) - 2023-08-22
[_Compare with previous release_](https://github.com/crowdsecurity/magento-cs-extension/compare/v0.3.0...v1.0.0)


### Removed

- Remove fallback remediation setting and always use `bypass` as fallback

---

## [0.3.0](https://github.com/crowdsecurity/magento-cs-extension/releases/tag/v0.3.0) - 2023-08-21
[_Compare with previous release_](https://github.com/crowdsecurity/magento-cs-extension/compare/v0.2.0...v0.3.0)

Expand Down
2 changes: 1 addition & 1 deletion Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ class Constants extends CapiConstants
/** @var string The user agent suffix used to send request to CAPI */
public const USER_AGENT_SUFFIX = 'magento2';
/** @var string The last version of this module */
public const VERSION = 'v0.3.0';
public const VERSION = 'v1.0.0';
}
51 changes: 1 addition & 50 deletions Test/EndToEnd/__tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check
import { test, expect } from "../fixtures";
import { testIp1, ORIGIN_CROWDSEC, blockRegex } from "../helpers/constants";
import { test } from "../fixtures";

test.describe("Extension configuration", () => {
test.beforeEach(async ({ adminCrowdSecSecurityConfigPage }) => {
Expand All @@ -27,51 +26,3 @@ test.describe("Extension configuration", () => {
await adminCrowdSecSecurityConfigPage.refreshCache();
});
});

test.describe("Fallback remediation setting", () => {
test("can see count incrementation for local decision with unhandled remediation", async ({
adminCrowdSecSecurityConfigPage,
adminCrowdSecSecurityReportPage,
runActionPage,
page,
homePage,
}) => {
// Reset all
await runActionPage.setForcedIp("");
await runActionPage.clearCache();
// Set config
await adminCrowdSecSecurityConfigPage.navigateTo();
await adminCrowdSecSecurityConfigPage.setDefaultConfig();
await adminCrowdSecSecurityReportPage.navigateTo();
// Local decision should be 0
await expect(
page.locator("#crowdsec-engine-metrics tbody tr:first-child td.count")
).toHaveText("0");

// Simulate a "unhandled" decision for testIp1
await runActionPage.addDecision(testIp1, "unhandled", ORIGIN_CROWDSEC, 60);
await runActionPage.setForcedIp(testIp1);
// Home page should be accessible as default fallback is bypass
await homePage.navigateTo();
await expect(page.locator("body")).not.toHaveText(blockRegex);
await adminCrowdSecSecurityReportPage.navigateTo();
// Local decision should be 1
await expect(
page.locator("#crowdsec-engine-metrics tbody tr:first-child td.count")
).toHaveText("1");

await adminCrowdSecSecurityConfigPage.navigateTo();
await page
.getByRole("combobox", { name: "[GLOBAL] Fallback" })
.selectOption("ban");

await adminCrowdSecSecurityConfigPage.saveConfig(false);
// Home page should be blocked as fallback is now ban
await homePage.navigateTo(false);
await expect(page.locator("body")).toHaveText(blockRegex);

// Clear cache for next tests and reinit forced test ip
await runActionPage.setForcedIp("");
await runActionPage.clearCache();
});
});
73 changes: 44 additions & 29 deletions Test/EndToEnd/__tests__/reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,23 @@ import {
} from "../helpers/constants";

test.describe("Reports page", () => {
test("can set default config", async ({
adminCrowdSecSecurityConfigPage,
}) => {
await adminCrowdSecSecurityConfigPage.navigateTo();
await adminCrowdSecSecurityConfigPage.setDefaultConfig();
});
test("can see default settings", async ({
adminCrowdSecSecurityReportPage,
adminCrowdSecSecurityConfigPage,
page,
runActionPage,
}) => {
await runActionPage.clearCache();
await adminCrowdSecSecurityConfigPage.navigateTo();
await adminCrowdSecSecurityConfigPage.setDefaultConfig();
await adminCrowdSecSecurityReportPage.navigateTo();
await expect(
page.locator("#crowdsec-engine-remediation-metrics")
).toHaveText(/Ban IP locally setting is enabled/);
await expect(
page.locator("#crowdsec-engine-remediation-metrics")
).toHaveText(/Block banned IP setting is enabled/);
).toHaveText(/Ban IP locally enabled/);
await expect(
page.locator("#crowdsec-engine-remediation-metrics")
).toHaveText(/Fallback setting is bypass/);
).toHaveText(/Block banned IP enabled/);

// Local decision should be 0
await expect(
page.locator("#crowdsec-engine-metrics tbody tr:first-child td.count")
Expand Down Expand Up @@ -61,21 +56,14 @@ test.describe("Reports page", () => {
.getByRole("combobox", { name: "[GLOBAL] Block banned IP" })
.selectOption("0");

await page
.getByRole("combobox", { name: "[GLOBAL] Fallback" })
.selectOption("ban");

await adminCrowdSecSecurityConfigPage.saveConfig();
await adminCrowdSecSecurityReportPage.navigateTo();
await expect(
page.locator("#crowdsec-engine-remediation-metrics")
).toHaveText(/Ban IP locally setting is disabled/);
await expect(
page.locator("#crowdsec-engine-remediation-metrics")
).toHaveText(/Block banned IP setting is disabled/);
).toHaveText(/Ban IP locally disabled/);
await expect(
page.locator("#crowdsec-engine-remediation-metrics")
).toHaveText(/Fallback setting is ban/);
).toHaveText(/Block banned IP disabled/);
});

test("can see count incrementation for local decision", async ({
Expand All @@ -91,9 +79,6 @@ test.describe("Reports page", () => {
.getByRole("combobox", { name: "[GLOBAL] Block banned IP" })
.selectOption("1");

await page
.getByRole("combobox", { name: "[GLOBAL] Fallback" })
.selectOption("bypass");
await adminCrowdSecSecurityConfigPage.saveConfig();
await adminCrowdSecSecurityReportPage.navigateTo();
// Local decision should be 0
Expand Down Expand Up @@ -129,9 +114,6 @@ test.describe("Reports page", () => {
.getByRole("combobox", { name: "[GLOBAL] Block banned IP" })
.selectOption("1");

await page
.getByRole("combobox", { name: "[GLOBAL] Fallback" })
.selectOption("bypass");
await adminCrowdSecSecurityConfigPage.saveConfig();
await adminCrowdSecSecurityReportPage.navigateTo();
// Community Blocklist decision should be 0
Expand Down Expand Up @@ -167,9 +149,6 @@ test.describe("Reports page", () => {
.getByRole("combobox", { name: "[GLOBAL] Block banned IP" })
.selectOption("1");

await page
.getByRole("combobox", { name: "[GLOBAL] Fallback" })
.selectOption("bypass");
await adminCrowdSecSecurityConfigPage.saveConfig();
await adminCrowdSecSecurityReportPage.navigateTo();
// Third party blocklist decision should be 0
Expand All @@ -191,4 +170,40 @@ test.describe("Reports page", () => {
// Clear cache for next tests
await runActionPage.clearCache();
});

test("can see count incrementation for local decision with unhandled remediation", async ({
adminCrowdSecSecurityConfigPage,
adminCrowdSecSecurityReportPage,
runActionPage,
page,
homePage,
}) => {
// Reset all
await runActionPage.setForcedIp("");
await runActionPage.clearCache();
// Set config
await adminCrowdSecSecurityConfigPage.navigateTo();
await adminCrowdSecSecurityConfigPage.setDefaultConfig();
await adminCrowdSecSecurityReportPage.navigateTo();
// Local decision should be 0
await expect(
page.locator("#crowdsec-engine-metrics tbody tr:first-child td.count")
).toHaveText("0");

// Simulate a "unhandled" decision for testIp1
await runActionPage.addDecision(testIp1, "unhandled", ORIGIN_CROWDSEC, 60);
await runActionPage.setForcedIp(testIp1);
// Home page should be accessible as default fallback is bypass
await homePage.navigateTo();
await expect(page.locator("body")).not.toHaveText(blockRegex);
await adminCrowdSecSecurityReportPage.navigateTo();
// Local decision should be 1
await expect(
page.locator("#crowdsec-engine-metrics tbody tr:first-child td.count")
).toHaveText("1");

// Clear cache for next tests and reinit forced test ip
await runActionPage.setForcedIp("");
await runActionPage.clearCache();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export default class CrowdSecSecurityConfigPage {
.getByRole("combobox", { name: "[GLOBAL] Block banned IP" })
.selectOption("1");

await this.page
.getByRole("combobox", { name: "[GLOBAL] Fallback" })
.selectOption("bypass");

await this.page
.getByRole("combobox", { name: "[GLOBAL] Technology" })
.selectOption("phpfs");
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "crowdsec/magento2-module-engine",
"description": "This Magento 2 module allows sharing threat signal and benefit from the CrowdSec's community blocklist.",
"type": "magento2-module",
"version": "0.3.0",
"version": "1.0.0",
"minimum-stability": "stable",
"license": "MIT",
"authors": [
Expand Down
7 changes: 0 additions & 7 deletions doc/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,6 @@ By default, it will have the following design and content:

***

`Decisions → Fallback` (`global` scope)

What remediation to apply when CrowdSec remediation differs from `ban` : `bypass` or `ban`.
Can be used as a fallback for `captcha` or any other custom remediation.


***

`Decisions → Cache configuration → Technology` (`global` scope)

Expand Down
Binary file modified doc/images/screenshots/config-decisions.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/images/screenshots/report-events.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/images/screenshots/report-metrics.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 3 additions & 8 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,16 @@
<group id="decisions" translate="label, comment" showInDefault="1">
<label>Decisions</label>
<attribute type="expanded">1</attribute>
<comment><![CDATA[Decisions may come from the community blocklist or from local detection. Configure how you want to manage them.]]></comment>
<comment><![CDATA[Decisions dictate what actions will be taken against an IP.<br>Decisions can be created locally or come from CrowdSec's blocklist.]]></comment>
<field id="ban_locally" translate="label,comment,tooltip" type="select" sortOrder="200" showInDefault="1">
<label>Ban IP locally</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[If enabled, a "ban" decision will be added to local cache as soon as an alert is triggered for the IP.]]></comment>
<comment><![CDATA[Apply a "ban" decision on locally detected alerts.]]></comment>
</field>
<field id="bounce_ban" translate="label,comment,tooltip" type="select" sortOrder="300" showInDefault="1">
<label>Block banned IP</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[If enabled, a cached "banned" IP will be blocked by a ban wall (403). You can edit the content of this ban wall in the "crowdsec-engine-ban-wall" CMS block.]]></comment>
</field>
<field id="fallback_remediation" translate="label,comment,tooltip" type="select" sortOrder="400" showInDefault="1">
<label>Fallback</label>
<source_model>CrowdSec\Engine\Model\Config\Source\Fallback</source_model>
<comment><![CDATA[What remediation to apply when CrowdSec remediation differs from "ban".<br>Can be used as a fallback for "captcha" or any other custom remediation.]]></comment>
<comment><![CDATA[Apply remediation on "ban" decisions redirecting to a ban wall (403).<br> You can edit the content of this ban wall in the "crowdsec-engine-ban-wall" CMS block.]]></comment>
</field>
<!-- Cache -->
<group id="cache" translate="label,comment,tooltip" sortOrder="500" showInDefault="1">
Expand Down
21 changes: 5 additions & 16 deletions view/adminhtml/templates/report/metrics.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@
<div id="crowdsec-engine-remediation-metrics" >
<h2 class="crowdsec-engine-report-subtitle"><?= $block->escapeHtml(__('Metrics')) ?></h2>
<div class="description">
<h3><?= $block->escapeHtml(__('Current bouncing behaviors')) ?></h3>
<h3><?= $block->escapeHtml(__('Current bouncing behaviors settings')) ?></h3>
<ul>
<li>&bull;
<?php if ($block->isLocalBanEnabled()): ?>
<?=
$block->escapeHtml(
__('<i>Ban IP locally</i> setting is <b>enabled</b>
__('<i>Ban IP locally</i> <b>enabled</b>
&rarr; When a Magento scenario triggers an alert, IP <b>is banned</b> locally.'),
['i','a','b']
)
?>
<?php else: ?>
<?=
$block->escapeHtml(
__('<i>Ban IP locally</i> setting is <b>disabled</b>
__('<i>Ban IP locally</i> <b>disabled</b>
&rarr; When a Magento scenario triggers an alert, IP <b>is not banned locally</b>.'),
['i','a','b']
) ?>
Expand All @@ -59,30 +59,19 @@
<?php if ($block->isBanBouncingEnabled()): ?>
<?=
$block->escapeHtml(
__('<i>Block banned IP</i> setting is <b>enabled</b>
__('<i>Block banned IP</i> <b>enabled</b>
&rarr; Access is currently <b>blocked</b> for banned IP addresses.'),
['i','a','b']
) ?>
<?php else: ?>
<?=
$block->escapeHtml(
__('<i>Block banned IP</i> setting is <b>disabled</b>
__('<i>Block banned IP</i> <b>disabled</b>
&rarr; Access is currently <b>allowed</b> for banned IP addresses.'),
['i','a','b']
) ?>
<?php endif; ?>
</li>
<li>&bull;
<?=
$block->escapeHtml(
__(
'<i>Fallback</i> setting is <b>%1</b>
&rarr; Any remediation that differs from "ban" will be considered as a <b>%1</b> remediation.',
$block->getFallback()
),
['i','a','b']
) ?>
</li>
</ul>
<p class="notice"><?= $block->escapeHtml(__(
'You can change these behaviors by modifying decisions settings <a href="%1">here</a>.',
Expand Down

0 comments on commit 7f59a44

Please sign in to comment.