Skip to content

Commit a6ad396

Browse files
authored
Merge pull request #178 from microsoft/akishore/feature/ci
Add Github Action for CI
2 parents 724e856 + 44eb151 commit a6ad396

File tree

6 files changed

+131
-101
lines changed

6 files changed

+131
-101
lines changed

.github/workflows/main.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the waf_nginx branch
6+
push:
7+
branches: [ waf_nginx ]
8+
pull_request:
9+
branches: [ waf_nginx ]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
20+
- uses: actions/checkout@v2
21+
22+
# Runs a single command using the runners shell
23+
- name: Run a one-line script
24+
run: echo Logging into appgwreg
25+
# Logs into Azure Registry
26+
- name: Docker Login
27+
uses: docker/[email protected]
28+
with:
29+
registry: appgwreg.azurecr.io
30+
# Username used to log against the Docker registry
31+
username: ${{ secrets.DOCKER_USERNAME }}
32+
# Password or personal access token used to log against the Docker registry
33+
password: ${{ secrets.DOCKER_PASSWORD }}
34+
# Log out from the Docker registry at the end of a job
35+
logout: true
36+
# Runs make commands
37+
- name: Pull Image and Compile
38+
run: |
39+
docker pull appgwreg.azurecr.io/modsecurity:latest
40+
docker-compose run --rm autoconf
41+
docker-compose run --rm configure
42+
docker-compose run --rm make

