Skip to content
Snippets Groups Projects
Commit ed3e2f33 authored by Aaron Weaver's avatar Aaron Weaver
Browse files

first commit

parents
No related branches found
No related tags found
No related merge requests found
The MIT License (MIT)
Copyright (c) 2016 Aaron Weaver, Template used by:
Copyright (c) 2015 Adam Parsons
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
include docs/*
include LICENSE.txt
\ No newline at end of file
DefectDojo API
=============
A Python API wrapper to facilitate interactions with `DefectDojo <https://github.com/OWASP/django-DefectDojo>`_.
This package implements API functionality available within Dojo.
Quick Start
-----------
Several quick start options are available:
- Install with pip (recommended): :code:`pip install defect_dojo_api`
- `Download the latest release <https://github.com/aaronweaver/dojo_api/releases/latest>`_
- Clone the repository: :code:`git clone https://github.com/aaronweaver/defect_dojo_api`
Example
-------
.. code-block:: python
# import the package
from defectdojo_api import defectdojo
# setup DefectDojo connection information
host = 'http://localhost:8000/'
api_key = 'your_api_key_from_DefectDojo'
user = 'admin'
# instantiate the DefectDojo api wrapper
dd = defectdojo.DefectDojoAPI(host, api_key, user, debug=False)
# If you need to disable certificate verification, set verify_ssl to False.
# dd = defectdojo.DefectDojoAPI(host, api_key, user, verify_ssl=False)
# You can also specify a local cert to use as client side certificate, as a
# single file (containing the private key and the certificate) or as a tuple
# of both file's path.
# cert=('/path/server.crt', '/path/key')
# dd = defectdojo.DefectDojoAPI(host, api_key, user, cert=cert)
#List Products
products = dd.get_products()
print(products.data_json(pretty=True)) # Decoded JSON object
for product in products.data["objects"]:
print(product['name']) # Print the name of each product
Supporting information for each method available can be found in the `documentation <https://github.com/aaronweaver/DefectDojo_api/tree/master/docs>`_.
Bugs and Feature Requests
-------------------------
Have a bug or a feature request? Please first search for existing and closed issues. If your problem or idea is not addressed yet, `please open a new issue <https://github.com/aaronweaver/Defect_Dojo_api/issues/new>`_.
Copyright and License
---------------------
- `Licensed under MIT <https://github.com/aaronweaver/Defect_Dojo_api/blob/master/LICENSE.txt>`_.
__version__ = '0.0.4'
This diff is collapsed.
setup.py 0 → 100644
#!/usr/bin/env python
import os
import sys
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from defect_dojo_api import __version__ as version
with open('README.rst', 'r') as f:
readme = f.read()
# Publish helper
if sys.argv[-1] == 'build':
os.system('python setup.py sdist bdist_wheel')
sys.exit(0)
if sys.argv[-1] == 'publish':
os.system('python setup.py sdist bdist_wheel upload -r pypi')
sys.exit(0)
if sys.argv[-1] == 'publish-test':
os.system('python setup.py sdist bdist_wheel upload -r pypitest')
sys.exit(0)
setup(
name='defectdojo_api',
packages=['defectdojo_api'],
version=version,
description='An API wrapper to facilitate interactions with Defect Dojo.',
long_description=readme,
author='Aaron Weaver',
author_email='aaron.weaver2@gmail.com',
url='https://github.com/aaronweaver/defect_dojo_api',
download_url='https://github.com/aaronweaver/defect_dojo_api/tarball/' + version,
license='MIT',
install_requires=['requests'],
keywords=['dojo', 'api', 'security', 'software'],
classifiers=[
'Development Status :: 1 - Beta',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries :: Python Modules',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
]
)
from defectdojo_api import defectdojo
import unittest
import os
class TestDefectDojoAPI(unittest.TestCase):
def setUp(self):
host = 'http://localhost:8000'
api_key = 'd76b707b48dbdca6222db7cd71c839ead6b1768e'
user = 'admin'
self.dd = defectdojo.DefectDojoAPI(host, api_key, user, debug=False)
#### USER API TESTS ####
def test_01_get_user(self):
user = self.dd.get_user(1)
self.assertIsNotNone(user.data['username'])
def test_02_get_users(self):
users = self.dd.get_users()
#print users.data_json(pretty=True)
#Test that the total count is not zero
self.assertTrue(users.data["meta"]["total_count"]>0)
#### Product API TESTS ####
def test_03_create_product(self):
product = self.dd.create_product("API Product Test", "Description", 1)
self.assertIsNotNone(product.id())
def test_04_get_product(self):
product = self.dd.get_product(1)
#print product.data_json(pretty=True)
self.assertIsNotNone(product.data['name'])
def test_05_set_product(self):
self.dd.set_product(1, name="Product Update Test")
product = self.dd.get_product(1)
#print product.data_json(pretty=True)
self.assertEqual("Product Update Test", product.data['name'])
def test_06_get_products(self):
products = self.dd.get_products()
#print products.data_json(pretty=True)
#Test that the total count is not zero
self.assertTrue(products.data["meta"]["total_count"]>0)
#### Engagement API TESTS ####
def test_07_create_engagement(self):
product_id = 1
user_id = 1
engagement = self.dd.create_engagement("API Engagement", product_id, user_id, "In Progress", "2016-11-01", "2016-12-01")
self.assertIsNotNone(engagement.id())
def test_08_get_engagement(self):
engagement = self.dd.get_engagement(1)
#print engagement.data_json(pretty=True)
self.assertIsNotNone(str(engagement.data["name"]))
def test_09_get_engagements(self):
engagements = self.dd.get_engagements()
#print engagements.data_json(pretty=True)
self.assertTrue(engagements.data["meta"]["total_count"]>0)
def test_10_set_engagement(self):
self.dd.set_engagement(1, name="Engagement Update Test")
engagement = self.dd.get_engagement(1)
#print engagement.data_json(pretty=True)
self.assertEqual("Engagement Update Test", engagement.data['name'])
#### Test API TESTS ####
def test_11_create_test(self):
engagement_id = 1
test_type = 1 #1 is the API Test
environment = 1 #1 is the Development Environment
test = self.dd.create_test(engagement_id, test_type, environment, "2016-11-01", "2016-12-01")
self.assertIsNotNone(test.id())
def test_12_get_test(self):
test = self.dd.get_test(1)
#print test.data_json(pretty=True)
self.assertIsNotNone(str(test.data["engagement"]))
def test_13_get_tests(self):
tests = self.dd.get_tests()
#print tests.data_json(pretty=True)
self.assertTrue(tests.data["meta"]["total_count"]>0)
def test_14_set_test(self):
self.dd.set_test(1, percent_complete="99")
test = self.dd.get_test(1)
#print test.data_json(pretty=True)
self.assertEqual(99, test.data['percent_complete'])
#### Findings API TESTS ####
def test_15_create_finding(self):
cwe = 25
product_id = 1
engagement_id = 1
test_id = 1
user_id = 1
finding = self.dd.create_finding("API Created", "Description", "Critical", cwe, "2016-11-01", product_id, engagement_id, test_id, user_id, "None", "true", "false", "References")
self.assertIsNotNone(finding.id())
def test_16_get_finding(self):
finding = self.dd.get_finding(1)
#print finding.data_json(pretty=True)
self.assertIsNotNone(str(finding.data["title"]))
def test_17_get_findings(self):
findings = self.dd.get_findings()
#print findings.data_json(pretty=True)
self.assertTrue(findings.data["meta"]["total_count"]>0)
def test_18_set_finding(self):
self.dd.set_finding(1, 1, 1, 1, title="API Finding Updates")
finding = self.dd.get_finding(1)
#print test.data_json(pretty=True)
self.assertEqual("API Finding Updates", finding.data['title'])
#### Upload API TESTS ####
def test_19_upload_scan(self):
dir_path = os.path.dirname(os.path.realpath(__file__))
engagement_id = 1
upload_scan = self.dd.upload_scan(engagement_id, "Burp Scan", dir_path + "/scans/Bodgeit-burp.xml",
"true", "01/11/2016", "Burp Upload")
#print upload_scan.data_json(pretty=True)
self.assertEqual("Bodgeit-burp.xml", upload_scan.data['file'])
if __name__ == '__main__':
unittest.main()
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment