Skip to content

Commit

Permalink
Tidy up, regen APIs
Browse files Browse the repository at this point in the history
Add API of OpenAPI add-on.
  • Loading branch information
thc202 committed May 5, 2017
1 parent be825cb commit 7ed5ae4
Show file tree
Hide file tree
Showing 26 changed files with 319 additions and 280 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ The latest released version can be downloaded from the [https://pypi.python.org/

pip install python-owasp-zap-v2.4

## Running

`docker pull owasp/zap2docker-weekly`
`docker run -u zap -p 1112:1112 -d owasp/zap2docker-weekly zap.sh -daemon -port 1112 -host 0.0.0.0 -config api.disablekey=true`
`docker inspect {code}`

## Getting Help

For help using OWASP ZAP API refer to:
Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
try:
from setuptools import setup, find_packages
except ImportError:
print('You must have setuptools installed to use setup.py. Exiting...')
raise SystemExit(1)


install_dependencies = (
'requests',
'six',
'six'
)
test_requirements = (
'mock',
Expand Down Expand Up @@ -44,7 +45,11 @@
'Topic :: Software Development :: Libraries :: Python Modules',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Programming Language :: Python'
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
],
install_requires=install_dependencies,
tests_require=test_requirements,
Expand Down
4 changes: 2 additions & 2 deletions src/zapv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""

__docformat__ = 'restructuredtext'
__version__ = '0.0.9'
__version__ = '0.0.10'

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
Expand Down Expand Up @@ -115,7 +115,7 @@ def urlopen(self, url, *args, **kwargs):
- `kwargs`: all other keyword arguments.
"""
# Must never leak the API key via proxied requests
return requests.get(url, proxies=self.__proxies, *args, **kwargs).text
return requests.get(url, proxies=self.__proxies, verify=False, *args, **kwargs).text

def _request_api(self, url, query=None):
"""
Expand Down
7 changes: 4 additions & 3 deletions src/zapv2/acsrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import six


class acsrf(object):

def __init__(self, zap):
Expand All @@ -37,16 +38,16 @@ def add_option_token(self, string, apikey=''):
"""
Adds an anti-CSRF token with the given name, enabled by default
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/addOptionToken/', {'String' : string, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/addOptionToken/', {'String': string, 'apikey': apikey})))

def remove_option_token(self, string, apikey=''):
"""
Removes the anti-CSRF token with the given name
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/removeOptionToken/', {'String' : string, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/removeOptionToken/', {'String': string, 'apikey': apikey})))

def gen_form(self, hrefid, apikey=''):
"""
Generate a form for testing lack of anti-CSRF tokens - typically invoked via ZAP
"""
return (self.zap._request_other(self.zap.base_other + 'acsrf/other/genForm/', {'hrefId' : hrefid, 'apikey' : apikey}))
return (self.zap._request_other(self.zap.base_other + 'acsrf/other/genForm/', {'hrefId': hrefid, 'apikey': apikey}))
27 changes: 14 additions & 13 deletions src/zapv2/ajaxSpider.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import six


class ajaxSpider(object):

def __init__(self, zap):
Expand Down Expand Up @@ -132,7 +133,7 @@ def scan(self, url=None, inscope=None, contextname=None, subtreeonly=None, apike
"""
This component is optional and therefore the API will only work if it is installed
"""
params = {'apikey' : apikey}
params = {'apikey': apikey}
if url is not None:
params['url'] = url
if inscope is not None:
Expand All @@ -147,7 +148,7 @@ def scan_as_user(self, contextname, username, url=None, subtreeonly=None, apikey
"""
This component is optional and therefore the API will only work if it is installed
"""
params = {'contextName' : contextname, 'userName' : username, 'apikey' : apikey}
params = {'contextName': contextname, 'userName': username, 'apikey': apikey}
if url is not None:
params['url'] = url
if subtreeonly is not None:
Expand All @@ -158,64 +159,64 @@ def stop(self, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/stop/', {'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/stop/', {'apikey': apikey})))

def set_option_browser_id(self, string, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionBrowserId/', {'String' : string, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionBrowserId/', {'String': string, 'apikey': apikey})))

def set_option_click_default_elems(self, boolean, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionClickDefaultElems/', {'Boolean' : boolean, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionClickDefaultElems/', {'Boolean': boolean, 'apikey': apikey})))

def set_option_click_elems_once(self, boolean, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionClickElemsOnce/', {'Boolean' : boolean, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionClickElemsOnce/', {'Boolean': boolean, 'apikey': apikey})))

def set_option_event_wait(self, integer, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionEventWait/', {'Integer' : integer, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionEventWait/', {'Integer': integer, 'apikey': apikey})))

def set_option_max_crawl_depth(self, integer, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionMaxCrawlDepth/', {'Integer' : integer, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionMaxCrawlDepth/', {'Integer': integer, 'apikey': apikey})))

def set_option_max_crawl_states(self, integer, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionMaxCrawlStates/', {'Integer' : integer, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionMaxCrawlStates/', {'Integer': integer, 'apikey': apikey})))

def set_option_max_duration(self, integer, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionMaxDuration/', {'Integer' : integer, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionMaxDuration/', {'Integer': integer, 'apikey': apikey})))

def set_option_number_of_browsers(self, integer, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionNumberOfBrowsers/', {'Integer' : integer, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionNumberOfBrowsers/', {'Integer': integer, 'apikey': apikey})))

def set_option_random_inputs(self, boolean, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionRandomInputs/', {'Boolean' : boolean, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionRandomInputs/', {'Boolean': boolean, 'apikey': apikey})))

def set_option_reload_wait(self, integer, apikey=''):
"""
This component is optional and therefore the API will only work if it is installed
"""
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionReloadWait/', {'Integer' : integer, 'apikey' : apikey})))
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setOptionReloadWait/', {'Integer': integer, 'apikey': apikey})))
Loading

0 comments on commit 7ed5ae4

Please sign in to comment.