.github/workflows/tests.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: IIS-tests
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the waf_nginx branch
6+
push:
7+
branches: [ waf_nginx ]
8+
pull_request:
9+
branches: [ waf_nginx ]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
jobs:
15+
build:
16+
runs-on: windows-2019
17+
steps:
18+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
19+
- uses: actions/checkout@v2
20+
# Setup Env
21+
- name: Install Modsec Dependencies
22+
run: cd iis; .\getModSecurityPkgs.ps1 https://modsecurity.blob.core.windows.net/windows-artifacts
23+
- name: Pre-Build Preparation
24+
run: |
25+
cd iis
26+
#setup the python virtual env - not a must but still
27+
py.exe -2 -m pip install virtualenv
28+
py.exe -2 -m virtualenv --version
29+
$python_proj_name = "test_crs3"
30+
py.exe -2 -m virtualenv $python_proj_name
31+
& ".\$python_proj_name\Scripts\activate.ps1"
32+
# Build
33+
- name: Build Modsec
34+
run: cd iis; ./build_release_amd64.bat
35+
# Test
36+
- name: Pre-Test Config
37+
run: |
38+
$python_proj_name = "test_crs3"
39+
& ".\iis\$python_proj_name\Scripts\activate.ps1"
40+
$modsec_repo = "$pwd"
41+
$modsec_conf = "$modsec_repo\iis\wix\modsecurity.conf"
42+
$modsec_iis_conf = "$modsec_repo\iis\wix\modsecurity_iis.conf"
43+
& {iisreset /stop} #need to stop iis before copy of files that are used by it
44+
#copy the xml file to the schema
45+
Copy-Item "$modsec_repo\iis\ModSecurity.xml" -Destination "$env:SystemRoot\System32\inetsrv\config\schema" -Force
46+
#set modsecurity in applicationhost.cofig
47+
[System.Reflection.Assembly]::LoadFrom("$env:systemroot\system32\inetsrv\Microsoft.Web.Administration.dll")
48+
$sm = new-object Microsoft.Web.Administration.ServerManager
49+
$rootSG = $sm.GetApplicationHostConfiguration().RootSectionGroup
50+
$rootSG.SectionGroups["system.webServer"].Sections.Add("ModSecurity")
51+
$rootSG.SectionGroups["system.webServer"].Sections["ModSecurity"].OverrideModeDefault = "Deny"
52+
$rootSG.SectionGroups["system.webServer"].Sections["ModSecurity"].AllowDefinition = "Everywhere"
53+
$sm.CommitChanges()
54+
& "$env:SystemRoot\System32\inetsrv\appcmd.exe" install module /name:"ModSecurity" /image:"$modsec_repo\iis\release\amd64\ModSecurityIIS.dll"
55+
& "$env:SystemRoot\System32\inetsrv\appcmd.exe" set config /section:"system.webServer/ModSecurity" /"enabled:true" /"configFile:$modsec_iis_conf"
56+
#setup the crs repo and the modsec config
57+
$crs_path = "$modsec_repo\crs"
58+
git clone -b "v3.1.0" -q https://github.com/SpiderLabs/owasp-modsecurity-crs.git $crs_path
59+
cd "$modsec_repo\tests"
60+
Rename-Item -Path "$crs_path\crs-setup.conf.example" -NewName "crs-setup.conf"
61+
Copy-Item "$crs_path\util\regression-tests\requirements.txt" -Destination "$modsec_repo\tests" -Force
62+
#setup the test env with depending python pkgs
63+
pip install ftw==1.1.7
64+
#configure modsec to use crs 3 and set if for the python testing
65+
$dbg_file = "$modsec_repo\modsec_debug.log"
66+
Add-Content $modsec_conf "SecDebugLog $dbg_file`r`nSecDebugLogLevel 3"
67+
Clear-Content $modsec_iis_conf
68+
#configure modsecurity_iis.conf for crs 3 and for runnig the python tests
69+
Add-Content $modsec_iis_conf "Include modsecurity.conf"
70+
Add-Content $modsec_iis_conf "SecAction ""id:900005,\`r`n phase:1,\`r`n nolog,\`r`n pass,\`r`n ctl:ruleEngine=DetectionOnly,\`r`n ctl:ruleRemoveById=910000,\"
71+
Add-Content $modsec_iis_conf " setvar:tx.paranoia_level=4,\`r`n setvar:tx.crs_validate_utf8_encoding=1,\`r`n setvar:tx.arg_name_length=100,\`r`n setvar:tx.arg_length=400"""
72+
Add-Content $modsec_iis_conf "include $crs_path\crs-setup.conf"
73+
Add-Content $modsec_iis_conf "include $crs_path/rules/*.conf"
74+
& {iisreset /start}; Start-Service W3SVC # finished all the modsec config, start iis
75+
- name: Run Test
76+
run: |
77+
$modsec_repo = "$pwd"
78+
$python_proj_name = "test_crs3"
79+
$crs_path = "$modsec_repo\crs"
80+
& "$modsec_repo\iis\$python_proj_name\Scripts\Activate.ps1"
81+
#usually the first test fail, due to i/o
82+
cd tests;
83+
py.test.exe -v CRS_Tests_modsec_dbg.py --rule="$crs_path\util\regression-tests\tests\test.yaml"
84+
#running all the tests
85+
py.test.exe -q CRS_Tests_modsec_dbg.py --ruledir_recurse="$crs_path\util\regression-tests\tests\" --result-log=res.txt --tb=no --junit-xml=res.xml
86+
python Parse_test_res.py res.txt

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

appveyor.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.

iis/build_dependencies.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@set CMAKE_DIR=%WORK_DIR%\%CMAKE:~0,-4%\bin
2424

2525
:: Aditional paths.
26-
@set PATH=%PATH%;%CMAKE_DIR%;"c:\program files\7-zip"
26+
@set PATH=%PATH%;%CMAKE_DIR%
2727

2828

2929
:: @set VCARGS32="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"

iis/build_release_amd64.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ mkdir "%RELEASE_DIR%"
1111

1212
mkdir "%AMD64%"
1313

14-
set VCARGS64="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat"
14+
set VCARGS64="C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsx86_amd64.bat"
15+
1516

1617
set SSDEEP_ARCH="x64"
1718
call build_dependencies.bat %VCARGS64%

0 commit comments

Comments
 (0)