Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
defectdojo_api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Raul Barreras
defectdojo_api
Commits
3b666e18
Commit
3b666e18
authored
8 years ago
by
Aaron Weaver
Browse files
Options
Downloads
Patches
Plain Diff
Data loader example
parent
f927cf6a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
defectdojo_api/defectdojo.py
+2
-2
2 additions, 2 deletions
defectdojo_api/defectdojo.py
examples/dojo_populate.py
+95
-0
95 additions, 0 deletions
examples/dojo_populate.py
tests/defectdojo_api_unit_test.py
+6
-1
6 additions, 1 deletion
tests/defectdojo_api_unit_test.py
with
103 additions
and
3 deletions
defectdojo_api/defectdojo.py
+
2
−
2
View file @
3b666e18
...
@@ -670,7 +670,7 @@ class DefectDojoAPI(object):
...
@@ -670,7 +670,7 @@ class DefectDojoAPI(object):
print
(
response
.
text
)
print
(
response
.
text
)
try
:
try
:
if
response
.
status_code
==
201
:
#Created new o
j
bect
if
response
.
status_code
==
201
:
#Created new ob
j
ect
object_id
=
response
.
headers
[
"
Location
"
].
split
(
'
/
'
)
object_id
=
response
.
headers
[
"
Location
"
].
split
(
'
/
'
)
key_id
=
object_id
[
-
2
]
key_id
=
object_id
[
-
2
]
try
:
try
:
...
@@ -681,7 +681,7 @@ class DefectDojoAPI(object):
...
@@ -681,7 +681,7 @@ class DefectDojoAPI(object):
return
DefectDojoResponse
(
message
=
"
Upload complete
"
,
data
=
data
,
success
=
True
)
return
DefectDojoResponse
(
message
=
"
Upload complete
"
,
data
=
data
,
success
=
True
)
elif
response
.
status_code
==
204
:
#Object updates
elif
response
.
status_code
==
204
:
#Object updates
return
DefectDojoResponse
(
message
=
"
Object updated.
"
,
success
=
True
)
return
DefectDojoResponse
(
message
=
"
Object updated.
"
,
success
=
True
)
elif
response
.
status_code
==
404
:
#
Created new ojbect
elif
response
.
status_code
==
404
:
#
Object not created
return
DefectDojoResponse
(
message
=
"
Object id does not exist.
"
,
success
=
False
)
return
DefectDojoResponse
(
message
=
"
Object id does not exist.
"
,
success
=
False
)
else
:
else
:
data
=
response
.
json
()
data
=
response
.
json
()
...
...
This diff is collapsed.
Click to expand it.
examples/dojo_populate.py
0 → 100644
+
95
−
0
View file @
3b666e18
from
defectdojo_api
import
defectdojo
from
random
import
randint
import
os
from
datetime
import
datetime
,
timedelta
"""
Imports test data into Defect DefectDojo
"""
# Setup DefectDojo connection information
host
=
'
http://localhost:8000
'
api_key
=
os
.
environ
[
'
DOJO_API_KEY
'
]
user
=
'
admin
'
"""
#Optionally, specify a proxy
proxies = {
'
http
'
:
'
http://localhost:8080
'
,
'
https
'
:
'
http://localhost:8080
'
,
}
#proxies=proxies
"""
# Instantiate the DefectDojo api wrapper
dd
=
defectdojo
.
DefectDojoAPI
(
host
,
api_key
,
user
,
debug
=
False
)
user_id
=
1
#Default user
def
create_finding_data
(
product_id
,
engagement_id
,
test_id
):
cwe
=
[
352
,
22
,
676
,
863
,
134
,
759
,
798
]
cwe_desc
=
[
'
Cross-Site Request Forgery (CSRF)
'
,
'
Improper Limitation of a Pathname to a Restricted Directory (
\'
Path Traversal
\'
)
'
,
'
Use of Potentially Dangerous Function
'
,
'
Incorrect Authorization
'
,
'
Uncontrolled Format String
'
,
'
Use of a One-Way Hash without a Salt
'
,
'
Use of Hard-coded Credentials
'
]
severity
=
[
'
Low
'
,
'
Medium
'
,
'
High
'
,
'
Critical
'
]
user_id
=
1
finding_date
=
datetime
.
now
()
finding_date
=
finding_date
+
timedelta
(
days
=
randint
(
-
30
,
0
))
finding_cwe
=
randint
(
0
,
6
)
finding
=
dd
.
create_finding
(
cwe_desc
[
finding_cwe
],
cwe_desc
[
finding_cwe
],
severity
[
randint
(
0
,
3
)],
cwe
[
finding_cwe
],
finding_date
.
strftime
(
"
%Y-%m-%d
"
),
product_id
,
engagement_id
,
test_id
,
user_id
,
"
None
"
,
"
true
"
,
"
true
"
,
"
References
"
)
def
create_load_data
(
product_name
,
product_desc
,
file
=
None
,
file_test_type
=
None
):
# Create a product
prod_type
=
1
#1 - Research and Development, product type
print
"
Creating product:
"
+
product_name
product
=
dd
.
create_product
(
product_name
,
product_desc
,
prod_type
)
if
product
.
success
:
# Get the product id
product_id
=
product
.
id
()
# Create an engagement
start_date
=
datetime
.
now
()
end_date
=
start_date
+
timedelta
(
days
=
randint
(
2
,
8
))
print
"
Creating engagement:
"
+
"
Intial
"
+
product_name
+
"
Engagement
"
engagement
=
dd
.
create_engagement
(
"
Intial
"
+
product_name
+
"
Engagement
"
,
product_id
,
user_id
,
"
In Progress
"
,
start_date
.
strftime
(
"
%Y-%m-%d
"
),
end_date
.
strftime
(
"
%Y-%m-%d
"
))
engagement_id
=
engagement
.
id
()
# Create some tests
print
"
Creating tests
"
#Load scanner test data
if
file
is
not
None
:
print
"
Loading scanner results from scanner export
"
dir_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
upload_scan
=
dd
.
upload_scan
(
engagement_id
,
"
Burp Scan
"
,
dir_path
+
file
,
"
true
"
,
"
01/11/2016
"
,
"
API
"
)
i
=
0
while
i
<
6
:
test_type
=
i
+
1
#Select some random tests
environment
=
randint
(
1
,
6
)
#Select random environments
test
=
dd
.
create_test
(
engagement_id
,
test_type
,
environment
,
start_date
.
strftime
(
"
%Y-%m-%d
"
),
start_date
.
strftime
(
"
%Y-%m-%d
"
))
test_id
=
test
.
id
()
f
=
0
f_max
=
randint
(
4
,
10
)
while
f
<
f_max
:
# Load findings
create_finding_data
(
product_id
,
engagement_id
,
test_id
)
f
=
f
+
1
i
=
i
+
1
else
:
print
product
.
message
##### Create Products, Engagements and Tests ########
create_load_data
(
"
BodgeIt
"
,
"
Product description.
"
,
"
../tests/scans/Bodgeit-burp.xml
"
,
"
Burp Scan
"
)
create_load_data
(
"
A CRM App
"
,
"
Product description.
"
)
create_load_data
(
"
An Engineering Application
"
,
"
Product description.
"
)
create_load_data
(
"
A Marketing Site
"
,
"
Product description.
"
)
This diff is collapsed.
Click to expand it.
tests/defectdojo_api_unit_test.py
+
6
−
1
View file @
3b666e18
...
@@ -10,7 +10,12 @@ class TestDefectDojoAPI(unittest.TestCase):
...
@@ -10,7 +10,12 @@ class TestDefectDojoAPI(unittest.TestCase):
api_key
=
os
.
environ
[
'
DOJO_API_KEY
'
]
api_key
=
os
.
environ
[
'
DOJO_API_KEY
'
]
user
=
'
admin
'
user
=
'
admin
'
self
.
dd
=
defectdojo
.
DefectDojoAPI
(
host
,
api_key
,
user
,
debug
=
False
)
proxies
=
{
'
http
'
:
'
http://localhost:8080
'
,
'
https
'
:
'
http://localhost:8080
'
,
}
self
.
dd
=
defectdojo
.
DefectDojoAPI
(
host
,
api_key
,
user
,
proxies
=
proxies
,
debug
=
False
)
#### USER API TESTS ####
#### USER API TESTS ####
def
test_01_get_user
(
self
):
def
test_01_get_user
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment