@lifeomic/veracode-client-js
Advanced tools
Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "@lifeomic/veracode-client-js", | ||
"description": "JavaScript Veracode API client", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"main": "src/VeracodeClient.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -29,2 +29,3 @@ // Native libs | ||
this.apiBase4 = 'https://analysiscenter.veracode.com/api/4.0/'; // some functionality is only available in v4 | ||
this.apiBaseRest = 'https://api.veracode.com/appsec/v1/'; | ||
} | ||
@@ -67,5 +68,5 @@ | ||
/* Veracode API Wrapper */ | ||
/* Veracode XML API Wrapper */ | ||
async _request (options) { | ||
async _xmlRequest (options) { | ||
const uri = new URL(options.endPoint, options.apiBase || this.apiBase); | ||
@@ -94,7 +95,41 @@ const method = (options.form || options.formData) ? 'POST' : 'GET'; | ||
/* Veracode REST API Wrapper */ | ||
async _restRequest (options) { | ||
const uri = new URL(options.endPoint, options.apiBase || this.apiBaseRest); | ||
const method = 'GET'; | ||
const response = await request({ | ||
method, | ||
uri, | ||
headers: { | ||
'Authorization': this.calculateAuthorizationHeader(uri, method) | ||
} | ||
}); | ||
const responseParsed = JSON.parse(response); | ||
return this.getEmbedded(responseParsed); | ||
} | ||
/* Veracode API functions */ | ||
async getApplications () { | ||
const response = await this._restRequest({ | ||
endPoint: 'applications' | ||
}); | ||
return response.applications; | ||
}; | ||
async getFindings (applicationGuid) { | ||
const response = await this._restRequest({ | ||
endPoint: `applications/${applicationGuid}/findings` | ||
}); | ||
return response.findings; | ||
}; | ||
// "The getapplist.do call compiles a list of the applications in the portfolio." | ||
async getAppList () { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'getapplist.do' | ||
@@ -108,3 +143,3 @@ }); | ||
async getSandboxList (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'getsandboxlist.do', | ||
@@ -121,3 +156,3 @@ form: { | ||
async createSandbox (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'createsandbox.do', | ||
@@ -135,3 +170,3 @@ form: { | ||
async getBuildList (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'getbuildlist.do', | ||
@@ -150,3 +185,3 @@ form: { | ||
async getAppBuilds (options = {}) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'getappbuilds.do', | ||
@@ -166,3 +201,3 @@ apiBase: this.apiBase4, // note the use of API v4, this call is not available in v5 | ||
async detailedReport (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'detailedreport.do', | ||
@@ -194,3 +229,3 @@ form: { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'uploadfile.do', | ||
@@ -205,3 +240,3 @@ formData | ||
async beginPrescan (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'beginprescan.do', | ||
@@ -221,3 +256,3 @@ form: { | ||
async createApp (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'createapp.do', | ||
@@ -249,3 +284,3 @@ form: { | ||
async createBuild (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'createbuild.do', | ||
@@ -267,3 +302,3 @@ form: { | ||
async getBuildInfo (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'getbuildinfo.do', | ||
@@ -282,3 +317,3 @@ form: { | ||
async deleteApp (options) { | ||
const response = await this._request({ | ||
const response = await this._xmlRequest({ | ||
endPoint: 'deleteapp.do', | ||
@@ -336,4 +371,12 @@ form: { | ||
} | ||
getEmbedded(response) { | ||
if (response._embedded) { | ||
return response._embedded; | ||
} else { | ||
return []; | ||
} | ||
} | ||
} | ||
module.exports = VeracodeClient; |
@@ -67,3 +67,3 @@ const VeracodeClient = require('./VeracodeClient'); | ||
describe("#_request", () => { | ||
describe('#_xmlRequest', () => { | ||
test('parses xml', async () => { | ||
@@ -75,3 +75,3 @@ request.mockResolvedValue(` | ||
`); | ||
const response = await veracodeClient._request({ endPoint: "mytest.do" }); | ||
const response = await veracodeClient._xmlRequest({ endPoint: "mytest.do" }); | ||
const expectedUrl = new URL('mytest.do', veracodeClient.apiBase); | ||
@@ -96,6 +96,36 @@ expect(request).toBeCalledWith(baseRequestArg(expectedUrl, 'GET')); | ||
request.mockResolvedValue('<error>Baby did a boom boom</error>'); | ||
expect(veracodeClient._request({ endPoint: "mytest.do" })).rejects.toThrow("Baby did a boom boom"); | ||
expect(veracodeClient._xmlRequest({ endPoint: "mytest.do" })).rejects.toThrow("Baby did a boom boom"); | ||
}); | ||
}); | ||
describe('#_restRequest', () => { | ||
test('returns _embedded', async () => { | ||
request.mockResolvedValue(` | ||
{ | ||
"_embedded": { | ||
"applications": [{ | ||
"guid": "some-long-guid", | ||
"id": 123456 | ||
}] | ||
} | ||
} | ||
`) | ||
const response = await veracodeClient._restRequest({ endPoint: 'applications' }); | ||
const expectedUrl = new URL('applications', veracodeClient.apiBaseRest); | ||
expect(request).toBeCalledWith({ | ||
method: 'GET', | ||
uri: expectedUrl, | ||
headers: { | ||
'Authorization': mockAuthHeader(expectedUrl, 'GET') | ||
} | ||
}); | ||
expect(response).toEqual({ | ||
applications: [{ | ||
guid: 'some-long-guid', | ||
id: 123456 | ||
}] | ||
}); | ||
}); | ||
}); | ||
describe('#uploadFile', async () => { | ||
@@ -102,0 +132,0 @@ test('uploads file with all options', async () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
184879
664