Skip to content

Commit e25f13a

Browse files
test(redis): Add test for ACL connection
1 parent 6d125e0 commit e25f13a

File tree

5 files changed

+131
-1
lines changed

5 files changed

+131
-1
lines changed

.github/workflows/end-to-end-auto-prepend-test-suite.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ jobs:
229229
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
230230
file_path: 12-appsec-timeout.js
231231

232+
- name: Prepare Redis ACL tests
233+
run: |
234+
ddev exec -s crowdsec tc qdisc del dev eth0 root netem
235+
# Allow ACL tests
236+
echo "requirepass ddev" >> .ddev/redis/redis.conf
237+
echo "user redis_user allcommands allkeys on >redis_password" >> .ddev/redis/redis.conf
238+
docker restart ddev-${{ env.WP_VERSION_CODE }}-redis
239+
240+
- name: Run Redis ACL tests
241+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
242+
with:
243+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
244+
file_path:
245+
13-redis-acl.js
246+
232247
- name: Check tested version
233248
run: |
234249
CURRENT_VERSION=$(ddev wp core version)

.github/workflows/end-to-end-multisite.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ jobs:
222222
file_path: 12-appsec-timeout.js
223223
subsite: ${{ matrix.subsite }}
224224

225+
- name: Prepare Redis ACL tests
226+
run: |
227+
ddev exec -s crowdsec tc qdisc del dev eth0 root netem
228+
# Allow ACL tests
229+
echo "requirepass ddev" >> .ddev/redis/redis.conf
230+
echo "user redis_user allcommands allkeys on >redis_password" >> .ddev/redis/redis.conf
231+
docker restart ddev-${{ env.WP_VERSION_CODE }}-redis
232+
233+
- name: Run Redis ACL tests
234+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
235+
with:
236+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
237+
file_path: 13-redis-acl.js
238+
225239
- name: Check tested version
226240
run: |
227241
CURRENT_VERSION=$(ddev wp core version)

.github/workflows/end-to-end-test-suite.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ jobs:
205205
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
206206
file_path: 11-appsec.js
207207

208-
209208
- name: Prepare CrowdSec for AppSec timeout tests
210209
run: ddev exec -s crowdsec tc qdisc add dev eth0 root netem delay 500ms
211210

@@ -215,6 +214,20 @@ jobs:
215214
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
216215
file_path: 12-appsec-timeout.js
217216

217+
- name: Prepare Redis ACL tests
218+
run: |
219+
ddev exec -s crowdsec tc qdisc del dev eth0 root netem
220+
# Allow ACL tests
221+
echo "requirepass ddev" >> .ddev/redis/redis.conf
222+
echo "user redis_user allcommands allkeys on >redis_password" >> .ddev/redis/redis.conf
223+
docker restart ddev-${{ env.WP_VERSION_CODE }}-redis
224+
225+
- name: Run Redis ACL tests
226+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
227+
with:
228+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
229+
file_path: 13-redis-acl.js
230+
218231
- name: Check tested version
219232
run: |
220233
CURRENT_VERSION=$(ddev wp core version)

.github/workflows/release-test.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989
ddev get julienloizelet/ddev-tools
9090
ddev get julienloizelet/ddev-crowdsec-php
9191
92+
9293
- name: Start DDEV
9394
uses: nick-fields/retry@v3
9495
with:
@@ -234,6 +235,42 @@ jobs:
234235
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
235236
file_path: 11-appsec.js
236237

238+
- name: Prepare CrowdSec for AppSec timeout tests
239+
run: ddev exec -s crowdsec tc qdisc add dev eth0 root netem delay 500ms
240+
241+
- name: Run AppSec timeout tests
242+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
243+
with:
244+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
245+
file_path: 12-appsec-timeout.js
246+
247+
- name: Prepare Redis ACL tests
248+
run: |
249+
ddev exec -s crowdsec tc qdisc del dev eth0 root netem
250+
# Allow ACL tests
251+
echo "requirepass ddev" >> .ddev/redis/redis.conf
252+
echo "user redis_user allcommands allkeys on >redis_password" >> .ddev/redis/redis.conf
253+
docker restart ddev-${{ env.WP_VERSION_CODE }}-redis
254+
255+
- name: Run Redis ACL tests
256+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
257+
with:
258+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
259+
file_path: 13-redis-acl.js
260+
261+
- name: Check tested version
262+
run: |
263+
CURRENT_VERSION=$(ddev wp core version)
264+
if [[ ${{ matrix.wp-version }} == $CURRENT_VERSION ]]
265+
then
266+
echo "Tested version was as expected"
267+
else
268+
echo "Tested version was not as expected"
269+
echo $CURRENT_VERSION
270+
echo ${{ matrix.wp-version }}
271+
exit 1
272+
fi
273+
237274
- name: tmate debugging session
238275
uses: mxschmitt/action-tmate@v3
239276
with:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* eslint-disable no-undef */
2+
const {
3+
wait,
4+
goToAdmin,
5+
onAdminGoToAdvancedPage,
6+
onAdminSaveSettings,
7+
publicHomepageShouldBeBanWall,
8+
publicHomepageShouldBeAccessible,
9+
banOwnIpForSeconds,
10+
removeAllDecisions,
11+
forceCronRun,
12+
fillInput,
13+
onLoginPageLoginAsAdmin,
14+
setDefaultConfig,
15+
onAdvancedPageEnableStreamMode,
16+
} = require("../utils/helpers");
17+
18+
const { CURRENT_IP } = require("../utils/constants");
19+
20+
describe(`Use Redis technology with ACL`, () => {
21+
beforeAll(async () => {
22+
await removeAllDecisions();
23+
await goToAdmin();
24+
await onLoginPageLoginAsAdmin();
25+
await setDefaultConfig();
26+
});
27+
28+
it('Should be able to use Redis cache"', async () => {
29+
await goToAdmin();
30+
await onAdminGoToAdvancedPage();
31+
await onAdvancedPageEnableStreamMode();
32+
await page.selectOption("[name=crowdsec_cache_system]", "redis");
33+
await wait(200);
34+
await fillInput(
35+
"crowdsec_redis_dsn",
36+
"redis://redis_user:redis_password@redis:6379",
37+
);
38+
await onAdminSaveSettings();
39+
await expect(page).toHaveText(
40+
"#wpbody-content > div.wrap > div.notice.notice-success",
41+
"As the stream mode is enabled, the cache has just been refreshed.",
42+
);
43+
await publicHomepageShouldBeAccessible();
44+
await banOwnIpForSeconds(15 * 60, CURRENT_IP);
45+
await forceCronRun();
46+
await publicHomepageShouldBeBanWall();
47+
await removeAllDecisions();
48+
await forceCronRun();
49+
await publicHomepageShouldBeAccessible();
50+
});
51+
});

0 commit comments

Comments
 (0)