-
Notifications
You must be signed in to change notification settings - Fork 29
/
owaspZAP-pipeline.yml
128 lines (116 loc) · 3.73 KB
/
owaspZAP-pipeline.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
trigger: none
pr: none
pool:
vmImage: "ubuntu-latest"
# variables:
# pathToDockerFile: 'Dockerfile'
# ACRConnectionName: 'AzureContainerRegistry-DevSecOps'
# ACRLoginServer: 'adinermieacr.azurecr.io'
# ACRRepository: 'eshoponweb'
stages:
- stage: QualityCheck
displayName: Quality Checks
jobs:
- job: OWASPJob
displayName: "OWASP ZAP Job"
steps:
- script: |
docker image pull node:19
displayName: Pull Node Docker Image
# - task: Docker@2
# displayName: Build Docker Container Image
# inputs:
# containerRegistry: $(ACRConnectionName)
# repository: $(ACRRepository)
# command: build
# Dockerfile: $(pathToDockerFile)
# tags: |
# $(Build.BuildId)
# - bash: |
# docker run -d -p 5000:8080 $(ACRLoginServer)/$(ACRRepository):$(Build.BuildId)
# displayName: Run Docker Container
- bash: |
docker run -d -p 8080:80 docker.io/library/node:19
displayName: Run Docker Container
- task: owaspzap@1
displayName: Running OWASP ZAP Scanner
inputs:
aggressivemode: false
scantype: 'agentScan'
threshold: 80
provideCustomContext: false
port: 5000
- bash: |
sudo npm install -g handlebars-cmd
cat <<EOF > owaspzap/nunit-template.hbs
{{#each site}}
<test-run
id="2"
name="Owasp test"
start-time="{{../[@generated]}}" >
<test-suite
id="{{@index}}"
type="Assembly"
name="{{[@name]}}"
result="Failed"
failed="{{alerts.length}}">
<attachments>
<attachment>
<filePath>$(Build.ArtifactStagingDirectory)/report.html</filePath>
</attachment>
<attachment>
<filePath>$(Build.ArtifactStagingDirectory)/report.json</filePath>
</attachment>
</attachments>
{{#each alerts}}<test-case
id="{{@index}}"
name="{{alert}}"
result="Failed"
fullname="{{alert}}"
time="1">
<failure>
<message>
<![CDATA[{{{desc}}}]]>
</message>
<stack-trace>
<![CDATA[
Solution:
{{{solution}}}
Reference:
{{{reference}}}
instances:{{#each instances}}
* {{uri}}
- {{method}}
{{#if evidence}}- {{{evidence}}}{{/if}}
{{/each}}]]>
</stack-trace>
</failure>
</test-case>
{{/each}}
</test-suite>
</test-run>
{{/each}}
EOF
displayName: OWASP NUnit Report Template
condition: succeededOrFailed()
- bash: |
handlebars owaspzap/report.json < owaspzap/nunit-template.hbs > owaspzap/test-results.xml
displayName: Generate NUnit Type File
condition: succeededOrFailed()
- task: PublishTestResults@2
displayName: 'Publish OWASP ZAP Test Results'
inputs:
testResultsFormat: NUnit
testResultsFiles: 'owaspzap/test-results.xml'
condition: succeededOrFailed()
- task: CopyFiles@2
displayName: Copy OWASP Files
condition: succeededOrFailed()
inputs:
SourceFolder: 'owaspzap/'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: Publish Build Artifact
condition: succeededOrFailed()
inputs:
ArtifactName: OWASP-ZAP-Reports