Skip to content

Commit 7cc9687

Browse files
Merge pull request #143 from julienloizelet/feat/multisite
Feat/multisite
2 parents cf57237 + e8e4fab commit 7cc9687

File tree

25 files changed

+671
-116
lines changed

25 files changed

+671
-116
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
name: End-to-end multisite
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- feat/multisite
7+
paths-ignore:
8+
- '**.md'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
env:
15+
# Allow ddev get to use a GitHub token to prevent rate limiting by tests
16+
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
18+
jobs:
19+
end-to-end-multisite:
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
wp-version: [ "4.9", "6.2" ]
24+
php-version: [ "7.2" ]
25+
subsite: ["site1", "site2"]
26+
27+
name: End-to-end Multisite
28+
runs-on: ubuntu-latest
29+
if: ${{ !contains(github.event.head_commit.message, 'chore(') }}
30+
31+
env:
32+
EXTENSION_NAME: "CrowdSec_Bouncer"
33+
EXTENSION_PATH: "wp-content/plugins/crowdsec"
34+
35+
steps:
36+
37+
- name: Install DDEV
38+
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures
39+
run: |
40+
curl -fsSL https://apt.fury.io/drud/gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/ddev.gpg > /dev/null
41+
echo "deb [signed-by=/etc/apt/trusted.gpg.d/ddev.gpg] https://apt.fury.io/drud/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list
42+
sudo apt-get -q update
43+
sudo apt-get -q -y install libnss3-tools ddev
44+
mkcert -install
45+
ddev config global --instrumentation-opt-in=false --omit-containers=dba,ddev-ssh-agent
46+
47+
48+
- name: Set WP_VERSION_CODE env
49+
# used in some directory path and conventional file naming
50+
# Example : 5.6.5 => wp565
51+
run: |
52+
echo "WP_VERSION_CODE=$(echo wp${{ matrix.wp-version }} | sed 's/\.//g' )" >> $GITHUB_ENV
53+
54+
- name: Create empty WordPress DDEV project (with Apache)
55+
run: ddev config --project-type=wordpress --project-name=${{ env.WP_VERSION_CODE }} --php-version=${{ matrix.php-version }} --webserver-type=apache-fpm
56+
57+
- name: Add Redis, Memcached, Crowdsec and Playwright
58+
run: |
59+
ddev get ddev/ddev-redis
60+
ddev get ddev/ddev-memcached
61+
ddev get julienloizelet/ddev-playwright
62+
# override redis.conf
63+
ddev get julienloizelet/ddev-tools
64+
ddev get julienloizelet/ddev-crowdsec-php
65+
66+
- name: Start DDEV
67+
run: ddev start
68+
69+
- name: Download WordPress
70+
run: ddev wp core download --version=${{ matrix.wp-version }}
71+
72+
- name: Setup Multisite WordPress ${{ matrix.wp-version }} with PHP ${{ matrix.php-version }}
73+
run: |
74+
ddev wp core multisite-install --url='https://${{ env.WP_VERSION_CODE }}.ddev.site' --title='WordPress' --admin_user='admin' --admin_password='admin123' --admin_email='admin@admin.com'
75+
76+
- name: Copy multisite .htaccess
77+
run: cp .ddev/okaeli-add-on/wordpress/custom_files/.htaccess-multisite-subfolder .htaccess
78+
79+
- name: Prepare multisite config
80+
run: |
81+
sed -i -e 's/#ddev-generated//g' wp-config-ddev.php
82+
sed -i -e 's/REPLACE_SUBDOMAIN_INSTALL/false/g' .ddev/okaeli-add-on/wordpress/custom_files/multisite-config.php
83+
sed -i -e 's/REPLACE_PROJECT_URI/${{ env.WP_VERSION_CODE }}.ddev.site/g' .ddev/okaeli-add-on/wordpress/custom_files/multisite-config.php
84+
sed -i '/DB_HOST/ r .ddev/okaeli-add-on/wordpress/custom_files/multisite-config.php' wp-config-ddev.php
85+
sed -i -e 's/#ddev-generated//g' wp-config-ddev.php
86+
87+
- name: Create sub sites
88+
run: |
89+
ddev wp site create --slug="site1" --title="WordPress Site1"
90+
ddev wp site create --slug="site2" --title="WordPress Site2"
91+
92+
- name: Clone ${{ env.EXTENSION_NAME }} files
93+
uses: actions/checkout@v3
94+
with:
95+
path: ${{ env.EXTENSION_PATH }}
96+
97+
- name: Prepare for playwright test
98+
run: |
99+
mkdir -p crowdsec/tls
100+
mkdir -p crowdsec/geolocation
101+
cp .ddev/okaeli-add-on/wordpress/custom_files/crowdsec/php/cache-actions-from-plugin-folder.php cache-actions.php
102+
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* crowdsec/tls
103+
ddev maxmind-download DEFAULT GeoLite2-City crowdsec/geolocation
104+
ddev maxmind-download DEFAULT GeoLite2-Country crowdsec/geolocation
105+
cd crowdsec/geolocation
106+
sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
107+
sha256sum -c GeoLite2-City.tar.gz.sha256.txt
108+
tar -xf GeoLite2-Country.tar.gz
109+
tar -xf GeoLite2-City.tar.gz
110+
rm GeoLite2-Country.tar.gz GeoLite2-Country.tar.gz.sha256.txt GeoLite2-City.tar.gz GeoLite2-City.tar.gz.sha256.txt
111+
cd ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev/__scripts__
112+
chmod +x test-init.sh
113+
./test-init.sh
114+
chmod +x run-tests.sh
115+
116+
- name: Some DEBUG information
117+
run: |
118+
ddev --version
119+
ddev exec php -v
120+
ddev exec -s crowdsec crowdsec -version
121+
122+
- name: Run Plugin activation tests
123+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
124+
with:
125+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
126+
file_path: 1-activate-plugin.js
127+
subsite: ${{ matrix.subsite }}
128+
129+
- name: Configure CrowdSec and Wordpress bouncer plugin
130+
run: |
131+
ddev crowdsec-config
132+
133+
- name: Run Live mode remediation tests
134+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
135+
with:
136+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
137+
file_path: 2-live-mode-remediations.js
138+
subsite: ${{ matrix.subsite }}
139+
140+
- name: Run more Live mode remediation tests
141+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
142+
with:
143+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
144+
file_path: 3-live-mode-more.js
145+
subsite: ${{ matrix.subsite }}
146+
147+
- name: Run Live mode cache tests
148+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
149+
with:
150+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
151+
file_path: 4-live-mode-cache.js
152+
subsite: ${{ matrix.subsite }}
153+
154+
- name: Prepare cron usage
155+
run: |
156+
sed -i 's/fastcgi_finish_request/\/\/fastcgi_finish_request/g' wp-cron.php
157+
158+
- name: Run Stream mode tests
159+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
160+
with:
161+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
162+
file_path: 5-stream-mode.js
163+
subsite: ${{ matrix.subsite }}
164+
165+
- name: Run Redis tests
166+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
167+
with:
168+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
169+
file_path: 6-redis.js
170+
subsite: ${{ matrix.subsite }}
171+
172+
- name: Run Memcached tests
173+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
174+
with:
175+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
176+
file_path: 7-memcached.js
177+
subsite: ${{ matrix.subsite }}
178+
179+
- name: Run Geolocation tests
180+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
181+
with:
182+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
183+
file_path: 8-geolocation.js
184+
subsite: ${{ matrix.subsite }}
185+
186+
187+
- name: tmate debugging session
188+
uses: mxschmitt/action-tmate@v3
189+
with:
190+
limit-access-to-actor: true
191+
github-token: ${{ secrets.GITHUB_TOKEN }}
192+
timeout-minutes: 15
193+
if: failure()

