-
Notifications
You must be signed in to change notification settings - Fork 2
859 lines (799 loc) · 46.7 KB
/
php-sdk-development-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
name: PHP SDK development tests
on:
workflow_dispatch:
inputs:
php_common_json:
type: string
description: The PHP common json to use
required: true
default: '["main","crowdsecurity/php-common"]'
lapi_client_json:
type: string
description: The LAPI client json to use
required: true
default: '["main","crowdsecurity/php-lapi-client"]'
capi_client_json:
type: string
description: The CAPI client json to use
required: true
default: '["main","crowdsecurity/php-capi-client"]'
remediation_engine_json:
type: string
description: The Remediation Engine json to use
required: true
default: '["main", "crowdsecurity/php-remediation-engine"]'
bouncer_lib_json:
type: string
description: The PHP bouncer library json to use
required: true
default: '["main", "crowdsecurity/php-cs-bouncer"]'
workflow_call:
# For workflow_call, we don't allow passing a repository as input
inputs:
is_call:
type: boolean
description: "Flag to indicate if the workflow is called"
# @see https://github.com/actions/runner/discussions/1884
required: false
default: true
php_common_json:
type: string
description: The PHP common json to use
required: true
default: '["main"]'
lapi_client_json:
type: string
description: The LAPI client json to use
required: true
default: '["main"]'
capi_client_json:
type: string
description: The CAPI client json to use
required: true
default: '["main"]'
remediation_engine_json:
type: string
description: The Remediation Engine json to use
required: true
default: '["main"]'
bouncer_lib_json:
type: string
description: The PHP bouncer library json to use
required: true
default: '["main"]'
permissions:
contents: read
env:
# Allow ddev get to use a GitHub token to prevent rate limiting by tests
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STANDALONE_BOUNCER_REPO: crowdsecurity/cs-standalone-php-bouncer
BOUNCER_LIB_REPO: crowdsecurity/php-cs-bouncer
REMEDIATION_ENGINE_REPO: crowdsecurity/php-remediation-engine
CAPI_CLIENT_REPO: crowdsecurity/php-capi-client
LAPI_CLIENT_REPO: crowdsecurity/php-lapi-client
PHP_COMMON_REPO: crowdsecurity/php-common
PHP_COMMON_JSON: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.php_common_json || inputs.php_common_json }}
LAPI_CLIENT_JSON: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.lapi_client_json || inputs.lapi_client_json }}
REMEDIATION_ENGINE_JSON: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.remediation_engine_json || inputs.remediation_engine_json }}
BOUNCER_LIB_JSON: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.bouncer_lib_json || inputs.bouncer_lib_json }}
CAPI_CLIENT_JSON: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.capi_client_json || inputs.capi_client_json }}
jobs:
test-suite:
strategy:
fail-fast: false
matrix:
php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]
name: Test suite
runs-on: ubuntu-20.04
if: ${{ !contains(github.event.head_commit.message, 'chore(') }}
env:
EXTENSION_PATH: "my-code/standalone-bouncer"
BOUNCER_LIB_PATH: "my-code/php-bouncer-lib"
REMEDIATION_ENGINE_PATH: "my-code/php-remediation-engine"
CAPI_CLIENT_PATH: "my-code/php-capi-client"
LAPI_CLIENT_PATH: "my-code/php-lapi-client"
PHP_COMMON_PATH: "my-code/php-common"
DDEV_PROJECT: "crowdsec-standalone-bouncer"
JP_TEST_IP: "210.249.74.42"
IPV6_TEST_IP: "2001:0db8:0000:85a3:0000:0000:ac1f:8001"
IPV6_TEST_PROXY_IP: "2345:0425:2CA1:0000:0000:0567:5673:23b5"
steps:
- name: Set PHP common variables
id: set-common-data
run: |
echo "branch=${{ fromJson(env.PHP_COMMON_JSON)[0] }}" >> $GITHUB_OUTPUT
if [ "${{ inputs.is_call }}" = "true" ]; then
echo "repo=${{env.PHP_COMMON_REPO}}" >> $GITHUB_OUTPUT
else
echo "repo=${{ fromJson(env.PHP_COMMON_JSON)[1] }}" >> $GITHUB_OUTPUT
fi
- name: Set LAPI client variables
id: set-lapi-client-data
run: |
echo "branch=${{ fromJson(env.LAPI_CLIENT_JSON)[0] }}" >> $GITHUB_OUTPUT
if [ "${{ inputs.is_call }}" = "true" ]; then
echo "repo=${{env.LAPI_CLIENT_REPO}}" >> $GITHUB_OUTPUT
else
echo "repo=${{ fromJson(env.LAPI_CLIENT_JSON)[1] }}" >> $GITHUB_OUTPUT
fi
- name: Set CAPI client variables
id: set-capi-client-data
run: |
echo "branch=${{ fromJson(env.CAPI_CLIENT_JSON)[0] }}" >> $GITHUB_OUTPUT
if [ "${{ inputs.is_call }}" = "true" ]; then
echo "repo=${{env.CAPI_CLIENT_REPO}}" >> $GITHUB_OUTPUT
else
echo "repo=${{ fromJson(env.CAPI_CLIENT_JSON)[1] }}" >> $GITHUB_OUTPUT
fi
- name: Set Remediation engine variables
id: set-remediation-engine-data
run: |
echo "branch=${{ fromJson(env.REMEDIATION_ENGINE_JSON)[0] }}" >> $GITHUB_OUTPUT
if [ "${{ inputs.is_call }}" = "true" ]; then
echo "repo=${{env.REMEDIATION_ENGINE_REPO}}" >> $GITHUB_OUTPUT
else
echo "repo=${{ fromJson(env.REMEDIATION_ENGINE_JSON)[1] }}" >> $GITHUB_OUTPUT
fi
- name: Set Bouncer library variables
id: set-bouncer-lib-data
run: |
echo "branch=${{ fromJson(env.BOUNCER_LIB_JSON)[0] }}" >> $GITHUB_OUTPUT
if [ "${{ inputs.is_call }}" = "true" ]; then
echo "repo=${{env.BOUNCER_LIB_REPO}}" >> $GITHUB_OUTPUT
else
echo "repo=${{ fromJson(env.BOUNCER_LIB_JSON)[1] }}" >> $GITHUB_OUTPUT
fi
- name: Install DDEV
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures
run: |
curl -fsSL https://apt.fury.io/drud/gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/ddev.gpg > /dev/null
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
sudo apt-get -q update
sudo apt-get -q -y install libnss3-tools ddev
mkcert -install
ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent
- name: Create empty PHP DDEV project
run: ddev config --project-type=php --project-name=${{env.DDEV_PROJECT}} --php-version=${{ matrix.php-version }}
- name: Add Redis, Memcached and Crowdsec
run: |
ddev add-on get ddev/ddev-redis
ddev add-on get ddev/ddev-memcached
# override redis.conf
ddev add-on get julienloizelet/ddev-tools
ddev add-on get julienloizelet/ddev-crowdsec-php
ddev add-on get julienloizelet/ddev-playwright
- name: Start DDEV
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 3
shell: bash
command: ddev start
- name: Set BOUNCER_KEY and PROXY_IP env
run: |
echo "BOUNCER_KEY=$(ddev create-bouncer)" >> $GITHUB_ENV
echo "PROXY_IP=$(ddev find-ip ddev-router)" >> $GITHUB_ENV
- name: Some DEBUG information
run: |
ddev --version
ddev exec php -v
ddev exec -s crowdsec crowdsec -version
ddev php -r "echo phpversion('memcached');"
- name: Clone standalone bouncer files
if: inputs.is_call != true
uses: actions/checkout@v4
with:
path: ${{env.EXTENSION_PATH}}
- name: Clone Standalone bouncer files
if: inputs.is_call == true
uses: actions/checkout@v4
with:
repository: ${{ env.STANDALONE_BOUNCER_REPO }}
path: ${{env.EXTENSION_PATH}}
ref: "main"
- name: Clone PHP common files
uses: actions/checkout@v4
with:
repository: ${{ steps.set-common-data.outputs.repo}}
ref: ${{ steps.set-common-data.outputs.branch }}
path: ${{env.PHP_COMMON_PATH}}
- name: Clone PHP LAPI client
uses: actions/checkout@v4
with:
repository: ${{ steps.set-lapi-client-data.outputs.repo }}
ref: ${{ steps.set-lapi-client-data.outputs.branch }}
path: ${{env.LAPI_CLIENT_PATH}}
- name: Clone PHP CAPI client
uses: actions/checkout@v4
with:
repository: ${{ steps.set-capi-client-data.outputs.repo }}
ref: ${{ steps.set-capi-client-data.outputs.branch }}
path: ${{env.CAPI_CLIENT_PATH}}
- name: Clone PHP remediation engine
uses: actions/checkout@v4
with:
repository: ${{ steps.set-remediation-engine-data.outputs.repo }}
ref: ${{ steps.set-remediation-engine-data.outputs.branch }}
path: ${{env.REMEDIATION_ENGINE_PATH}}
- name: Clone PHP bouncer lib
uses: actions/checkout@v4
with:
repository: ${{ steps.set-bouncer-lib-data.outputs.repo }}
ref: ${{ steps.set-bouncer-lib-data.outputs.branch }}
path: ${{env.BOUNCER_LIB_PATH}}
- name: Add local repositories to composer
run: |
# Standalone bouncer
ddev exec --raw composer config repositories.0 '{"type": "path", "url": "../php-common", "options": {"symlink": true}}' --working-dir ./${{ env.EXTENSION_PATH }}
ddev exec --raw composer config repositories.1 '{"type": "path", "url": "../php-lapi-client", "options": {"symlink": true}}' --working-dir ./${{ env.EXTENSION_PATH }}
ddev exec --raw composer config repositories.2 '{"type": "path", "url": "../php-remediation-engine", "options": {"symlink": true}}' --working-dir ./${{ env.EXTENSION_PATH }}
ddev exec --raw composer config repositories.3 '{"type": "path", "url": "../php-bouncer-lib", "options": {"symlink": true}}' --working-dir ./${{ env.EXTENSION_PATH }}
ddev exec --raw composer config repositories.4 '{"type": "path", "url": "../php-capi-client", "options": {"symlink": true}}' --working-dir ./${{ env.EXTENSION_PATH }}
# Bouncer lib
ddev exec --raw composer config repositories.0 '{"type": "path", "url": "../php-common", "options": {"symlink": true}}' --working-dir ./${{ env.BOUNCER_LIB_PATH }}
ddev exec --raw composer config repositories.1 '{"type": "path", "url": "../php-lapi-client", "options": {"symlink": true}}' --working-dir ./${{ env.BOUNCER_LIB_PATH }}
ddev exec --raw composer config repositories.2 '{"type": "path", "url": "../php-remediation-engine", "options": {"symlink": true}}' --working-dir ./${{ env.BOUNCER_LIB_PATH }}
ddev exec --raw composer config repositories.3 '{"type": "path", "url": "../php-capi-client", "options": {"symlink": true}}' --working-dir ./${{ env.BOUNCER_LIB_PATH }}
# Remediation engine
ddev exec --raw composer config repositories.0 '{"type": "path", "url": "../php-common", "options": {"symlink": true}}' --working-dir ./${{ env.REMEDIATION_ENGINE_PATH }}
ddev exec --raw composer config repositories.1 '{"type": "path", "url": "../php-lapi-client", "options": {"symlink": true}}' --working-dir ./${{ env.REMEDIATION_ENGINE_PATH }}
ddev exec --raw composer config repositories.2 '{"type": "path", "url": "../php-capi-client", "options": {"symlink": true}}' --working-dir ./${{ env.REMEDIATION_ENGINE_PATH }}
# CAPI client
ddev exec --raw composer config repositories.0 '{"type": "path", "url": "../php-common", "options": {"symlink": true}}' --working-dir ./${{ env.CAPI_CLIENT_PATH }}
# LAPI client
ddev exec --raw composer config repositories.0 '{"type": "path", "url": "../php-common", "options": {"symlink": true}}' --working-dir ./${{ env.LAPI_CLIENT_PATH }}
- name: Modify dependencies to use development aliases
run: |
# Standalone bouncer
ddev exec --raw composer require crowdsec/bouncer:"dev-${{ steps.set-bouncer-lib-data.outputs.branch }}" --no-update --working-dir ./${{env.EXTENSION_PATH}}
ddev exec --raw composer require crowdsec/common:"dev-${{ steps.set-common-data.outputs.branch }}" --no-update --working-dir ./${{env.EXTENSION_PATH}}
ddev exec --raw composer require crowdsec/lapi-client:"dev-${{ steps.set-lapi-client-data.outputs.branch }}" --no-update --working-dir ./${{env.EXTENSION_PATH}}
ddev exec --raw composer require crowdsec/remediation-engine:"dev-${{ steps.set-remediation-engine-data.outputs.branch }}" --no-update --working-dir ./${{env.EXTENSION_PATH}}
ddev exec --raw composer require crowdsec/capi-client:"dev-${{ steps.set-capi-client-data.outputs.branch }}" --no-update --working-dir ./${{env.EXTENSION_PATH}}
# Bouncer lib
ddev exec --raw composer require crowdsec/common:"dev-${{ steps.set-common-data.outputs.branch }}" --no-update --working-dir ./${{env.BOUNCER_LIB_PATH}}
ddev exec --raw composer require crowdsec/lapi-client:"dev-${{ steps.set-lapi-client-data.outputs.branch }}" --no-update --working-dir ./${{env.BOUNCER_LIB_PATH}}
ddev exec --raw composer require crowdsec/remediation-engine:"dev-${{ steps.set-remediation-engine-data.outputs.branch }}" --no-update --working-dir ./${{env.BOUNCER_LIB_PATH}}
ddev exec --raw composer require crowdsec/capi-client:"dev-${{ steps.set-capi-client-data.outputs.branch }}" --no-update --working-dir ./${{env.BOUNCER_LIB_PATH}}
# Remediation engine
ddev exec --raw composer require crowdsec/common:"dev-${{ steps.set-common-data.outputs.branch }}" --no-update --working-dir ./${{env.REMEDIATION_ENGINE_PATH}}
ddev exec --raw composer require crowdsec/lapi-client:"dev-${{ steps.set-lapi-client-data.outputs.branch }}" --no-update --working-dir ./${{env.REMEDIATION_ENGINE_PATH}}
ddev exec --raw composer require crowdsec/capi-client:"dev-${{ steps.set-capi-client-data.outputs.branch }}" --no-update --working-dir ./${{env.REMEDIATION_ENGINE_PATH}}
# CAPI client
ddev exec --raw composer require crowdsec/common:"dev-${{ steps.set-common-data.outputs.branch }}" --no-update --working-dir ./${{env.CAPI_CLIENT_PATH}}
# LAPI client
ddev exec --raw composer require crowdsec/common:"dev-${{ steps.set-common-data.outputs.branch }}" --no-update --working-dir ./${{env.LAPI_CLIENT_PATH}}
- name: Validate composer.json
run: |
# Standalone bouncer
cat ./${{env.EXTENSION_PATH}}/composer.json
ddev composer validate --strict --working-dir ./${{env.EXTENSION_PATH}}
# Bouncer lib
cat ./${{env.BOUNCER_LIB_PATH}}/composer.json
ddev composer validate --strict --working-dir ./${{env.BOUNCER_LIB_PATH}}
# Remediation engine
cat ./${{env.REMEDIATION_ENGINE_PATH}}/composer.json
ddev composer validate --strict --working-dir ./${{env.REMEDIATION_ENGINE_PATH}}
# CAPI client
cat ./${{env.CAPI_CLIENT_PATH}}/composer.json
ddev composer validate --strict --working-dir ./${{env.CAPI_CLIENT_PATH}}
# LAPI client
cat ./${{env.LAPI_CLIENT_PATH}}/composer.json
ddev composer validate --strict --working-dir ./${{env.LAPI_CLIENT_PATH}}
- name: Install CrowdSec lib dependencies
run: |
ddev composer update --working-dir ./${{env.EXTENSION_PATH}}
- name: Check installed packages versions
run: |
PHP_COMMON_VERSION=$(ddev composer show crowdsec/common --working-dir ./${{env.EXTENSION_PATH}} | grep -oP "versions : \* \K(.*)")
if [[ $PHP_COMMON_VERSION == "dev-${{ steps.set-common-data.outputs.branch }}" ]]
then
echo "PHP_COMMON_VERSION COMPARISON OK"
else
echo "PHP_COMMON_VERSION COMPARISON KO"
echo $PHP_COMMON_VERSION
exit 1
fi
LAPI_CLIENT_VERSION=$(ddev composer show crowdsec/lapi-client --working-dir ./${{env.EXTENSION_PATH}} | grep -oP "versions : \* \K(.*)")
if [[ $LAPI_CLIENT_VERSION == "dev-${{ steps.set-lapi-client-data.outputs.branch }}" ]]
then
echo "LAPI_CLIENT_VERSION COMPARISON OK"
else
echo "LAPI_CLIENT_VERSION COMPARISON KO"
echo $LAPI_CLIENT_VERSION
exit 1
fi
CAPI_CLIENT_VERSION=$(ddev composer show crowdsec/capi-client --working-dir ./${{env.EXTENSION_PATH}} | grep -oP "versions : \* \K(.*)")
if [[ $CAPI_CLIENT_VERSION == "dev-${{ steps.set-capi-client-data.outputs.branch }}" ]]
then
echo "CAPI_CLIENT_VERSION COMPARISON OK"
else
echo "CAPI_CLIENT_VERSION COMPARISON KO"
echo $CAPI_CLIENT_VERSION
exit 1
fi
REMEDIATION_ENGINE_VERSION=$(ddev composer show crowdsec/remediation-engine --working-dir ./${{env.EXTENSION_PATH}} | grep -oP "versions : \* \K(.*)")
if [[ $REMEDIATION_ENGINE_VERSION == "dev-${{ steps.set-remediation-engine-data.outputs.branch }}" ]]
then
echo "REMEDIATION_ENGINE_VERSION COMPARISON OK"
else
echo "REMEDIATION_ENGINE_VERSION COMPARISON KO"
echo $REMEDIATION_ENGINE_VERSION
exit 1
fi
BOUNCER_LIB_VERSION=$(ddev composer show crowdsec/bouncer --working-dir ./${{env.EXTENSION_PATH}} | grep -oP "versions : \* \K(.*)")
if [[ $BOUNCER_LIB_VERSION == "dev-${{ steps.set-bouncer-lib-data.outputs.branch }}" ]]
then
echo "BOUNCER_LIB_VERSION COMPARISON OK"
else
echo "BOUNCER_LIB_VERSION COMPARISON KO"
echo $BOUNCER_LIB_VERSION
exit 1
fi
- name: Run "Unit Tests"
run: |
ddev exec /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors ./${{env.EXTENSION_PATH}}/tests/Unit
- name: Prepare PHP Integration and end-to-end tests
run: |
mkdir ${{ github.workspace }}/cfssl
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* ${{ github.workspace }}/cfssl
ddev maxmind-download DEFAULT GeoLite2-City /var/www/html/${{env.EXTENSION_PATH}}/tests
ddev maxmind-download DEFAULT GeoLite2-Country /var/www/html/${{env.EXTENSION_PATH}}/tests
cd ${{env.EXTENSION_PATH}}/tests
sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
sha256sum -c GeoLite2-City.tar.gz.sha256.txt
tar -xf GeoLite2-Country.tar.gz
tar -xf GeoLite2-City.tar.gz
rm GeoLite2-Country.tar.gz GeoLite2-Country.tar.gz.sha256.txt GeoLite2-City.tar.gz GeoLite2-City.tar.gz.sha256.txt
- name: Run "IP verification with file_get_contents" test
run: |
ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} AGENT_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Integration/IpVerificationTest.php
- name: Run "IP verification with cURL" test
run: |
ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} AGENT_TLS_PATH=/var/www/html/cfssl USE_CURL=1 APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Integration/IpVerificationTest.php
- name: Run "IP verification with TLS" test
run: |
ddev exec AGENT_TLS_PATH=/var/www/html/cfssl BOUNCER_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Integration/IpVerificationTest.php
- name: Run "Geolocation with file_get_contents" test
run: |
ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} AGENT_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Integration/GeolocationTest.php
- name: Run "Geolocation with cURL" test
run: |
ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} AGENT_TLS_PATH=/var/www/html/cfssl USE_CURL=1 APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Integration/GeolocationTest.php
- name: Prepare Standalone Bouncer end-to-end tests
run: |
# Enabel auto-prepend in Nginx
cd ${{ github.workspace }}/.ddev
ddev nginx-config okaeli-add-on/native/custom_files/crowdsec/crowdsec-prepend-nginx-site.conf
# Add iproute2 for timeout simulation
ddev exec -s crowdsec apk add iproute2
# Prepare settings
cd ${{ github.workspace }}
cp ${{env.EXTENSION_PATH}}/tests/end-to-end/settings/base.php.dist crowdsec-lib-settings.php
sed -i -e 's#REPLACE_API_KEY#${{ env.BOUNCER_KEY }}#g' crowdsec-lib-settings.php
sed -i -e 's/REPLACE_PROXY_IP/${{ env.PROXY_IP }}/g' crowdsec-lib-settings.php
sed -i -e 's/REPLACE_FORCED_IP//g' crowdsec-lib-settings.php
sed -i -e 's/REPLACE_FORCED_FORWARDED_IP//g' crowdsec-lib-settings.php
mv crowdsec-lib-settings.php ${{env.EXTENSION_PATH}}/scripts/settings.php
# Prepare tests scripts
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/__scripts__
chmod +x test-init.sh
./test-init.sh
chmod +x run-tests.sh
- name: Verify auto_prepend_file directive
run: |
cd ${{ github.workspace }}
cp .ddev/okaeli-add-on/common/custom_files/phpinfo.php ${{env.EXTENSION_PATH}}/tests/scripts/public/phpinfo.php
curl -v https://${{env.DDEV_PROJECT}}.ddev.site/${{env.EXTENSION_PATH}}/tests/scripts/public/phpinfo.php
PREPENDVERIF=$(curl https://${{env.DDEV_PROJECT}}.ddev.site/${{env.EXTENSION_PATH}}/tests/scripts/public/phpinfo.php | grep -o -E "auto_prepend_file=(.*)php(.*)" | sed 's/<\/tr>//g; s/<\/td>//g;' | tr '\n' '#')
if [[ $PREPENDVERIF == "auto_prepend_file=/var/www/html/${{env.EXTENSION_PATH}}/scripts/bounce.php#auto_prepend_file=/var/www/html/${{env.EXTENSION_PATH}}/scripts/bounce.php#" ]]
then
echo "AUTO PREPEND FILE OK"
else
echo "AUTO PREPEND FILE KO"
echo $PREPENDVERIF
exit 1
fi
- name: Run "live mode with file_get_contents and without geolocation" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Increase cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 1/\x27clean_ip_cache_duration\x27 => 3/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/1-live-mode.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "Display error with bad settings" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/\x27cache_system\x27 => 1/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/6-display-error-on.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "No display error with bad settings" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27display_errors\x27 => true/\x27display_errors\x27 => false/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/5-display-error-off.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "No display error with error while bouncing" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27cache_system\x27 => 1/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/g' scripts/settings.php
sed -i 's/\x27forced_test_ip\x27 => \x27\x27/\x27forced_test_ip\x27 => \x27bad-ip\x27/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/5-display-error-off.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "Display error with error while bouncing" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27display_errors\x27 => false/\x27display_errors\x27 => true/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/6-display-error-on.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "live mode with cURL and without geolocation" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Increase cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 1/\x27clean_ip_cache_duration\x27 => 3/g' scripts/settings.php
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/settings.php
sed -i 's/\x27forced_test_ip\x27 => \x27bad-ip\x27/\x27forced_test_ip\x27 => \x27\x27/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/1-live-mode.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "live mode with file_get_contents and with geolocation" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27use_curl\x27 => true/\x27use_curl\x27 => false/g' scripts/settings.php
sed -i 's/\x27enabled\x27 => false/\x27enabled\x27 => true/g' scripts/settings.php
sed -i 's/\x27forced_test_forwarded_ip\x27 => \x27\x27/\x27forced_test_forwarded_ip\x27 => \x27${{env.JP_TEST_IP}}\x27/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/2-live-mode-with-geolocation.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "live mode with cURL and with geolocation" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/settings.php
sed -i 's/\x27enabled\x27 => false/\x27enabled\x27 => true/g' scripts/settings.php
sed -i 's/\x27forced_test_forwarded_ip\x27 => \x27\x27/\x27forced_test_forwarded_ip\x27 => \x27${{env.JP_TEST_IP}}\x27/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/2-live-mode-with-geolocation.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "stream mode with file_get_contents and without geolocation" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27use_curl\x27 => true/\x27use_curl\x27 => false/g' scripts/settings.php
sed -i 's/\x27enabled\x27 => true/\x27enabled\x27 => false/g' scripts/settings.php
sed -i 's/\x27forced_test_forwarded_ip\x27 => \x27${{env.JP_TEST_IP}}\x27/\x27forced_test_forwarded_ip\x27 => \x27\x27/g' scripts/settings.php
sed -i 's/\x27stream_mode\x27 => false/\x27stream_mode\x27 => true/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/3-stream-mode.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "stream mode with cURL and without geolocation" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/settings.php
sed -i 's/\x27enabled\x27 => true/\x27enabled\x27 => false/g' scripts/settings.php
sed -i 's/\x27forced_test_forwarded_ip\x27 => \x27${{env.JP_TEST_IP}}\x27/\x27forced_test_forwarded_ip\x27 => \x27\x27/g' scripts/settings.php
sed -i 's/\x27stream_mode\x27 => false/\x27stream_mode\x27 => true/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/3-stream-mode.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "standalone geolocation" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/4-geolocation.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "live mode with IPv6" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Increase cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 1/\x27clean_ip_cache_duration\x27 => 3/g' scripts/settings.php
sed -i 's/\x27forced_test_forwarded_ip\x27 => \x27\x27/\x27forced_test_forwarded_ip\x27 => \x27${{env.IPV6_TEST_IP}}\x27/g' scripts/settings.php
sed -i 's/\x27forced_test_ip\x27 => \x27\x27/\x27forced_test_ip\x27 => \x27${{env.IPV6_TEST_PROXY_IP}}\x27/g' scripts/settings.php
sed -i -e 's/${{ env.PROXY_IP }}/${{env.IPV6_TEST_PROXY_IP}}/g' scripts/settings.php
sed -i 's/\x27stream_mode\x27 => true/\x27stream_mode\x27 => false/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/1-live-mode.js"
- name: Run "live mode with TLS auth" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Increase cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 1/\x27clean_ip_cache_duration\x27 => 3/g' scripts/settings.php
sed -i 's/\x27auth_type\x27 => \x27api_key\x27/\x27auth_type\x27 => \x27tls\x27/g' scripts/settings.php
sed -i 's#\x27api_key\x27 => \x27${{env.BOUNCER_KEY}}\x27#\x27api_key\x27 => \x27\x27#g' scripts/settings.php
sed -i 's/\x27tls_cert_path\x27 => \x27\x27/\x27tls_cert_path\x27 => \x27\/var\/www\/html\/cfssl\/bouncer.pem\x27/g' scripts/settings.php
sed -i 's/\x27tls_key_path\x27 => \x27\x27/\x27tls_key_path\x27 => \x27\/var\/www\/html\/cfssl\/bouncer-key.pem\x27/g' scripts/settings.php
sed -i 's/\x27tls_ca_cert_path\x27 => \x27\x27/\x27tls_ca_cert_path\x27 => \x27\/var\/www\/html\/cfssl\/ca-chain.pem\x27/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/1-live-mode.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "stream mode with TLS auth and cURL" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27stream_mode\x27 => false/\x27stream_mode\x27 => true/g' scripts/settings.php
sed -i 's/\x27forced_test_forwarded_ip\x27 => \x27${{env.IPV6_TEST_IP}}\x27/\x27forced_test_forwarded_ip\x27 => \x27\x27/g' scripts/settings.php
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/3-stream-mode.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "stream mode with TLS auth and cURL and Redis" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/\x27cache_system\x27 => Constants::CACHE_SYSTEM_REDIS/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/3-stream-mode.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "stream mode with TLS auth and cURL and Memcached" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Decrease cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 3/\x27clean_ip_cache_duration\x27 => 1/g' scripts/settings.php
sed -i 's/\x27cache_system\x27 => Constants::CACHE_SYSTEM_REDIS/\x27cache_system\x27 => Constants::CACHE_SYSTEM_MEMCACHED/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/3-stream-mode.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "AppSec with cURL" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Increase cache duration for clean IP
sed -i 's/\x27clean_ip_cache_duration\x27 => 1/\x27clean_ip_cache_duration\x27 => 3/g' scripts/settings.php
# Use Api key
sed -i 's#\x27api_key\x27 => \x27\x27#\x27api_key\x27 => \x27${{env.BOUNCER_KEY}}\x27#g' scripts/settings.php
sed -i 's/\x27auth_type\x27 => \x27tls\x27/\x27auth_type\x27 => \x27api_key\x27/g' scripts/settings.php
# Disable stream mode
sed -i 's/\x27stream_mode\x27 => true/\x27stream_mode\x27 => false/g' scripts/settings.php
# Use Redis
sed -i 's/\x27cache_system\x27 => Constants::CACHE_SYSTEM_MEMCACHED/\x27cache_system\x27 => Constants::CACHE_SYSTEM_REDIS/g' scripts/settings.php
# Enable AppSec
sed -i 's/\x27use_appsec\x27 => false/\x27use_appsec\x27 => true/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/7-appsec.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "AppSec with file_get_contents" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Disable curl
sed -i 's/\x27use_curl\x27 => true/\x27use_curl\x27 => false/g' scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/7-appsec.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "AppSec upload" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Set block as AppSec action
sed -i 's/\x27appsec_body_size_exceeded_action\x27 => \x27headers_only\x27/\x27appsec_body_size_exceeded_action\x27 => \x27block\x27/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/12-appsec-upload.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "AppSec POST too big body" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
sed -i 's/\x27appsec_max_body_size_kb\x27 => 1024/\x27appsec_max_body_size_kb\x27 => 1/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/11-appsec-max-body-ban.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "AppSec with timeout (captcha fallback) and file_get_contents" test
run: |
# Add delay
ddev exec -s crowdsec tc qdisc add dev eth0 root netem delay 500ms
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/8-appsec-timeout-captcha.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "AppSec with timeout (ban fallback) and cURL" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Use curl
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/settings.php
# Change AppSec fallback
sed -i 's/\x27appsec_fallback_remediation\x27 => Constants::REMEDIATION_CAPTCHA/\x27appsec_fallback_remediation\x27 => Constants::REMEDIATION_BAN/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/9-appsec-timeout-ban.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi
- name: Run "AppSec with timeout (bypass fallback) and cURL" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
# Change AppSec fallback
sed -i 's/\x27appsec_fallback_remediation\x27 => Constants::REMEDIATION_BAN/\x27appsec_fallback_remediation\x27 => Constants::REMEDIATION_BYPASS/g' scripts/settings.php
cat scripts/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/10-appsec-timeout-bypass.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi