Skip to content

Commit

Permalink
Merge pull request #48 from thc202/update-apis
Browse files Browse the repository at this point in the history
Update APIs of add-ons and core
  • Loading branch information
psiinon committed Jul 17, 2023
2 parents 766512d + 1d22820 commit 047ee49
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 8 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [Unreleased]
## [2.0.0-rc.2] - 2023-07-17
### Changed
* Update the link to API docs in README.md
* Update core APIs for 2.13.
* Update the APIs of the following add-ons:
* AJAX Spider version 23.15.0;
* Alert Filters version 17;
* GraphQL Support version 0.18.0;
* Network version 0.10.0;
* Selenium version 15.13.0.

### Fixed
* Return errors (e.g. connection, ZAP API) with a rejected promise.
Expand Down Expand Up @@ -74,7 +81,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
## 0.3.0 - 2017-12-04


[Unreleased]: https://github.com/zaproxy/zap-api-nodejs/compare/v2.0.0-rc.1...HEAD
[2.0.0-rc.2]: https://github.com/zaproxy/zap-api-nodejs/compare/v2.0.0-rc.1...v2.0.0-rc.2
[2.0.0-rc.1]: https://github.com/zaproxy/zap-api-nodejs/compare/v1.0.1...v2.0.0-rc.1
[1.0.1]: https://github.com/zaproxy/zap-api-nodejs/compare/v1.0.0-rc.1...v1.0.1
[1.0.0-rc.1]: https://github.com/zaproxy/zap-api-nodejs/compare/ccad7bac914e3572dba4e9d09fc2114bb5208d8d...v1.0.0-rc.1
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zaproxy",
"description": "ZAP API Client for Node.js",
"version": "2.0.0-rc.1",
"version": "2.0.0-rc.2",
"homepage": "https://github.com/zaproxy/zap-api-nodejs",
"author": {
"name": "Najam Ul Saqib",
Expand Down
87 changes: 87 additions & 0 deletions src/ajaxSpider.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ AjaxSpider.prototype.allowedResources = function () {
return this.api.request('/ajaxSpider/view/allowedResources/')
}

/**
* Gets the excluded elements. The excluded elements are not clicked during crawling, for example, to prevent logging out.
* This component is optional and therefore the API will only work if it is installed
* @param {string} contextname - The name of the context.
**/
AjaxSpider.prototype.excludedElements = function (args) {
return this.api.request('/ajaxSpider/view/excludedElements/', { contextName: args.contextname })
}

/**
* Gets the current status of the crawler. Actual values are Stopped and Running.
* This component is optional and therefore the API will only work if it is installed
Expand Down Expand Up @@ -221,6 +230,84 @@ AjaxSpider.prototype.addAllowedResource = function (args) {
return this.api.request('/ajaxSpider/action/addAllowedResource/', params)
}

/**
* Adds an excluded element to a context.
* This component is optional and therefore the API will only work if it is installed
* @param {string} contextname - The name of the context.
* @param {string} description - The description of the excluded element.
* @param {string} element - The element to exclude.
* @param {string} xpath - The XPath of the element.
* @param {string} text - The text of the element.
* @param {string} attributename - The attribute name of the element.
* @param {string} attributevalue - The attribute value of the element.
* @param {string} enabled - The enabled state, true or false.
**/
AjaxSpider.prototype.addExcludedElement = function (args) {
const params = { contextName: args.contextname, description: args.description, element: args.element }
if (args.xpath && args.xpath !== null) {
params.xpath = args.xpath
}
if (args.text && args.text !== null) {
params.text = args.text
}
if (args.attributename && args.attributename !== null) {
params.attributeName = args.attributename
}
if (args.attributevalue && args.attributevalue !== null) {
params.attributeValue = args.attributevalue
}
if (args.enabled && args.enabled !== null) {
params.enabled = args.enabled
}
return this.api.request('/ajaxSpider/action/addExcludedElement/', params)
}

/**
* Modifies an excluded element of a context.
* This component is optional and therefore the API will only work if it is installed
* @param {string} contextname - The name of the context.
* @param {string} description - The description of the excluded element.
* @param {string} element - The element to exclude.
* @param {string} descriptionnew - The new description.
* @param {string} xpath - The XPath of the element.
* @param {string} text - The text of the element.
* @param {string} attributename - The attribute name of the element.
* @param {string} attributevalue - The attribute value of the element.
* @param {string} enabled - The enabled state, true or false.
**/
AjaxSpider.prototype.modifyExcludedElement = function (args) {
const params = { contextName: args.contextname, description: args.description, element: args.element }
if (args.descriptionnew && args.descriptionnew !== null) {
params.descriptionNew = args.descriptionnew
}
if (args.xpath && args.xpath !== null) {
params.xpath = args.xpath
}
if (args.text && args.text !== null) {
params.text = args.text
}
if (args.attributename && args.attributename !== null) {
params.attributeName = args.attributename
}
if (args.attributevalue && args.attributevalue !== null) {
params.attributeValue = args.attributevalue
}
if (args.enabled && args.enabled !== null) {
params.enabled = args.enabled
}
return this.api.request('/ajaxSpider/action/modifyExcludedElement/', params)
}

/**
* Removes an excluded element from a context.
* This component is optional and therefore the API will only work if it is installed
* @param {string} contextname - The name of the context.
* @param {string} description - The description of the excluded element.
**/
AjaxSpider.prototype.removeExcludedElement = function (args) {
return this.api.request('/ajaxSpider/action/removeExcludedElement/', { contextName: args.contextname, description: args.description })
}

/**
* Removes an allowed resource.
* This component is optional and therefore the API will only work if it is installed
Expand Down
16 changes: 16 additions & 0 deletions src/alertFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ AlertFilter.prototype.globalAlertFilterList = function () {
* @param {string} attackisregex
* @param {string} evidence
* @param {string} evidenceisregex
* @param {string} methods
**/
AlertFilter.prototype.addAlertFilter = function (args) {
const params = { contextId: args.contextid, ruleId: args.ruleid, newLevel: args.newlevel }
Expand Down Expand Up @@ -88,6 +89,9 @@ AlertFilter.prototype.addAlertFilter = function (args) {
if (args.evidenceisregex && args.evidenceisregex !== null) {
params.evidenceIsRegex = args.evidenceisregex
}
if (args.methods && args.methods !== null) {
params.methods = args.methods
}
return this.api.request('/alertFilter/action/addAlertFilter/', params)
}

Expand All @@ -106,6 +110,7 @@ AlertFilter.prototype.addAlertFilter = function (args) {
* @param {string} attackisregex
* @param {string} evidence
* @param {string} evidenceisregex
* @param {string} methods
**/
AlertFilter.prototype.removeAlertFilter = function (args) {
const params = { contextId: args.contextid, ruleId: args.ruleid, newLevel: args.newlevel }
Expand Down Expand Up @@ -136,6 +141,9 @@ AlertFilter.prototype.removeAlertFilter = function (args) {
if (args.evidenceisregex && args.evidenceisregex !== null) {
params.evidenceIsRegex = args.evidenceisregex
}
if (args.methods && args.methods !== null) {
params.methods = args.methods
}
return this.api.request('/alertFilter/action/removeAlertFilter/', params)
}

Expand All @@ -153,6 +161,7 @@ AlertFilter.prototype.removeAlertFilter = function (args) {
* @param {string} attackisregex
* @param {string} evidence
* @param {string} evidenceisregex
* @param {string} methods
**/
AlertFilter.prototype.addGlobalAlertFilter = function (args) {
const params = { ruleId: args.ruleid, newLevel: args.newlevel }
Expand Down Expand Up @@ -183,6 +192,9 @@ AlertFilter.prototype.addGlobalAlertFilter = function (args) {
if (args.evidenceisregex && args.evidenceisregex !== null) {
params.evidenceIsRegex = args.evidenceisregex
}
if (args.methods && args.methods !== null) {
params.methods = args.methods
}
return this.api.request('/alertFilter/action/addGlobalAlertFilter/', params)
}

Expand All @@ -200,6 +212,7 @@ AlertFilter.prototype.addGlobalAlertFilter = function (args) {
* @param {string} attackisregex
* @param {string} evidence
* @param {string} evidenceisregex
* @param {string} methods
**/
AlertFilter.prototype.removeGlobalAlertFilter = function (args) {
const params = { ruleId: args.ruleid, newLevel: args.newlevel }
Expand Down Expand Up @@ -230,6 +243,9 @@ AlertFilter.prototype.removeGlobalAlertFilter = function (args) {
if (args.evidenceisregex && args.evidenceisregex !== null) {
params.evidenceIsRegex = args.evidenceisregex
}
if (args.methods && args.methods !== null) {
params.methods = args.methods
}
return this.api.request('/alertFilter/action/removeGlobalAlertFilter/', params)
}

Expand Down
15 changes: 15 additions & 0 deletions src/ascan.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ Ascan.prototype.optionHostPerScan = function () {
return this.api.request('/ascan/view/optionHostPerScan/')
}

/**
* Gets the maximum number of alerts that a rule can raise before being skipped.
**/
Ascan.prototype.optionMaxAlertsPerRule = function () {
return this.api.request('/ascan/view/optionMaxAlertsPerRule/')
}

/**
*
**/
Expand Down Expand Up @@ -736,6 +743,14 @@ Ascan.prototype.setOptionInjectPluginIdInHeader = function (args) {
return this.api.request('/ascan/action/setOptionInjectPluginIdInHeader/', { Boolean: args.bool })
}

/**
* Sets the maximum number of alerts that a rule can raise before being skipped.
* @param {string} integer - The maximum alerts.
**/
Ascan.prototype.setOptionMaxAlertsPerRule = function (args) {
return this.api.request('/ascan/action/setOptionMaxAlertsPerRule/', { Integer: args.integer })
}

/**
*
* @param {string} integer
Expand Down
17 changes: 17 additions & 0 deletions src/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ Graphql.prototype.optionOptionalArgsEnabled = function () {
return this.api.request('/graphql/view/optionOptionalArgsEnabled/')
}

/**
* Returns whether the query generator is enabled.
* This component is optional and therefore the API will only work if it is installed
**/
Graphql.prototype.optionQueryGenEnabled = function () {
return this.api.request('/graphql/view/optionQueryGenEnabled/')
}

/**
* Returns the current level for which a single query is generated.
* This component is optional and therefore the API will only work if it is installed
Expand Down Expand Up @@ -186,4 +194,13 @@ Graphql.prototype.setOptionOptionalArgsEnabled = function (args) {
return this.api.request('/graphql/action/setOptionOptionalArgsEnabled/', { Boolean: args.bool })
}

/**
* Sets whether the query generator is enabled.
* This component is optional and therefore the API will only work if it is installed
* @param {string} bool - Enable query generation (true or false).
**/
Graphql.prototype.setOptionQueryGenEnabled = function (args) {
return this.api.request('/graphql/action/setOptionQueryGenEnabled/', { Boolean: args.bool })
}

module.exports = Graphql
41 changes: 41 additions & 0 deletions src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ Network.prototype.isUseGlobalHttpState = function () {
return this.api.request('/network/view/isUseGlobalHttpState/')
}

/**
* List of rate limit rules.
* This component is optional and therefore the API will only work if it is installed
**/
Network.prototype.getRateLimitRules = function () {
return this.api.request('/network/view/getRateLimitRules/')
}

/**
* Generates a new Root CA certificate, used to issue server certificates.
* This component is optional and therefore the API will only work if it is installed
Expand Down Expand Up @@ -458,6 +466,39 @@ Network.prototype.setUseClientCertificate = function (args) {
return this.api.request('/network/action/setUseClientCertificate/', { use: args.use })
}

/**
* Adds a rate limit rule
* This component is optional and therefore the API will only work if it is installed
* @param {string} description - A description that allows you to identify the rule. Each rule must have a unique description.
* @param {string} enabled - The enabled state, true or false.
* @param {string} matchregex - Regex used to match the host.
* @param {string} matchstring - Plain string match is handled based on DNS conventions. If the string has one or two components.
* @param {string} requestspersecond - The maximum number of requests per second.
* @param {string} groupby - How to group hosts when applying rate limiting: rule or host
**/
Network.prototype.addRateLimitRule = function (args) {
return this.api.request('/network/action/addRateLimitRule/', { description: args.description, enabled: args.enabled, matchRegex: args.matchregex, matchString: args.matchstring, requestsPerSecond: args.requestspersecond, groupBy: args.groupby })
}

/**
* Remove a rate limit rule
* This component is optional and therefore the API will only work if it is installed
* @param {string} description - The description of the rule to remove.
**/
Network.prototype.removeRateLimitRule = function (args) {
return this.api.request('/network/action/removeRateLimitRule/', { description: args.description })
}

/**
* Set enabled state for a rate limit rule.
* This component is optional and therefore the API will only work if it is installed
* @param {string} description - The description of the rule to modify.
* @param {string} enabled - The enabled state, true or false.
**/
Network.prototype.setRateLimitRuleEnabled = function (args) {
return this.api.request('/network/action/setRateLimitRuleEnabled/', { description: args.description, enabled: args.enabled })
}

/**
* Provides a PAC file, proxying through the main proxy.
* This component is optional and therefore the API will only work if it is installed
Expand Down
3 changes: 0 additions & 3 deletions src/selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Selenium.prototype.optionLastDirectory = function () {
}

/**
* Returns the current path to PhantomJS binary
* This component is optional and therefore the API will only work if it is installed
**/
Selenium.prototype.optionPhantomJsBinaryPath = function () {
Expand Down Expand Up @@ -138,9 +137,7 @@ Selenium.prototype.setOptionLastDirectory = function (args) {
}

/**
* Sets the current path to PhantomJS binary
* This component is optional and therefore the API will only work if it is installed
* @param {string} string
**/
Selenium.prototype.setOptionPhantomJsBinaryPath = function (args) {
return this.api.request('/selenium/action/setOptionPhantomJsBinaryPath/', { String: args.string })
Expand Down

0 comments on commit 047ee49

Please sign in to comment.