.github/workflows/end-to-end/run-single-test/action.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ inputs:
1010
required: true
1111
description: "Path to the js test file"
1212

13+
subsite:
14+
required: false
15+
description: "Subsite for Multisite frontend test"
16+
1317
runs:
1418
using: "composite"
1519
steps:
1620
- name: Run test
1721
shell: bash
1822
run: |
1923
cd ${{ inputs.test_path }}/__scripts__
20-
./run-tests.sh ci "./__tests__/${{ inputs.file_path }}"
24+
./run-tests.sh ci "./__tests__/${{ inputs.file_path }}" "${{ inputs.subsite }}"
2125
cd ${{ inputs.test_path }}
2226
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
2327
if [[ $PENDING_TESTS == "0" ]]

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
- name: WordPress Plugin Deploy
126126
if: github.event.inputs.deploy_to_wordpress == 'true'
127127
id: deploy
128-
uses: 10up/action-wordpress-plugin-deploy@2.1.1
128+
uses: 10up/action-wordpress-plugin-deploy@2.2.0
129129
with:
130130
generate-zip: true
131131
env:
@@ -333,4 +333,4 @@ jobs:
333333
limit-access-to-actor: true
334334
github-token: ${{ secrets.GITHUB_TOKEN }}
335335
timeout-minutes: 30
336-
if: failure()
336+
if: failure()

CHANGELOG.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77

8+
## [2.5.0](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.5.0) - 2023-06-01
9+
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v2.4.1...v2.5.0)
10+
11+
### Added
12+
13+
- Add WordPress multisite compatibility
14+
15+
16+
---
17+
18+
819
## [2.4.1](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.4.1) - 2023-04-28
920
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v2.4.0...v2.4.1)
1021

@@ -13,11 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1324
- No change. Release to test update process hook.
1425

1526

16-
1727
---
1828

1929

20-
2130
## [2.4.0](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.4.0) - 2023-04-28
2231
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v2.3.1...v2.4.0)
2332

crowdsec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/crowdsecurity/cs-wordpress-bouncer
55
* Description: Safer Together. Protect your WordPress application with CrowdSec.
66
* Tags: crowdsec-bouncer, wordpress, security, firewall, captcha, ip-scanner, ip-blocker, ip-blocking, ip-address, ip-database, ip-range-check, crowdsec, ban-hosts, ban-management, anti-hacking, hacker-protection, captcha-image, captcha-generator, captcha-generation, captcha-service
7-
* Version: 2.4.1
7+
* Version: 2.5.0
88
* Author: CrowdSec
99
* Author URI: https://www.crowdsec.net/
1010
* Github: https://github.com/crowdsecurity/cs-wordpress-bouncer
@@ -13,7 +13,7 @@
1313
* Requires PHP: 7.2
1414
* Requires at least: 4.9
1515
* Tested up to: 6.2
16-
* Stable tag: 2.4.1
16+
* Stable tag: 2.5.0
1717
* Text Domain: crowdsec-wp
1818
* First release: 2021.
1919
*/

docs/USER_GUIDE.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Please note that it is possible to customize all the colors of these pages in a
6161

6262
On the other hand, all texts are also fully customizable. This will allow you, for example, to present translated pages in your users’ language.
6363

64-
6564
### Configurations
6665

6766
This plugin comes with configurations that you will find under `CrowdSec` admin section.
@@ -592,7 +591,18 @@ If you are using Apache, you should add this line to your `.htaccess` file:
592591

593592
php_value auto_prepend_file "/wordpress-root-directory/wp-content/plugins/crowdsec/inc/standalone-bounce.php"
594593

594+
### Multisite usage
595+
596+
If you are using the [`multisite` WordPress feature](https://wordpress.org/documentation/article/wordpress-glossary/#multisite), the bouncer plugin has to be network activated and
597+
configurations will be used for all sites of the network. This means that every individual site on your network will be protected by the bouncer with the same settings.
598+
599+
#### Differences with a single installation
600+
601+
In a WordPress multisite installation, `CrowdSec` configurations are accessible via the `My Sites -> Network admin` left panel.
602+
603+
![Multisite admin](./images/screenshots/admin-multisite.jpg)
595604

605+
Settings are stored in the `wp_sitemeta` table instead of the `wp_options` table for a single WordPress installation.
596606

597607
## Resources
598608

68.3 KB
Loading

inc/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ class Constants extends LibConstants
2020
public const LOG_BASE_PATH = __DIR__ . '/../logs/';
2121
public const CACHE_PATH = __DIR__ . '/../.cache';
2222
public const CONFIG_PATH = __DIR__ . '/standalone-settings.php';
23-
public const VERSION = 'v2.4.1';
23+
public const VERSION = 'v2.5.0';
2424
}

0 commit comments

Comments
 (0)