├── .gitignore ├── api ├── role.js ├── alerts.js ├── webhook.js ├── rules.js ├── modules.js ├── history.js ├── agent.js ├── events.js ├── profile.js ├── library.js ├── user.js ├── support.js ├── scores.js ├── trace.js ├── organization.js ├── tags.js ├── server.js └── application.js ├── test ├── roleTest.js ├── alertTest.js ├── webhookTest.js ├── config.json.example ├── setup.js ├── sdkTest.js ├── modulesTest.js ├── rulesTest.js ├── historyTest.js ├── agentTest.js ├── eventsTest.js ├── userTest.js ├── libraryTest.js ├── profileTest.js ├── organizationTest.js ├── scoreTest.js ├── traceTest.js ├── tagsTest.js ├── serverTest.js └── applicationTest.js ├── package.json ├── .github └── dependabot.yml ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /test/config.json 3 | contrast.jar 4 | npm-debug.log 5 | 6 | .idea -------------------------------------------------------------------------------- /api/role.js: -------------------------------------------------------------------------------- 1 | function getRoles(){ 2 | return this._get('roles'); 3 | } 4 | 5 | module.exports.getRoles = getRoles; 6 | -------------------------------------------------------------------------------- /api/alerts.js: -------------------------------------------------------------------------------- 1 | function getAlerts(orgUuid){ 2 | var path = `${orgUuid}/alerts`; 3 | return this._get(path); 4 | } 5 | 6 | function getAlertData(orgUuid, alertId){ 7 | var path = `${orgUuid}/alerts/${alertId}`; 8 | return this._get(path); 9 | } 10 | 11 | module.exports.getAlerts = getAlerts; 12 | module.exports.getAlertData = getAlertData; 13 | -------------------------------------------------------------------------------- /test/roleTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Role API Test', function() { 5 | 6 | it('should get roles', function(done) { 7 | configured.sdk.getRoles().then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /test/alertTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Alert API Test', function() { 5 | 6 | it('should get alerts', function(done) { 7 | configured.sdk.getAlerts(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /test/webhookTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Webhook API Test', function() { 5 | 6 | it('should get webhooks', function(done) { 7 | configured.sdk.getWebhooks(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /test/config.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "username": "contrast_admin", 3 | "apiKey": "demo", 4 | "serviceKey":"demo", 5 | "teamserverUrl": "http://127.0.0.1:19080/Contrast", 6 | "orgUuid": "de7dd2a9-7643-46fb-b9d8-9c38aeffed7e", 7 | "serverId": "2", 8 | "appId": "982a4e03-694e-4b00-8d33-955ad6950168", 9 | "traceId": "R6A5-0Z83-BCQM-QDSA", 10 | "javaLibrarHash": "94a9ce681a42d0352b3ad22659f67835e560d107" 11 | } -------------------------------------------------------------------------------- /api/webhook.js: -------------------------------------------------------------------------------- 1 | function getWebhooks(orgUuid, expand){ 2 | var path = `${orgUuid}/webhooks`; 3 | return this._get(path, {'expand': expand}); 4 | } 5 | 6 | function getWebhook(orgUuid, webhookId, expand){ 7 | var path = `${orgUuid}/webhooks/${webhookId}`; 8 | return this._get(path, {'expand': expand}); 9 | } 10 | 11 | module.exports.getWebhooks = getWebhooks; 12 | module.exports.getWebhook = getWebhook; 13 | -------------------------------------------------------------------------------- /api/rules.js: -------------------------------------------------------------------------------- 1 | function getValidatorsAndSanitizers(orgUuid){ 2 | var path = `${orgUuid}/controls`; 3 | return this._get(path); 4 | } 5 | 6 | function getControlSuggestions(orgUuid){ 7 | var path =`${orgUuid}/controls/suggestion`; 8 | return this._get(path); 9 | } 10 | 11 | module.exports.getValidatorsAndSanitizers = getValidatorsAndSanitizers 12 | module.exports.getControlSuggestions = getControlSuggestions 13 | -------------------------------------------------------------------------------- /test/setup.js: -------------------------------------------------------------------------------- 1 | var ContrastSdk = require('../index.js'); 2 | var config = require('./config'); 3 | 4 | module.exports.sdk = new ContrastSdk(config.username, config.apiKey, config.serviceKey, config.teamserverUrl); 5 | module.exports.org = config.orgUuid; 6 | module.exports.username = config.username 7 | module.exports.server = config.serverId; 8 | module.exports.app = config.appId; 9 | module.exports.trace = config.traceId; 10 | module.exports.library = config.javaLibraryHash; 11 | -------------------------------------------------------------------------------- /api/modules.js: -------------------------------------------------------------------------------- 1 | function getApplicationModules(orgUuid, expand){ 2 | var path = `${orgUuid}/modules`; 3 | return this._get(path, params={'expand': expand}); 4 | } 5 | 6 | function getApplicationChildModules(orgUuid, appId, expand){ 7 | var path = `${orgUuid}/modules/${appId}`; 8 | return this._get(path, params={'expand':expand}); 9 | } 10 | 11 | module.exports.getApplicationModules = getApplicationModules; 12 | module.exports.getApplicationChildModules = getApplicationChildModules; 13 | -------------------------------------------------------------------------------- /test/sdkTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var ContrastSdk = require('../index.js'); 3 | 4 | var testConfig = require('./config'); 5 | 6 | describe('SDK Setup Test', function() { 7 | 8 | it('Should have created correct headers', function() { 9 | sdk = new ContrastSdk('contrast_admin','demo','demo') 10 | assert(sdk); 11 | assert(sdk.headers); 12 | assert.equal(testConfig.authorizationHeader, sdk.headers.Authorization); 13 | assert.equal(testConfig.apiKey, sdk.headers['API-Key']); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contrast-sdk", 3 | "version": "0.0.1", 4 | "description": "Node module to interact with the Contrast API", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha --timeout 10000", 8 | "client": "browserify index.js --s ContrastSdk > contrast-security.js" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "chai": "^4.2.0" 15 | }, 16 | "dependencies": { 17 | "contrast-sdk": "0.0.1", 18 | "request": "^2.88.0", 19 | "request-promise": "^4.2.4" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /api/history.js: -------------------------------------------------------------------------------- 1 | function getOrganizationScoreHistory(orgUuid, limit){ 2 | var path = `${orgUuid}/history/scores`; 3 | return this._get(path, params={'limit':limit}); 4 | } 5 | 6 | function getOrganizationScoreHistoryInterval(orgUuid, interval, includeDefense){ 7 | defense = includeDefense ? '/defense' : ''; 8 | var path = `${orgUuid}/history/scores/interval${defense}`; 9 | return this._get(path, params={'interval':interval}); 10 | } 11 | 12 | module.exports.getOrganizationScoreHistory = getOrganizationScoreHistory; 13 | module.exports.getOrganizationScoreHistoryInterval = getOrganizationScoreHistoryInterval; 14 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | target-branch: main 6 | schedule: 7 | interval: "daily" 8 | time: "07:00" 9 | labels: 10 | - "dependencies" 11 | open-pull-requests-limit: 5 12 | reviewers: 13 | - "Contrast-Security-OSS/ecosystem-engineering" 14 | 15 | - package-ecosystem: "github-actions" 16 | directory: "/" 17 | target-branch: main 18 | schedule: 19 | interval: "daily" 20 | time: "07:00" 21 | labels: 22 | - "dependencies" 23 | open-pull-requests-limit: 5 24 | reviewers: 25 | - "Contrast-Security-OSS/ecosystem-engineering" 26 | -------------------------------------------------------------------------------- /test/modulesTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Module API Test', function() { 5 | 6 | it('should get modules', function(done) { 7 | configured.sdk.getApplicationModules(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get application child modules', function(done) { 14 | configured.sdk.getApplicationChildModules(configured.org, configured.app).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/rulesTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Rules Policy API Test', function() { 5 | 6 | it('should get validators and sanitizers', function(done) { 7 | configured.sdk.getValidatorsAndSanitizers(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get control suggestions', function(done) { 14 | configured.sdk.getControlSuggestions(configured.org).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/historyTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('History API Test', function() { 5 | 6 | it('should get org history', function(done) { 7 | configured.sdk.getOrganizationScoreHistory(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get org history with interval', function(done) { 14 | configured.sdk.getOrganizationScoreHistoryInterval(configured.org, 'WEEK').then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /api/agent.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var _path = require('path'); 3 | 4 | function getAgentProfiles(orgUuid, expand){ 5 | var path = `${orgUuid}/agents/profiles`; 6 | return this._get(path, {'expand': expand}); 7 | } 8 | 9 | function getAgentProfile(orgUuid, profile, expand){ 10 | var path = `${orgUuid}/agents/profiles/${profile}`; 11 | return this._get(path, {'expand': expand}); 12 | } 13 | 14 | function getAgentVersions(orgUuid){ 15 | var path = `${orgUuid}/agents/versions`; 16 | return this._get(path); 17 | } 18 | 19 | module.exports.getAgentProfiles = getAgentProfiles; 20 | module.exports.getAgentProfile = getAgentProfile; 21 | module.exports.getAgentVersions = getAgentVersions; 22 | -------------------------------------------------------------------------------- /test/agentTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | var path = require('path'); 4 | var fs = require('fs'); 5 | 6 | describe('Agent API Test', function() { 7 | 8 | it('should get agent profiles', function(done) { 9 | configured.sdk.getAgentProfiles(configured.org).then(function(response){ 10 | assert.equal(true, response.success); 11 | done(); 12 | }); 13 | }); 14 | 15 | it('should get agent versions', function(done) { 16 | configured.sdk.getAgentVersions(configured.org).then(function(response){ 17 | assert.equal(true, response.success); 18 | done(); 19 | }); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /api/events.js: -------------------------------------------------------------------------------- 1 | function getLatestEvents(orgUuid, limit){ 2 | var path = `${orgUuid}/events`; 3 | return this._get(path, params={'limit':limit}); 4 | } 5 | 6 | function getLatestApplicationCreation(orgUuid, limit){ 7 | var path = `${orgUuid}/events/application`; 8 | return this._get(path, params={'limit':limit}); 9 | } 10 | 11 | function getLatestServerCreation(orgUuid, limit){ 12 | var path = `${orgUuid}/events/server`; 13 | return this._get(path, params={'limit': limit}); 14 | } 15 | 16 | function getLatestTracesReceived(orgUuid, limit){ 17 | var path = `${orgUuid}/events/trace`; 18 | return this._get(path, params={'limit': limit}); 19 | } 20 | 21 | module.exports.getLatestEvents = getLatestEvents; 22 | module.exports.getLatestApplicationCreation = getLatestApplicationCreation; 23 | module.exports.getLatestServerCreation = getLatestServerCreation; 24 | module.exports.getLatestTracesReceived = getLatestTracesReceived; 25 | -------------------------------------------------------------------------------- /test/eventsTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Event API Test', function() { 5 | 6 | it('should get latest events', function(done) { 7 | configured.sdk.getLatestEvents(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get org history with interval', function(done) { 14 | configured.sdk.getLatestApplicationCreation(configured.org).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get latest events', function(done) { 21 | configured.sdk.getLatestServerCreation(configured.org).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should get org history with interval', function(done) { 28 | configured.sdk.getLatestTracesReceived(configured.org).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | }); 35 | -------------------------------------------------------------------------------- /api/profile.js: -------------------------------------------------------------------------------- 1 | function getProfileInfo(params){ 2 | return this._get('profile', params); 3 | } 4 | 5 | function getProfileOrganizations(){ 6 | return this._get('profile/organizations'); 7 | } 8 | 9 | function getProfileDefaultOrganization(){ 10 | return this._get('profile/organizations/default'); 11 | } 12 | 13 | function getOrgInfo(orgUuid){ 14 | path = `profile/organizations/${orgUuid}`; 15 | return this._get(path); 16 | } 17 | 18 | function getProfilePasswordPolicy(){ 19 | return this._get('profile/passwordpolicy'); 20 | } 21 | 22 | function getProfileRoles(){ 23 | return this._get('profile/roles'); 24 | } 25 | 26 | function setProfileDefaultOrg(orgUuid){ 27 | path = `profile/${orgUuid}/default`; 28 | return this._put(path); 29 | } 30 | 31 | module.exports.getProfileInfo = getProfileInfo; 32 | module.exports.getProfileOrganizations = getProfileOrganizations; 33 | module.exports.getProfileDefaultOrganization = getProfileDefaultOrganization; 34 | module.exports.getOrgInfo = getOrgInfo; 35 | module.exports.getProfilePasswordPolicy = getProfilePasswordPolicy; 36 | module.exports.getProfileRoles = getProfileRoles; 37 | module.exports.setProfileDefaultOrg = setProfileDefaultOrg 38 | -------------------------------------------------------------------------------- /api/library.js: -------------------------------------------------------------------------------- 1 | function getLibraries(orgUuid, expand, quickFilter){ 2 | var path = `${orgUuid}/libraries`; 3 | return this._get(path, params={'expand': expand, 'quickFilter': quickFilter}); 4 | } 5 | 6 | function getDotnetLibrary(orgUuid, libraryHash, expand){ 7 | var path = `${orgUuid}/libraries/dotnet/${libraryHash}`; 8 | return this._get(path, params={'expand': expand}); 9 | } 10 | 11 | function getJavaLibrary(orgUuid, libraryHash, expand){ 12 | var path = `${orgUuid}/libraries/java/${libraryHash}`; 13 | return this._get(path, params={'expand': expand}); 14 | } 15 | 16 | function getLibraryStats(orgUuid){ 17 | var path = `${orgUuid}/libraries/stats`; 18 | return this._get(path); 19 | } 20 | 21 | function filterLibraries(orgUuid, filter){ 22 | var path = `${orgUuid}/libraries/filter`; 23 | return this._get(path, params=filter); 24 | } 25 | 26 | function getLibraryPolicy(orgUuid){ 27 | var path = `${orgUuid}/library/policy`; 28 | return this._get(path); 29 | } 30 | 31 | module.exports.getLibraries = getLibraries 32 | module.exports.getDotnetLibrary = getDotnetLibrary 33 | module.exports.getJavaLibrary = getJavaLibrary 34 | module.exports.getLibraryStats = getLibraryStats 35 | module.exports.filterLibraries = filterLibraries 36 | module.exports.getLibraryPolicy = getLibraryPolicy 37 | -------------------------------------------------------------------------------- /api/user.js: -------------------------------------------------------------------------------- 1 | function getUsers(orgUuid, expand){ 2 | var path = `${orgUuid}/users`; 3 | return this._get(path, {'expand': expand}); 4 | } 5 | 6 | function getCustomAlerts(orgUuid){ 7 | var path = `${orgUuid}/users/alerts/custom`; 8 | return this._get(path); 9 | } 10 | 11 | function getCustomAttackAlerts(orgUuid){ 12 | var path = `${orgUuid}/users/alerts/custom/attacks`; 13 | return this._get(path); 14 | } 15 | 16 | function getCustomVulnerabilityAlerts(orgUuid){ 17 | var path = `${orgUuid}/users/alerts/custom/vulnerabilities`; 18 | return this._get(path); 19 | } 20 | 21 | function getUserInformation(orgUuid, userId, expand){ 22 | var path = `${orgUuid}/users/alerts/custom/vulnerabilities`; 23 | return this._get(path, {'expand': expand}); 24 | } 25 | 26 | function getUserAuthorizationHeader(orgUuid, userId){ 27 | var path = `${orgUuid}/users/${userId}/authorization`; 28 | return this._get(path); 29 | } 30 | 31 | module.exports.getUsers = getUsers; 32 | module.exports.getCustomAlerts = getCustomAlerts; 33 | module.exports.getCustomAttackAlerts = getCustomAttackAlerts; 34 | module.exports.getCustomVulnerabilityAlerts = getCustomVulnerabilityAlerts; 35 | module.exports.getUserInformation = getUserInformation; 36 | module.exports.getUserAuthorizationHeader = getUserAuthorizationHeader; 37 | -------------------------------------------------------------------------------- /test/userTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('User API Test', function() { 5 | 6 | it('should get org users', function(done) { 7 | configured.sdk.getUsers(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get custom alerts', function(done) { 14 | configured.sdk.getCustomAlerts(configured.org).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get custom attack alerts', function(done) { 21 | configured.sdk.getCustomAttackAlerts(configured.org).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should get custom vuln alerts', function(done) { 28 | configured.sdk.getCustomVulnerabilityAlerts(configured.org).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should get user info', function(done) { 35 | configured.sdk.getUserInformation(configured.org, configured.username).then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should get user auth header', function(done) { 42 | configured.sdk.getUsers(configured.org, configured.username).then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | }); 49 | -------------------------------------------------------------------------------- /api/support.js: -------------------------------------------------------------------------------- 1 | var rp = require('request-promise'); 2 | 3 | function _get(path, params){ 4 | url = this.teamserverUrl + this.version + path 5 | var options = { 6 | uri: url, 7 | qs: params, 8 | headers: this.headers, 9 | json: true 10 | }; 11 | return rp(options); 12 | } 13 | 14 | function _post(path, data){ 15 | url = this.teamserverUrl + this.version + path 16 | var options = { 17 | method: 'POST', 18 | uri: url, 19 | body: data, 20 | headers: this.headers, 21 | json: true 22 | }; 23 | return rp(options); 24 | } 25 | 26 | function _put(path, data){ 27 | url = this.teamserverUrl + this.version + path 28 | var options = { 29 | method: 'PUT', 30 | uri: url, 31 | body: data, 32 | headers: this.headers, 33 | json: true 34 | }; 35 | return rp(options); 36 | } 37 | 38 | 39 | function _delete(path, data){ 40 | url = this.teamserverUrl + this.version + path 41 | var options = { 42 | method: 'DELETE', 43 | uri: url, 44 | body: data, 45 | headers: this.headers, 46 | json: true 47 | }; 48 | return rp(options); 49 | } 50 | 51 | function _download(path, params){ 52 | url = this.teamserverUrl + this.version + path; 53 | var options = { 54 | uri: url, 55 | qs: params, 56 | headers: this.headers, 57 | resolveWithFullResponse: true, 58 | encoding: null 59 | }; 60 | return rp(options); 61 | } 62 | 63 | module.exports._get = _get; 64 | module.exports._post = _post; 65 | module.exports._put = _put; 66 | module.exports._delete = _delete; 67 | module.exports._download = _download; 68 | -------------------------------------------------------------------------------- /test/libraryTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Library API Test', function() { 5 | 6 | it('should get libraries', function(done) { 7 | configured.sdk.getLibraries(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get java library', function(done) { 14 | configured.sdk.getLibraries(configured.org, configured.library).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get org library stats', function(done) { 21 | configured.sdk.getLibraryStats(configured.org).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should filter libraries', function(done) { 28 | configured.sdk.filterLibraries(configured.org).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should get libraries', function(done) { 35 | configured.sdk.getLibraries(configured.org).then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should get library policy', function(done) { 42 | configured.sdk.getLibraryPolicy(configured.org).then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | it('should get libraries', function(done) { 49 | configured.sdk.getLibraries(configured.org).then(function(response){ 50 | assert.equal(true, response.success); 51 | done(); 52 | }); 53 | }); 54 | 55 | }); 56 | -------------------------------------------------------------------------------- /test/profileTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Profile API Test', function() { 5 | 6 | it('should get profile info', function(done) { 7 | configured.sdk.getProfileInfo().then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get profile organizations', function(done) { 14 | configured.sdk.getProfileOrganizations().then(function(response){ 15 | assert(response.organizations) 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get profile default org', function(done) { 21 | configured.sdk.getProfileDefaultOrganization().then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should get profile org info', function(done) { 28 | configured.sdk.getOrgInfo(configured.org).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should get profile password policy info', function(done) { 35 | configured.sdk.getProfilePasswordPolicy().then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should get profile roles', function(done) { 42 | configured.sdk.getProfileRoles().then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | it('should set profile default org', function(done) { 49 | configured.sdk.setProfileDefaultOrg(configured.org).then(function(response){ 50 | assert.equal(true, response.success); 51 | done(); 52 | }); 53 | }); 54 | 55 | 56 | 57 | 58 | }); 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Install 2 | The Contrast Api module is available to install via *npm*. 3 | ```commandline 4 | npm install contrast-sdk --save 5 | ``` 6 | 7 | ### Sample usage 8 | The SDK offers a majority of our public APIs through an instance of the ContrastSdk. 9 | Any method of the SDK that interacts with our API returns a promise. 10 | 11 | > **Note:** The Contrast URL is optional and defaults to https://app.contrastsecurity.com/Contrast/api 12 | 13 | ```javascript 14 | var ContrastSdk = require('contrast-sdk'); 15 | var contrastSdk = new ContrastSdk('username','api_key','service_key','teamserver_url'); 16 | ``` 17 | 18 | An example of getting an application: 19 | ```javascript 20 | var orgUuid='organization_uuid'; 21 | contrastSdk.getApplication(orgUuid, 'an_app_id').then(function(response){ 22 | console.log(response.application.name); 23 | }); 24 | ``` 25 | 26 | In some cases, you may want to filter applications, servers, traces or libraries. Any endpoint that involves filtering can use the appropriate filter object. 27 | 28 | These methods are easily identifiable on the ContrastSdk object by looking at any methods that include the phrase `filter`. 29 | 30 | ```javascript 31 | var filter = {}; 32 | filter.apps = ['appId1', 'appId2']; 33 | contrastSdk.filterLibraries(orgUuid, filter).then(function(response){ 34 | response.libraries.forEach(function(library){ 35 | console.log(library.file_name + ' : ' + library.grade); 36 | }); 37 | }); 38 | ``` 39 | 40 | ### Developing 41 | Use *npm* to install the projects dependencies: 42 | 43 | ```commandline 44 | npm install 45 | npm install -g mocha 46 | ``` 47 | 48 | To run the tests, create a file in the `/tests` directory called *config.json* with TeamServer information. An example test configuration can be seen in `tests/config.json.example`. 49 | 50 | Then run tests with mocha: 51 | 52 | ```commandline 53 | npm run test 54 | ``` 55 | -------------------------------------------------------------------------------- /api/scores.js: -------------------------------------------------------------------------------- 1 | function getOverallScores(orgUuid){ 2 | var path = `${orgUuid}/scores`; 3 | return this._get(path); 4 | } 5 | 6 | function getScoreCategoryBreakdown(orgUuid){ 7 | var path = `${orgUuid}/scores/breakdown/category`; 8 | return this._get(path); 9 | } 10 | 11 | function getScoreRuleBreakdown(orgUuid){ 12 | var path =`${orgUuid}/scores/breakdown/rule`; 13 | return this._get(path); 14 | } 15 | 16 | function getScoreServerBreakdown(orgUuid){ 17 | var path =`${orgUuid}/scores/breakdown/server`; 18 | return this._get(path); 19 | } 20 | 21 | function getScoreSeverityBreakdown(orgUuid){ 22 | var path = `${orgUuid}/scores/breakdown/severity`; 23 | return this._get(path); 24 | } 25 | 26 | function getScoreStatusBreakdown(orgUuid){ 27 | var path = `${orgUuid}/scores/breakdown/status`; 28 | return this._get(path); 29 | } 30 | 31 | function getScoreTraceRuleBreakdown(orgUuid){ 32 | var path = `${orgUuid}/scores/breakdown/trace/rule`; 33 | return this._get(path); 34 | } 35 | 36 | function getScoreTraceSeverityBreakdown(orgUuid){ 37 | var path = `${orgUuid}/scores/breakdown/trace/severity`; 38 | return this._get(path); 39 | } 40 | 41 | function getScoreTraceStatusBreakdown(orgUuid){ 42 | var path = `${orgUuid}/scores/breakdown/trace/status`; 43 | return this._get(path); 44 | } 45 | 46 | function getPlatformScore(orgUuid, includeDefense){ 47 | var defense = includeDefense ? '/defense' : ''; 48 | var path = `${orgUuid}/scores/platform/${defense}`; 49 | return this._get(path); 50 | } 51 | 52 | function getSecurityScore(orgUuid, includeDefense){ 53 | var defense = includeDefense ? '/defense' : ''; 54 | var path = `${orgUuid}/scores/security/${defense}`; 55 | return this._get(path); 56 | } 57 | 58 | module.exports.getOverallScores = getOverallScores 59 | module.exports.getScoreCategoryBreakdown = getScoreCategoryBreakdown 60 | module.exports.getScoreRuleBreakdown = getScoreRuleBreakdown 61 | module.exports.getScoreServerBreakdown = getScoreServerBreakdown 62 | module.exports.getScoreSeverityBreakdown = getScoreSeverityBreakdown 63 | module.exports.getScoreStatusBreakdown = getScoreStatusBreakdown 64 | module.exports.getScoreTraceRuleBreakdown = getScoreTraceRuleBreakdown 65 | module.exports.getScoreTraceSeverityBreakdown = getScoreTraceSeverityBreakdown 66 | module.exports.getScoreTraceStatusBreakdown = getScoreTraceStatusBreakdown 67 | module.exports.getPlatformScore = getPlatformScore 68 | module.exports.getSecurityScore = getSecurityScore 69 | -------------------------------------------------------------------------------- /api/trace.js: -------------------------------------------------------------------------------- 1 | function filterOrgTraces(orgUuid, filter){ 2 | var path = `${orgUuid}/orgtraces/filter`; 3 | return this._get(path, filter); 4 | } 5 | 6 | function getOrgTrace(orgUuid, traceId, expand){ 7 | var path = `${orgUuid}/orgtraces/filter/${traceId}`; 8 | return this._get(path, {'expand': expand}); 9 | } 10 | 11 | function getTraceNotes(orgUuid, appId, traceId){ 12 | var path = `${orgUuid}/applications/${appId}/traces/${traceId}/notes`; 13 | return this._get(path); 14 | } 15 | 16 | function createTraceNote(orgUuid, appId, traceId, note){ 17 | var path = `${orgUuid}/applications/${appId}/traces/${traceId}/notes`; 18 | return this._post(path, {'note': note}); 19 | } 20 | 21 | function getOrgTraceIds(orgUuid, filter){ 22 | var path = `${orgUuid}/orgtraces/ids`; 23 | return this._get(path, filter); 24 | } 25 | 26 | function getOrgTracePolicyViolations(orgUuid){ 27 | var path = `${orgUuid}/orgtraces/policy/violations`; 28 | return this._get(path); 29 | } 30 | 31 | function getTraceVisibility(orgUuid, traceId){ 32 | var path = `${orgUuid}/orgtraces/${traceId}/visible`; 33 | return this._get(path); 34 | } 35 | 36 | function getNewTraceTrend(orgUuid, interval, filter){ 37 | var path = `${orgUuid}/orgtraces/stats/trend/${interval}/new`; 38 | return this._get(path, filter); 39 | } 40 | 41 | function getTotalTraceTrend(orgUuid, interval, filter){ 42 | var path = `${orgUuid}/orgtraces/stats/trend/${interval}/total`; 43 | return this._get(path, filter); 44 | } 45 | 46 | function getTraceTimeToRemediateCurrent(orgUuid){ 47 | var path = `${orgUuid}/orgtraces/stats/ttr/severity/current`; 48 | return this._get(path); 49 | } 50 | 51 | function getTraceTimeToRemediateMonthTrend(orgUuid){ 52 | var path = `${orgUuid}/orgtraces/stats/ttr/severity/trend`; 53 | return this._get(path); 54 | } 55 | 56 | module.exports.filterOrgTraces = filterOrgTraces 57 | module.exports.getOrgTrace = getOrgTrace 58 | module.exports.getTraceNotes = getTraceNotes 59 | module.exports.createTraceNote = createTraceNote 60 | module.exports.getOrgTraceIds = getOrgTraceIds 61 | module.exports.getOrgTracePolicyViolations = getOrgTracePolicyViolations 62 | module.exports.getTraceVisibility = getTraceVisibility 63 | module.exports.getNewTraceTrend = getNewTraceTrend 64 | module.exports.getTotalTraceTrend = getTotalTraceTrend 65 | module.exports.getTraceTimeToRemediateCurrent = getTraceTimeToRemediateCurrent 66 | module.exports.getTraceTimeToRemediateMonthTrend = getTraceTimeToRemediateMonthTrend 67 | -------------------------------------------------------------------------------- /api/organization.js: -------------------------------------------------------------------------------- 1 | function search(orgUuid, query){ 2 | var path = `${orgUuid}/search`; 3 | return this._get(path, params={'q':query}); 4 | } 5 | 6 | function getOrganizationInfo(orgUuid, expand){ 7 | var path = `${orgUuid}/organizations`; 8 | return this._get(path, params={'expand': expand}); 9 | } 10 | 11 | function getOrganizationAdministrators(orgUuid){ 12 | var path = `${orgUuid}/organizations/administrators`; 13 | return this._get(path); 14 | } 15 | 16 | function getOrganizationApplicationRoles(orgUuid){ 17 | var path = `${orgUuid}/organizations/application/roles`; 18 | return this._get(path); 19 | } 20 | 21 | function getOrganizationServersNeedingRestart(orgUuid, language){ 22 | var path = `${orgUuid}/organizations/servers/restart/${language}`; 23 | return this._get(path); 24 | } 25 | 26 | function getOrganizationApplicationStats(orgUuid, interval, expand){ 27 | var path = `${orgUuid}/organizations/stats/application`; 28 | return this._get(path, params={'interval':interval, 'expand': expand}); 29 | } 30 | 31 | function getOrganizationLibraryStats(orgUuid, interval, expand){ 32 | var path = `${orgUuid}/organizations/stats/library`; 33 | return this._get(path, params={'interval':interval, 'expand': expand}); 34 | } 35 | 36 | function getOrganizationServerStats(orgUuid, interval, expand){ 37 | var path = `${orgUuid}/organizations/stats/server`; 38 | return this._get(path, params={'interval':interval, 'expand': expand}); 39 | } 40 | 41 | function getOrganizationTraceStats(orgUuid, interval){ 42 | var path = `${orgUuid}/organizations/stats/trace`; 43 | return this._get(path, params={'interval':interval}); 44 | } 45 | 46 | function getOrganizationServerSettings(orgUuid){ 47 | var path = `${orgUuid}/server/settings`; 48 | return this._get(path); 49 | } 50 | 51 | 52 | 53 | module.exports.search = search; 54 | module.exports.getOrganizationInfo = getOrganizationInfo; 55 | module.exports.getOrganizationAdministrators = getOrganizationAdministrators; 56 | module.exports.getOrganizationApplicationRoles = getOrganizationApplicationRoles; 57 | module.exports.getOrganizationServersNeedingRestart = getOrganizationServersNeedingRestart; 58 | module.exports.getOrganizationApplicationStats = getOrganizationApplicationStats; 59 | module.exports.getOrganizationLibraryStats = getOrganizationLibraryStats; 60 | module.exports.getOrganizationServerStats = getOrganizationServerStats; 61 | module.exports.getOrganizationTraceStats = getOrganizationTraceStats; 62 | module.exports.getOrganizationServerSettings = getOrganizationServerSettings; 63 | -------------------------------------------------------------------------------- /test/organizationTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Organization API Test', function() { 5 | 6 | it('should search', function(done) { 7 | configured.sdk.search(configured.org, 'app').then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('get organization info', function(done) { 14 | configured.sdk.getOrganizationInfo(configured.org).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('get organization admins', function(done) { 21 | configured.sdk.getOrganizationAdministrators(configured.org).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('get organization application roles', function(done) { 28 | configured.sdk.getOrganizationApplicationRoles(configured.org).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('get organization servers needing restart', function(done) { 35 | configured.sdk.getOrganizationServersNeedingRestart(configured.org, 'Java').then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('get organization application stats', function(done) { 42 | configured.sdk.getOrganizationApplicationStats(configured.org).then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | it('get organization library stats', function(done) { 49 | configured.sdk.getOrganizationLibraryStats(configured.org).then(function(response){ 50 | assert.equal(true, response.success); 51 | done(); 52 | }); 53 | }); 54 | 55 | it('get organization server stats', function(done) { 56 | configured.sdk.getOrganizationServerStats(configured.org).then(function(response){ 57 | assert.equal(true, response.success); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('get organization trace stats', function(done) { 63 | configured.sdk.getOrganizationTraceStats(configured.org).then(function(response){ 64 | assert.equal(true, response.success); 65 | done(); 66 | }); 67 | }); 68 | 69 | it('get organization server settings', function(done) { 70 | configured.sdk.getOrganizationServerSettings(configured.org).then(function(response){ 71 | assert.equal(true, response.success); 72 | done(); 73 | }); 74 | }); 75 | 76 | }); 77 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var ProfileApi = require('./api/profile'); 2 | var OrganizationApi = require('./api/organization'); 3 | var HistoryApi = require('./api/history'); 4 | var EventsApi = require('./api/events'); 5 | var LibraryApi = require('./api/library'); 6 | var ModuleApi = require('./api/modules'); 7 | var AlertApi = require('./api/alerts'); 8 | var RoleApi = require('./api/role'); 9 | var ServerApi = require('./api/server'); 10 | var UserApi = require('./api/user'); 11 | var WebhookApi = require('./api/webhook'); 12 | var ScoreApi = require('./api/scores'); 13 | var RulesApi = require('./api/rules'); 14 | var TraceApi = require('./api/trace'); 15 | var TagsApi = require('./api/tags'); 16 | var ApplicationApi = require('./api/application'); 17 | var AgentApi = require('./api/agent'); 18 | 19 | var ApiSupport = require('./api/support') 20 | 21 | function ContrastSdk(username, apiKey, serviceKey, teamserverUrl){ 22 | this.username = username; 23 | this.apiKey = apiKey; 24 | this.serviceKey = serviceKey; 25 | this.teamserverUrl = teamserverUrl || 'https://app.contrastsecurity.com/Contrast/api'; 26 | this.headers = createHeaders(username, serviceKey, apiKey); 27 | this.version = '/ng/'; 28 | configureAllApis(this); 29 | } 30 | 31 | function createHeaders(username, serviceKey, apiKey){ 32 | var buffer = new Buffer(username + ':' + serviceKey); 33 | var authorization = buffer.toString('base64'); 34 | return { 35 | 'Authorization': authorization, 36 | 'API-Key': apiKey, 37 | 'Content-type': 'application/json', 38 | 'Accept': 'application/json' 39 | }; 40 | } 41 | 42 | function configureAllApis(instance){ 43 | configureGenericApi(ProfileApi, instance); 44 | configureGenericApi(OrganizationApi, instance); 45 | configureGenericApi(HistoryApi, instance); 46 | configureGenericApi(EventsApi, instance); 47 | configureGenericApi(LibraryApi, instance); 48 | configureGenericApi(ModuleApi, instance); 49 | configureGenericApi(AlertApi, instance); 50 | configureGenericApi(RoleApi, instance); 51 | configureGenericApi(ServerApi, instance); 52 | configureGenericApi(UserApi, instance); 53 | configureGenericApi(WebhookApi, instance); 54 | configureGenericApi(ScoreApi, instance); 55 | configureGenericApi(RulesApi, instance); 56 | configureGenericApi(TraceApi, instance); 57 | configureGenericApi(TagsApi, instance); 58 | configureGenericApi(ApplicationApi, instance); 59 | configureGenericApi(AgentApi, instance); 60 | } 61 | 62 | function configureGenericApi(api, instance){ 63 | var methods = Object.keys(api); 64 | for (var i = 0; i < methods.length; i++){ 65 | ContrastSdk.prototype[methods[i]] = api[methods[i]]; 66 | } 67 | } 68 | 69 | ContrastSdk.prototype._get = ApiSupport._get; 70 | ContrastSdk.prototype._post = ApiSupport._post; 71 | ContrastSdk.prototype._put = ApiSupport._put; 72 | ContrastSdk.prototype._delete = ApiSupport._delete; 73 | ContrastSdk.prototype._download = ApiSupport._download; 74 | 75 | module.exports = ContrastSdk; 76 | -------------------------------------------------------------------------------- /test/scoreTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Score API Test', function() { 5 | 6 | it('should get overall scores', function(done) { 7 | configured.sdk.getOverallScores(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get score category breakdown', function(done) { 14 | configured.sdk.getScoreCategoryBreakdown(configured.org).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get score rule breakdown', function(done) { 21 | configured.sdk.getScoreRuleBreakdown(configured.org).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should get score server breakdown', function(done) { 28 | configured.sdk.getScoreServerBreakdown(configured.org).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should get score severity breakdown', function(done) { 35 | configured.sdk.getScoreSeverityBreakdown(configured.org).then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should get score status breakdown', function(done) { 42 | configured.sdk.getScoreStatusBreakdown(configured.org).then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | it('should get score trace rule breakdown', function(done) { 49 | configured.sdk.getScoreTraceRuleBreakdown(configured.org).then(function(response){ 50 | assert.equal(true, response.success); 51 | done(); 52 | }); 53 | }); 54 | 55 | it('should get score trace severity breakdown', function(done) { 56 | configured.sdk.getScoreTraceSeverityBreakdown(configured.org).then(function(response){ 57 | assert.equal(true, response.success); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('should get score trace status breakdown', function(done) { 63 | configured.sdk.getScoreTraceStatusBreakdown(configured.org).then(function(response){ 64 | assert.equal(true, response.success); 65 | done(); 66 | }); 67 | }); 68 | 69 | it('should get platform score', function(done) { 70 | configured.sdk.getPlatformScore(configured.org).then(function(response){ 71 | assert.equal(true, response.success); 72 | done(); 73 | }); 74 | }); 75 | 76 | it('should get security score', function(done) { 77 | configured.sdk.getSecurityScore(configured.org).then(function(response){ 78 | assert.equal(true, response.success); 79 | done(); 80 | }); 81 | }); 82 | 83 | }); 84 | -------------------------------------------------------------------------------- /test/traceTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Trace API Test', function() { 5 | 6 | it('should filter traces', function(done) { 7 | configured.sdk.filterOrgTraces(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get org trace', function(done) { 14 | configured.sdk.getOrgTrace(configured.org, configured.trace).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get trace notes', function(done) { 21 | configured.sdk.getTraceNotes(configured.org, configured.app, configured.trace).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should create trace note', function(done) { 28 | configured.sdk.createTraceNote(configured.org, configured.app, configured.trace, 'test').then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should get org trace ids', function(done) { 35 | configured.sdk.getOrgTraceIds(configured.org).then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should get org policy violations', function(done) { 42 | configured.sdk.getOrgTracePolicyViolations(configured.org).then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | it('should get trace visibility', function(done) { 49 | configured.sdk.getTraceVisibility(configured.org, configured.trace).then(function(response){ 50 | assert.equal(true, response.success); 51 | done(); 52 | }); 53 | }); 54 | 55 | it('should get new trace trend', function(done) { 56 | configured.sdk.getNewTraceTrend(configured.org, 'week').then(function(response){ 57 | assert.equal(true, response.success); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('should get total trace trend', function(done) { 63 | configured.sdk.getTotalTraceTrend(configured.org, 'week').then(function(response){ 64 | assert.equal(true, response.success); 65 | done(); 66 | }); 67 | }); 68 | 69 | it('should get trace time to remediate month trend ', function(done) { 70 | configured.sdk.getTraceTimeToRemediateMonthTrend(configured.org).then(function(response){ 71 | assert.equal(true, response.success); 72 | done(); 73 | }); 74 | }); 75 | 76 | it('should get trace time to remediate current', function(done) { 77 | configured.sdk.getTraceTimeToRemediateCurrent(configured.org).then(function(response){ 78 | assert.equal(true, response.success); 79 | done(); 80 | }); 81 | }); 82 | 83 | }); 84 | -------------------------------------------------------------------------------- /api/tags.js: -------------------------------------------------------------------------------- 1 | function getApplicationTags(orgUuid, appId){ 2 | var path = `${orgUuid}/tags/application/list/${appId}`; 3 | return this._get(path); 4 | } 5 | 6 | function getAllLibraryTags(orgUuid){ 7 | var path = `${orgUuid}/tags/libraries/list`; 8 | return this._get(path); 9 | } 10 | 11 | function getAllApplicationTags(orgUuid){ 12 | var path = `${orgUuid}/tags/applications/list`; 13 | return this._get(path); 14 | } 15 | 16 | function getApplicationLibraryTags(orgUuid, appId){ 17 | var path = `${orgUuid}/tags/libraries/${appId}/list`; 18 | return this._get(path); 19 | } 20 | 21 | 22 | function getServerTagList(orgUuid, serverId){ 23 | var path = `${orgUuid}/tags/server/list/${serverId}`; 24 | return this._get(path); 25 | } 26 | 27 | function getAllServerTags(orgUuid){ 28 | var path = `${orgUuid}/tags/servers/list`; 29 | return this._get(path); 30 | } 31 | 32 | function getAllTraceTags(orgUuid){ 33 | var path = `${orgUuid}/tags/traces`; 34 | return this._get(path); 35 | } 36 | 37 | function getAllApplicationTraceTags(orgUuid, appId){ 38 | var path = `${orgUuid}/tags/traces/application/${appId}`; 39 | return this._get(path); 40 | } 41 | 42 | function getAllServerTraceTags(orgUuid, serverId){ 43 | var path = `${orgUuid}/tags/traces/server/${serverId}`; 44 | return this._get(path); 45 | } 46 | 47 | function getAllTagsForTrace(orgUuid, traceId){ 48 | var path = `${orgUuid}/tags/traces/trace/${traceId}`; 49 | return this._get(path); 50 | } 51 | 52 | function tagApplication(orgUuid, appId, tag){ 53 | var path = `${orgUuid}/tags/applications`; 54 | return this._put(path, {'applications_id': [appId], 'links':[],'tags':[tag]}); 55 | } 56 | 57 | function tagServer(orgUuid, serverId, tag){ 58 | var path = `${orgUuid}/tags/servers`; 59 | return this._put(path, {'servers_id': [serverId], 'links':[],'tags':[tag]}); 60 | } 61 | 62 | function tagTrace(orgUuid, traceId, tag){ 63 | var path = `${orgUuid}/tags/traces`; 64 | return this._put(path, {'traces_id': [traceId], 'links':[],'tags':[tag]}); 65 | } 66 | 67 | function deleteTagFromApplication(orgUuid, appId, tag){ 68 | var path = `${orgUuid}/tags/application/${appId}`; 69 | return this._delete(path, {'tag': tag}); 70 | } 71 | 72 | function deleteTagFromTrace(orgUuid, traceId, tag){ 73 | var path = `${orgUuid}/tags/trace/${traceId}`; 74 | return this._delete(path, {'tag': tag}); 75 | } 76 | 77 | function deleteTagFromServer(orgUuid, serverId, tag){ 78 | var path = `${orgUuid}/tags/server/${serverId}`; 79 | return this._delete(path, {'tag': tag}); 80 | } 81 | 82 | 83 | module.exports.getApplicationTags = getApplicationTags 84 | module.exports.getAllLibraryTags = getAllLibraryTags 85 | module.exports.getAllApplicationTags = getAllApplicationTags 86 | module.exports.getApplicationLibraryTags = getApplicationLibraryTags 87 | module.exports.getServerTagList = getServerTagList 88 | module.exports.getAllServerTags = getAllServerTags 89 | module.exports.getAllTraceTags = getAllTraceTags 90 | module.exports.getAllApplicationTraceTags = getAllApplicationTraceTags 91 | module.exports.getAllServerTraceTags = getAllServerTraceTags 92 | module.exports.getAllTagsForTrace = getAllTagsForTrace 93 | module.exports.tagApplication = tagApplication 94 | module.exports.tagServer = tagServer 95 | module.exports.tagTrace = tagTrace 96 | module.exports.deleteTagFromApplication = deleteTagFromApplication 97 | module.exports.deleteTagFromTrace = deleteTagFromTrace 98 | module.exports.deleteTagFromServer = deleteTagFromServer 99 | -------------------------------------------------------------------------------- /test/tagsTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Tags API Test', function() { 5 | 6 | it('should get application tags', function(done) { 7 | configured.sdk.getApplicationTags(configured.org, configured.app).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get all library tags', function(done) { 14 | configured.sdk.getAllLibraryTags(configured.org).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get all application tags', function(done) { 21 | configured.sdk.getAllApplicationTags(configured.org).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should get all application library tags', function(done) { 28 | configured.sdk.getApplicationLibraryTags(configured.org, configured.app).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should get server tag list', function(done) { 35 | configured.sdk.getServerTagList(configured.org, configured.server).then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should get all server tags', function(done) { 42 | configured.sdk.getAllServerTags(configured.org).then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | it('should get all trace tags', function(done) { 49 | configured.sdk.getAllTraceTags(configured.org).then(function(response){ 50 | assert.equal(true, response.success); 51 | done(); 52 | }); 53 | }); 54 | 55 | it('should get all application trace tags', function(done) { 56 | configured.sdk.getAllApplicationTraceTags(configured.org, configured.app).then(function(response){ 57 | assert.equal(true, response.success); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('should get all application trace tags', function(done) { 63 | configured.sdk.getAllApplicationTraceTags(configured.org, configured.app).then(function(response){ 64 | assert.equal(true, response.success); 65 | done(); 66 | }); 67 | }); 68 | 69 | it('should get all server trace tags', function(done) { 70 | configured.sdk.getAllServerTraceTags(configured.org, configured.server).then(function(response){ 71 | assert.equal(true, response.success); 72 | done(); 73 | }); 74 | }); 75 | 76 | it('should get all server trace tags', function(done) { 77 | configured.sdk.getAllServerTraceTags(configured.org, configured.server).then(function(response){ 78 | assert.equal(true, response.success); 79 | done(); 80 | }); 81 | }); 82 | 83 | it('should get all tags for trace', function(done) { 84 | configured.sdk.getAllTagsForTrace(configured.org, configured.trace).then(function(response){ 85 | assert.equal(true, response.success); 86 | done(); 87 | }); 88 | }); 89 | 90 | it('should tag application', function(done) { 91 | configured.sdk.tagApplication(configured.org, configured.app, 'test').then(function(response){ 92 | assert.equal(true, response.success); 93 | done(); 94 | }); 95 | }); 96 | 97 | it('should tag server', function(done) { 98 | configured.sdk.tagServer(configured.org, configured.server, 'test').then(function(response){ 99 | assert.equal(true, response.success); 100 | done(); 101 | }); 102 | }); 103 | 104 | it('should delete application tag', function(done) { 105 | configured.sdk.deleteTagFromApplication(configured.org, configured.app, 'test').then(function(response){ 106 | assert.equal(true, response.success); 107 | done(); 108 | }); 109 | }); 110 | 111 | it('should delete trace tag', function(done) { 112 | configured.sdk.deleteTagFromTrace(configured.org, configured.trace, 'test').then(function(response){ 113 | assert.equal(true, response.success); 114 | done(); 115 | }); 116 | }); 117 | 118 | it('should delete server tag', function(done) { 119 | configured.sdk.deleteTagFromServer(configured.org, configured.server, 'test').then(function(response){ 120 | assert.equal(true, response.success); 121 | done(); 122 | }); 123 | }); 124 | 125 | 126 | }); 127 | -------------------------------------------------------------------------------- /api/server.js: -------------------------------------------------------------------------------- 1 | function getServers(orgUuid, includeArchived,expand,query){ 2 | var path = `${orgUuid}/servers`; 3 | return this._get(path, params={'q':query, 'includeArchived':includeArchived, 'expand':expand}); 4 | } 5 | 6 | function getActiveServers(orgUuid){ 7 | var path = `${orgUuid}/servers/active`; 8 | return this._get(path); 9 | } 10 | 11 | function filterServers(orgUuid, filter){ 12 | var path = `${orgUuid}/servers/filter`; 13 | return this._get(path, params=filter); 14 | } 15 | 16 | function getServerFilters(orgUuid){ 17 | var path = `${orgUuid}/servers/filters/listing`; 18 | return this._get(path); 19 | } 20 | 21 | function getServerFilterSubfilters(orgUuid, filterType){ 22 | var path = `${orgUuid}/servers/filters/${filterType}/listing`; 23 | return this._get(path); 24 | } 25 | 26 | function getServerModes(orgUuid){ 27 | var path = `${orgUuid}/servers/modes`; 28 | return this._get(path); 29 | } 30 | 31 | function getServerDetails(orgUuid, serverId, expand){ 32 | var path = `${orgUuid}/servers/${serverId}`; 33 | return this._get(path, params={'expand':expand}); 34 | } 35 | 36 | function getServerAgentActivity(orgUuid, serverId, interval){ 37 | var path = `${orgUuid}/servers/${serverId}/activity/interval`; 38 | return this._get(path, params={'interval':interval}); 39 | } 40 | 41 | function getServerAppTraces(orgUuid, serverId, orphans){ 42 | var path = `${orgUuid}/servers/${serverId}/apptraces`; 43 | return this._get(path, params={'orphans': orphans}); 44 | } 45 | 46 | function getServerAttackStatus(orgUuid, serverId, includeMerged){ 47 | var path = `${orgUuid}/servers/${serverId}/breakdown/attack/status`; 48 | return this._get(path, params={'includeMerged':includeMerged}); 49 | } 50 | 51 | function getServerAttackTypes(orgUuid, serverId, includeMerged){ 52 | var path = `${orgUuid}/servers/${serverId}/breakdown/attack/type`; 53 | return this._get(path, params={'includeMerged': includeMerged}); 54 | } 55 | 56 | function getServerTraceBreakdown(orgUuid, serverId, includeMerged){ 57 | var path = `${orgUuid}/servers/${serverId}/breakdown/trace/rule`; 58 | return this._get(path, params={'includeMerged':includeMerged}); 59 | 60 | } 61 | 62 | function getServerTraceSeverityBreakdown(orgUuid, serverId, includeMerged){ 63 | var path = `${orgUuid}/servers/${serverId}/breakdown/trace/severity`; 64 | return this._get(path, params={'includeMerged':includeMerged}); 65 | } 66 | 67 | function getServerTraceStatusBreakdown(orgUuid, serverId, includeMerged){ 68 | var path = `${orgUuid}/servers/${serverId}/breakdown/trace/status`; 69 | return this._get(path, params={'includeMerged':includeMerged}); 70 | } 71 | 72 | function getServerLibrariesBreakdown(orgUuid, serverId, includeMerged, includeArchived){ 73 | var path = `${orgUuid}/servers/${serverId}/libraries/breakdown`; 74 | return this._get(path, params={'includeMerged': includeMerged, 'includeArchived': includeArchived}); 75 | } 76 | 77 | function updateServerName(orgUuid, serverId, newName){ 78 | var path = `${orgUuid}/servers/${serverId}/name`; 79 | return this._put(path, data={'name': newName}); 80 | } 81 | 82 | function getServerProperties(orgUuid,serverId){ 83 | var path = `${orgUuid}/servers/${serverId}/properties`; 84 | return this._get(path); 85 | } 86 | 87 | function getServerVulnAndAttackUrls(orgUuid, serverId, interval){ 88 | var path = `${orgUuid}/servers/${serverId}/url`; 89 | return this._get(path, params={'interval': interval}); 90 | } 91 | 92 | function getServerVulnUrls(orgUuid, serverId, interval){ 93 | var path = `${orgUuid}/servers/${serverId}/url/vuln`; 94 | return this._get(path, params={'interval':interval}); 95 | } 96 | 97 | function getServerAttackUrls(orgUuid, serverId, interval){ 98 | var path = `${orgUuid}/servers/${serverId}/url/attack`; 99 | return this._get(path, params={'interval':interval}); 100 | } 101 | 102 | function getServerLibraries(orgUuid, serverId, expand, quickFilter){ 103 | var path = `${orgUuid}/servers/${serverId}/libraries`; 104 | return this._get(path, params={'expand': expand, 'quickFilter': quickFilter}); 105 | } 106 | 107 | function getServerLibrariesSubfilters(orgUuid, serverId, filterType){ 108 | var path = `${orgUuid}/servers/${serverId}/libraries/filters/${filterType}/listing`; 109 | return this._get(path); 110 | } 111 | 112 | function getServerLibrariesStats(orgUuid, serverId, includeMerged){ 113 | var path = `${orgUuid}/servers/${serverId}/libraries/stats`; 114 | return this._get(path, params={'includeMerged':includeMerged}); 115 | } 116 | 117 | function filterServerLibraries(orgUuid, serverId, filter){ 118 | var path = `${orgUuid}/servers/${serverId}/libraries/filter`; 119 | return this._get(path, params=filter); 120 | } 121 | 122 | function getServerTraceSubfilters(orgUUid, serverId, traceFilterType){ 123 | var path = `${orgUUid}/servertraces/${serverId}/filter/${traceFilterType}/listing`; 124 | return this._get(path); 125 | } 126 | 127 | function getServerTraceDetails(orgUuid, serverId, traceUuid, expand){ 128 | var path = `${orgUuid}/servertraces/${serverId}/filter/${traceUuid}`; 129 | return this._get(path, params={'expand': expand}); 130 | 131 | } 132 | 133 | function filterServerTraces(orgUuid, serverId, filter){ 134 | var path = `${orgUuid}/servertraces/${serverId}/filter`; 135 | return this._get(path, params=filter); 136 | } 137 | 138 | function deleteServerTraces(orgUuid, serverId, traces){ 139 | var path = `${orgUuid}/servertraces/${serverId}`; 140 | return this._delete(path, data={'traces': traces}); 141 | } 142 | 143 | function getServerVulnerabilityUuids(orgUuid, serverId, filter){ 144 | var path = `${orgUuid}/servertraces/${serverId}/ids`; 145 | return this._get(path, filter); 146 | } 147 | 148 | function getServerPolicyViolations(orgUuid, serverId){ 149 | var path = `${orgUuid}/servertraces/${serverId}/policy/violations`; 150 | return this._get(path); 151 | } 152 | 153 | function deleteServerTrace(orgUuid, serverId, traceUuid){ 154 | var path = `${orgUuid}/servertraces/${serverId}/trace/${traceUuid}`; 155 | return this._delete(path); 156 | } 157 | 158 | function getServerTraceVulnerabilityVisibility(orgUuid, serverId, traceUuid){ 159 | var path = `${orgUuid}/servertraces/${serverId}/${traceUuid}/visible`; 160 | return this._get(path); 161 | } 162 | 163 | 164 | module.exports.getServers = getServers; 165 | module.exports.getActiveServers = getActiveServers; 166 | module.exports.filterServers = filterServers; 167 | module.exports.getServerFilters = getServerFilters; 168 | module.exports.getServerFilterSubfilters = getServerFilterSubfilters; 169 | module.exports.getServerModes = getServerModes; 170 | module.exports.getServerDetails = getServerDetails; 171 | module.exports.getServerAgentActivity = getServerAgentActivity; 172 | module.exports.getServerAppTraces = getServerAppTraces; 173 | module.exports.getServerAttackStatus = getServerAttackStatus; 174 | module.exports.getServerAttackTypes = getServerAttackTypes; 175 | module.exports.getServerTraceBreakdown = getServerTraceBreakdown; 176 | module.exports.getServerTraceSeverityBreakdown = getServerTraceSeverityBreakdown; 177 | module.exports.getServerTraceStatusBreakdown = getServerTraceStatusBreakdown; 178 | module.exports.getServerLibrariesBreakdown = getServerLibrariesBreakdown; 179 | module.exports.updateServerName = updateServerName; 180 | module.exports.getServerProperties = getServerProperties; 181 | module.exports.getServerVulnAndAttackUrls = getServerVulnAndAttackUrls; 182 | module.exports.getServerVulnUrls = getServerVulnUrls; 183 | module.exports.getServerAttackUrls = getServerAttackUrls; 184 | module.exports.getServerLibraries = getServerLibraries; 185 | module.exports.getServerLibrariesSubfilters = getServerLibrariesSubfilters; 186 | module.exports.getServerLibrariesStats = getServerLibrariesStats; 187 | module.exports.filterServerLibraries = filterServerLibraries; 188 | module.exports.getServerTraceSubfilters = getServerTraceSubfilters; 189 | module.exports.getServerTraceDetails = getServerTraceDetails; 190 | module.exports.filterServerTraces = filterServerTraces; 191 | module.exports.deleteServerTraces = deleteServerTraces; 192 | module.exports.getServerVulnerabilityUuids = getServerVulnerabilityUuids; 193 | module.exports.getServerPolicyViolations = getServerPolicyViolations; 194 | module.exports.deleteServerTrace = deleteServerTrace; 195 | module.exports.getServerTraceVulnerabilityVisibility = getServerTraceVulnerabilityVisibility; 196 | -------------------------------------------------------------------------------- /test/serverTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Server API Test', function() { 5 | 6 | it('should get servers', function(done) { 7 | configured.sdk.getServers(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get active servers', function(done) { 14 | configured.sdk.getActiveServers(configured.org).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should filter servers', function(done) { 21 | configured.sdk.filterServers(configured.org).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should get server filters', function(done) { 28 | configured.sdk.getServerFilters(configured.org).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should get server filter subfilters', function(done) { 35 | configured.sdk.getServerFilterSubfilters(configured.org, 'environment').then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should get server modes', function(done) { 42 | configured.sdk.getServerModes(configured.org).then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | it('should get server details', function(done) { 49 | configured.sdk.getServerDetails(configured.org, configured.server).then(function(response){ 50 | assert.equal(true, response.success); 51 | done(); 52 | }); 53 | }); 54 | 55 | it('should get server agent activity', function(done) { 56 | configured.sdk.getServerAgentActivity(configured.org, configured.server).then(function(response){ 57 | assert.equal(true, response.success); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('should get server app traces', function(done) { 63 | configured.sdk.getServerAppTraces(configured.org, configured.server).then(function(response){ 64 | assert.equal(true, response.success); 65 | done(); 66 | }); 67 | }); 68 | 69 | it('should get server attack status', function(done) { 70 | configured.sdk.getServerAttackStatus(configured.org, configured.server).then(function(response){ 71 | assert.equal(true, response.success); 72 | done(); 73 | }); 74 | }); 75 | 76 | it('should get server attack types', function(done) { 77 | configured.sdk.getServerAttackTypes(configured.org, configured.server).then(function(response){ 78 | assert.equal(true, response.success); 79 | done(); 80 | }); 81 | }); 82 | 83 | it('should get server trace breakdown', function(done) { 84 | configured.sdk.getServerTraceBreakdown(configured.org, configured.server).then(function(response){ 85 | assert.equal(true, response.success); 86 | done(); 87 | }); 88 | }); 89 | 90 | it('should get server trace severity breakdown', function(done) { 91 | configured.sdk.getServerTraceSeverityBreakdown(configured.org, configured.server).then(function(response){ 92 | assert.equal(true, response.success); 93 | done(); 94 | }); 95 | }); 96 | 97 | it('should get server trace status breakdown', function(done) { 98 | configured.sdk.getServerTraceStatusBreakdown(configured.org, configured.server).then(function(response){ 99 | assert.equal(true, response.success); 100 | done(); 101 | }); 102 | }); 103 | 104 | it('should get server libraries breakdown', function(done) { 105 | configured.sdk.getServerLibrariesBreakdown(configured.org, configured.server).then(function(response){ 106 | assert.equal(true, response.success); 107 | done(); 108 | }); 109 | }); 110 | 111 | it('should update server name', function(done) { 112 | configured.sdk.updateServerName(configured.org, configured.server,'js-sdk-test').then(function(response){ 113 | assert.equal(true, response.success); 114 | done(); 115 | }); 116 | }); 117 | 118 | it('should get server properties', function(done) { 119 | configured.sdk.getServerProperties(configured.org, configured.server).then(function(response){ 120 | assert.equal(true, response.success); 121 | done(); 122 | }); 123 | }); 124 | 125 | it('should get server vulns and attack urls', function(done) { 126 | configured.sdk.getServerVulnAndAttackUrls(configured.org, configured.server).then(function(response){ 127 | assert.equal(true, response.success); 128 | done(); 129 | }); 130 | }); 131 | 132 | it('should get server vulns urls', function(done) { 133 | configured.sdk.getServerVulnUrls(configured.org, configured.server).then(function(response){ 134 | assert.equal(true, response.success); 135 | done(); 136 | }); 137 | }); 138 | 139 | it('should get server attack urls', function(done) { 140 | configured.sdk.getServerAttackUrls(configured.org, configured.server).then(function(response){ 141 | assert.equal(true, response.success); 142 | done(); 143 | }); 144 | }); 145 | 146 | it('should get server libraries', function(done) { 147 | configured.sdk.getServerLibraries(configured.org, configured.server).then(function(response){ 148 | assert.equal(true, response.success); 149 | done(); 150 | }); 151 | }); 152 | 153 | it('should get server libraries subfilters', function(done) { 154 | configured.sdk.getServerLibrariesSubfilters(configured.org, configured.server,'apps').then(function(response){ 155 | assert.equal(true, response.success); 156 | done(); 157 | }); 158 | }); 159 | 160 | it('should get server libraries stats', function(done) { 161 | configured.sdk.getServerLibrariesStats(configured.org, configured.server).then(function(response){ 162 | assert.equal(true, response.success); 163 | done(); 164 | }); 165 | }); 166 | 167 | it('should filter server libraries', function(done) { 168 | configured.sdk.filterServerLibraries(configured.org, configured.server).then(function(response){ 169 | assert.equal(true, response.success); 170 | done(); 171 | }); 172 | }); 173 | 174 | it('should get server trace subfilters', function(done) { 175 | configured.sdk.getServerTraceSubfilters(configured.org, configured.server,'modules').then(function(response){ 176 | assert.equal(true, response.success); 177 | done(); 178 | }); 179 | }); 180 | 181 | it('should get server trace details', function(done) { 182 | configured.sdk.getServerTraceDetails(configured.org, configured.server, configured.trace).then(function(response){ 183 | assert.equal(true, response.success); 184 | done(); 185 | }); 186 | }); 187 | 188 | it('should filter server traces', function(done) { 189 | configured.sdk.filterServerTraces(configured.org, configured.server).then(function(response){ 190 | assert.equal(true, response.success); 191 | done(); 192 | }); 193 | }); 194 | 195 | it('should get vuln uuids', function(done) { 196 | configured.sdk.getServerVulnerabilityUuids(configured.org, configured.server).then(function(response){ 197 | assert.equal(true, response.success); 198 | done(); 199 | }); 200 | }); 201 | 202 | it('should get server policy violations', function(done) { 203 | configured.sdk.getServerPolicyViolations(configured.org, configured.server).then(function(response){ 204 | assert.equal(true, response.success); 205 | done(); 206 | }); 207 | }); 208 | 209 | it('should get server trace vuln visibility', function(done) { 210 | configured.sdk.getServerTraceVulnerabilityVisibility(configured.org, configured.server, configured.trace).then(function(response){ 211 | assert.equal(true, response.success); 212 | done(); 213 | }); 214 | }); 215 | 216 | 217 | }); 218 | -------------------------------------------------------------------------------- /test/applicationTest.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var configured = require('./setup') 3 | 4 | describe('Application API Test', function() { 5 | 6 | it('should get inactive applications', function(done) { 7 | configured.sdk.getInactiveApplications(configured.org).then(function(response){ 8 | assert.equal(true, response.success); 9 | done(); 10 | }); 11 | }); 12 | 13 | it('should get newest applications', function(done) { 14 | configured.sdk.getNewestApplications(configured.org).then(function(response){ 15 | assert.equal(true, response.success); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get recent applications', function(done) { 21 | configured.sdk.getRecentApplications(configured.org).then(function(response){ 22 | assert.equal(true, response.success); 23 | done(); 24 | }); 25 | }); 26 | 27 | it('should get application components', function(done) { 28 | configured.sdk.getApplicationComponents(configured.org, configured.app).then(function(response){ 29 | assert.equal(true, response.success); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should get application coverage', function(done) { 35 | configured.sdk.getApplicationCoverage(configured.org, configured.app).then(function(response){ 36 | assert.equal(true, response.success); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should get application coverage - week', function(done) { 42 | configured.sdk.getApplicationCoveragePastWeek(configured.org, configured.app).then(function(response){ 43 | assert.equal(true, response.success); 44 | done(); 45 | }); 46 | }); 47 | 48 | it('should get application history', function(done) { 49 | configured.sdk.getApplicationHistory(configured.org, configured.app).then(function(response){ 50 | assert.equal(true, response.success); 51 | done(); 52 | }); 53 | }); 54 | 55 | it('should get application history', function(done) { 56 | configured.sdk.getApplicationHistoryByInterval(configured.org, configured.app, 'DEVELOPMENT', 'WEEK').then(function(response){ 57 | assert.equal(true, response.success); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('should get application libraries', function(done) { 63 | configured.sdk.getApplicationLibraries(configured.org, configured.app).then(function(response){ 64 | assert.equal(true, response.success); 65 | done(); 66 | }); 67 | }); 68 | 69 | it('should get application library subfilters', function(done) { 70 | configured.sdk.getApplicationLibrarySubfilters(configured.org, configured.app, 'tags').then(function(response){ 71 | assert.equal(true, response.success); 72 | done(); 73 | }); 74 | }); 75 | 76 | it('should filter applications', function(done) { 77 | configured.sdk.filterApplications(configured.org).then(function(response){ 78 | assert.equal(true, response.success); 79 | done(); 80 | }); 81 | }); 82 | 83 | it('should get application library stats', function(done) { 84 | configured.sdk.getApplicationLibraryStats(configured.org, configured.app).then(function(response){ 85 | assert.equal(true, response.success); 86 | done(); 87 | }); 88 | }); 89 | 90 | it('should get application status breakdown', function(done) { 91 | configured.sdk.getApplicationStatusBreakdown(configured.org, configured.app).then(function(response){ 92 | assert.equal(true, response.success); 93 | done(); 94 | }); 95 | }); 96 | 97 | it('should get application trace breakdown', function(done) { 98 | configured.sdk.getApplicationTraceBreakdown(configured.org, configured.app).then(function(response){ 99 | assert.equal(true, response.success); 100 | done(); 101 | }); 102 | }); 103 | 104 | it('should get application trace rule breakdown', function(done) { 105 | configured.sdk.getApplicationTraceRuleBreakdown(configured.org, configured.app, 'DEVELOPMENT').then(function(response){ 106 | assert.equal(true, response.success); 107 | done(); 108 | }); 109 | }); 110 | 111 | it('should get application trace severity breakdown', function(done) { 112 | configured.sdk.getApplicationTraceSeverityBreakdown(configured.org, configured.app, 'DEVELOPMENT').then(function(response){ 113 | assert.equal(true, response.success); 114 | done(); 115 | }); 116 | }); 117 | 118 | it('should get application trace status breakdown', function(done) { 119 | configured.sdk.getApplicationTraceStatusBreakdown(configured.org, configured.app, 'DEVELOPMENT').then(function(response){ 120 | assert.equal(true, response.success); 121 | done(); 122 | }); 123 | }); 124 | 125 | it('should get application servers', function(done) { 126 | configured.sdk.getApplicationServers(configured.org, configured.app).then(function(response){ 127 | assert.equal(true, response.success); 128 | done(); 129 | }); 130 | }); 131 | 132 | it('should get application servers breakdown', function(done) { 133 | configured.sdk.getApplicationServersBreakdown(configured.org, configured.app).then(function(response){ 134 | assert.equal(true, response.success); 135 | done(); 136 | }); 137 | }); 138 | 139 | it('should get application servers count', function(done) { 140 | configured.sdk.getApplicationServersCount(configured.org, configured.app).then(function(response){ 141 | assert.equal(true, response.success); 142 | done(); 143 | }); 144 | }); 145 | 146 | it('should get application servers recently active', function(done) { 147 | configured.sdk.getApplicationServersRecentlyActive(configured.org, configured.app).then(function(response){ 148 | assert.equal(true, response.success); 149 | done(); 150 | }); 151 | }); 152 | 153 | it('should get application server properties', function(done) { 154 | configured.sdk.getApplicationServerProperties(configured.org, configured.app).then(function(response){ 155 | assert.equal(true, response.success); 156 | done(); 157 | }); 158 | }); 159 | 160 | it('should get application server settings', function(done) { 161 | configured.sdk.getApplicationServerSettings(configured.org, configured.app).then(function(response){ 162 | assert.equal(true, response.success); 163 | done(); 164 | }); 165 | }); 166 | 167 | it('should get application technologies', function(done) { 168 | configured.sdk.getApplicationTechnologies(configured.org, configured.app).then(function(response){ 169 | assert.equal(true, response.success); 170 | done(); 171 | }); 172 | }); 173 | 174 | it('should get technologies', function(done) { 175 | configured.sdk.getTechnologies(configured.org).then(function(response){ 176 | assert.equal(true, response.success); 177 | done(); 178 | }); 179 | }); 180 | 181 | it('should get total allowed apps', function(done) { 182 | configured.sdk.getTotalAllowedApplications(configured.org).then(function(response){ 183 | assert.equal(true, response.success); 184 | done(); 185 | }); 186 | }); 187 | 188 | it('should filter apps', function(done) { 189 | configured.sdk.filterApplications(configured.org).then(function(response){ 190 | assert.equal(true, response.success); 191 | done(); 192 | }); 193 | }); 194 | 195 | it('should get app filters', function(done) { 196 | configured.sdk.getApplicationFilters(configured.org).then(function(response){ 197 | assert.equal(true, response.success); 198 | done(); 199 | }); 200 | }); 201 | 202 | it('should get application', function(done) { 203 | configured.sdk.getApplication(configured.org, configured.app).then(function(response){ 204 | assert.equal(true, response.success); 205 | done(); 206 | }); 207 | }); 208 | 209 | it('should update app importance', function(done) { 210 | configured.sdk.updateApplicationImportance(configured.org, configured.app,1).then(function(response){ 211 | assert.equal(true, response.success); 212 | done(); 213 | }); 214 | }); 215 | 216 | it('should get app license details', function(done) { 217 | configured.sdk.getApplicationLicenseDetails(configured.org, configured.app).then(function(response){ 218 | assert.equal(true, response.success); 219 | done(); 220 | }); 221 | }); 222 | 223 | it('should filter app traces', function(done) { 224 | configured.sdk.filterApplicationTraces(configured.org, configured.app).then(function(response){ 225 | assert.equal(true, response.success); 226 | done(); 227 | }); 228 | }); 229 | 230 | it('should get application vuln details', function(done) { 231 | configured.sdk.getApplicationVulnDetails(configured.org, configured.app, configured.trace).then(function(response){ 232 | assert.equal(true, response.success); 233 | done(); 234 | }); 235 | }); 236 | 237 | it('should get application trace ids', function(done) { 238 | configured.sdk.getApplicationTraceUuids(configured.org, configured.app).then(function(response){ 239 | assert.equal(true, response.success); 240 | done(); 241 | }); 242 | }); 243 | 244 | it('should get application policy violations', function(done) { 245 | configured.sdk.getApplicationTracesWithPolicyViolations(configured.org, configured.app, 'DEVELOPMENT').then(function(response){ 246 | assert.equal(true, response.success); 247 | done(); 248 | }); 249 | }); 250 | 251 | it('should get application trace details', function(done) { 252 | configured.sdk.getApplicationTraceDetails(configured.org, configured.app, configured.trace).then(function(response){ 253 | assert.equal(true, response.success); 254 | done(); 255 | }); 256 | }); 257 | 258 | it('should get application trace reqs', function(done) { 259 | configured.sdk.getApplicationTraceRequirements(configured.org, configured.app, configured.trace).then(function(response){ 260 | assert.equal(true, response.success); 261 | done(); 262 | }); 263 | }); 264 | 265 | it('should get application trace servers', function(done) { 266 | configured.sdk.getApplicationTraceServers(configured.org, configured.app, configured.trace).then(function(response){ 267 | assert.equal(true, response.success); 268 | done(); 269 | }); 270 | }); 271 | 272 | it('should get application trace visibility', function(done) { 273 | configured.sdk.getApplicationTraceVisibility(configured.org, configured.app, configured.trace).then(function(response){ 274 | assert.equal(true, response.success); 275 | done(); 276 | }); 277 | }); 278 | 279 | }); 280 | -------------------------------------------------------------------------------- /api/application.js: -------------------------------------------------------------------------------- 1 | function getInactiveApplications(orgUuid, expand, includeArchived, includeMerged, limit){ 2 | var path = `${orgUuid}/applications/activity/inactive`; 3 | return this._get(path, {'expand': expand, 'includeArchived': includeArchived, 'includeMerged': includeMerged, 'limit': limit}); 4 | } 5 | 6 | function getNewestApplications(orgUuid, expand, includeArchived, includeMerged, limit){ 7 | var path = `${orgUuid}/applications/activity/newest`; 8 | return this._get(path, {'expand': expand, 'includeArchived': includeArchived, 'includeMerged': includeMerged, 'limit': limit}); 9 | } 10 | 11 | function getRecentApplications(orgUuid, expand, includeArchived, includeMerged, limit){ 12 | var path = `${orgUuid}/applications/activity/recent`; 13 | return this._get(path, {'expand': expand, 'includeArchived': includeArchived, 'includeMerged': includeMerged, 'limit': limit}); 14 | } 15 | 16 | function getApplicationComponents(orgUuid, appId){ 17 | var path = `${orgUuid}/applications/${appId}/components`; 18 | return this._get(path); 19 | } 20 | 21 | function getApplicationCoverage(orgUuid, appId, includeMerged, limit){ 22 | var path = `${orgUuid}/applications/${appId}/coverage`; 23 | return this._get(path, {'includeMerged': includeMerged, 'limit': limit}); 24 | } 25 | 26 | function getApplicationCoveragePastWeek(orgUuid, appId, includeMerged, limit){ 27 | var path = `${orgUuid}/applications/${appId}/coverage/stats/week`; 28 | return this._get(path, {'includeMerged': includeMerged, 'limit': limit}); 29 | } 30 | 31 | function getApplicationHistory(orgUuid, appId, includeMerged){ 32 | var path = `${orgUuid}/applications/${appId}/history`; 33 | return this._get(path, {'includeMerged': includeMerged}); 34 | } 35 | 36 | function getApplicationHistoryByInterval(orgUuid, appId, environment, interval, includeDefense){ 37 | var defense = includeDefense ? '/defense' : ''; 38 | var path = `${orgUuid}/applications/${appId}/history/interval${defense}`; 39 | return this._get(path, {'environment': environment, 'interval': interval}); 40 | } 41 | 42 | function getApplicationLibraries(orgUuid, appId, expand, loadCVE, quickFilter){ 43 | var path = `${orgUuid}/applications/${appId}/libraries`; 44 | return this._get(path, {'expand': expand, 'loadCVE': loadCVE, 'quickFilter': quickFilter}); 45 | } 46 | 47 | function filterApplicationLibraries(orgUuid, appId, filter){ 48 | var path = `${orgUuid}/applications/${appId}/libraries/filter`; 49 | return this._get(path, filter); 50 | } 51 | 52 | function getApplicationLibrarySubfilters(orgUuid, appId, filterType){ 53 | var path = `${orgUuid}/applications/${appId}/libraries/filters/${filterType}/listing`; 54 | return this._get(path); 55 | } 56 | 57 | function getApplicationLibraryStats(orgUuid, appId, includeMerged){ 58 | var path = `${orgUuid}/applications/${appId}/libraries/stats`; 59 | return this._get(path, {'includeMerged': includeMerged}); 60 | } 61 | 62 | function getApplicationStatusBreakdown(orgUuid, appId, includeMerged){ 63 | var path = `${orgUuid}/applications/${appId}/breakdown/status`; 64 | return this._get(path, {'includeMerged': includeMerged}); 65 | } 66 | 67 | function getApplicationTraceBreakdown(orgUuid, appId, includeMerged){ 68 | var path = `${orgUuid}/applications/${appId}/breakdown/trace`; 69 | return this._get(path, {'includeMerged': includeMerged}); 70 | } 71 | 72 | function getApplicationTraceRuleBreakdown(orgUuid, appId, environment){ 73 | var path =`${orgUuid}/applications/${appId}/breakdown/trace/rule`; 74 | return this._get(path, {'environment': environment}); 75 | } 76 | 77 | function getApplicationTraceSeverityBreakdown(orgUuid, appId, environment){ 78 | var path = `${orgUuid}/applications/${appId}/breakdown/status`; 79 | return this._get(path, {'environment': environment}); 80 | } 81 | 82 | function getApplicationTraceStatusBreakdown(orgUuid, appId, environment){ 83 | var path = `${orgUuid}/applications/${appId}/breakdown/trace/status`; 84 | return this._get(path, {'environment': environment}); 85 | } 86 | 87 | function getApplicationServers(orgUuid, appId, expand, includeMerged, onlyLicensed){ 88 | var path = `${orgUuid}/applications/${appId}/servers`; 89 | return this._get(path, {'expand':expand, 'includeMerged': includeMerged, 'onlyLicensed': onlyLicensed}); 90 | } 91 | 92 | function getApplicationServersBreakdown(orgUuid, appId){ 93 | var path = `${orgUuid}/applications/${appId}/servers/breakdown`; 94 | return this._get(path); 95 | } 96 | 97 | function getApplicationServersCount(orgUuid, appId, includeMerged){ 98 | var path = `${orgUuid}/applications/${appId}/servers/count`; 99 | return this._get(path, {'includeMerged':includeMerged}); 100 | } 101 | 102 | function getApplicationServersRecentlyActive(orgUuid, appId, expand, includeMerged){ 103 | var path = `${orgUuid}/applications/${appId}/servers/newest`; 104 | return this._get(path, {'expand': expand, 'includeMerged':includeMerged}); 105 | } 106 | 107 | function getApplicationServerProperties(orgUuid, appId, includeMerged){ 108 | var path = `${orgUuid}/applications/${appId}/servers/properties`; 109 | return this._get(path, {'includeMerged': includeMerged}); 110 | } 111 | 112 | function getApplicationServerSettings(orgUuid, appId, includeMerged, filterEnvironment){ 113 | var envString = filterEnvironment ? '/environment' : ''; 114 | var path = `${orgUuid}/applications/${appId}/servers/settings${envString}`; 115 | return this._get(path); 116 | } 117 | 118 | function getApplicationTechnologies(orgUuid, appId){ 119 | var path = `${orgUuid}/applications/${appId}/techs`; 120 | return this._get(path); 121 | } 122 | 123 | function getTechnologies(orgUuid){ 124 | var path = `${orgUuid}/techs`; 125 | return this._get(path); 126 | } 127 | 128 | function getTotalAllowedApplications(orgUuid){ 129 | var path = `${orgUuid}/applications/allowed`; 130 | return this._get(path); 131 | } 132 | 133 | function filterApplications(orgUuid, filter){ 134 | var path = `${orgUuid}/applications/filter`; 135 | return this._get(path, filter); 136 | } 137 | 138 | function getApplicationFilters(orgUuid){ 139 | var path = `${orgUuid}/applications/filters/listing`; 140 | return this._get(path); 141 | } 142 | 143 | function getApplication(orgUuid, appId, expand, includeMerged){ 144 | var path = `${orgUuid}/applications/${appId}`; 145 | return this._get(path, {'expand': expand, 'includeMerged': includeMerged}); 146 | } 147 | 148 | function updateApplicationImportance(orgUuid, appId, importance){ 149 | var path = `${orgUuid}/applications/${appId}/importance`; 150 | return this._put(path, {'importance': importance}); 151 | } 152 | 153 | function getApplicationLicenseDetails(orgUuid, appId){ 154 | var path = `${orgUuid}/applications/${appId}/license`; 155 | return this._get(path); 156 | } 157 | 158 | function filterApplicationTraces(orgUuid, appId, filter){ 159 | var path = `${orgUuid}/traces/${appId}/filter`; 160 | return this._get(path, filter); 161 | } 162 | 163 | function getApplicationVulnDetails(orgUuid, appId, traceId, expand){ 164 | var path = `${orgUuid}/traces/${appId}/filter/${traceId}`; 165 | return this._get(path, {'expand': expand}); 166 | } 167 | 168 | function getApplicationTraceUuids(orgUuid, appId, filter){ 169 | var path = `${orgUuid}/traces/${appId}/ids`; 170 | return this._get(path, filter); 171 | } 172 | 173 | function getApplicationTracesWithPolicyViolations(orgUuid, appId, environment){//'DEVELOPMENT' 174 | var path = `${orgUuid}/traces/${appId}/policy/violations`; 175 | return this._get(path, {'environment': environment}); 176 | } 177 | 178 | function deleteApplicationTrace(orgUuid, appId, traceId){ 179 | var path = `${orgUuid}/traces/${appId}/trace/${traceId}`; 180 | return this._delete(path); 181 | } 182 | 183 | function deleteApplicationTraces(orgUuid, appId, traceArray){ 184 | var path = `${orgUuid}/traces/${appId}`; 185 | return this._delete(path, {'traces': traceArray}) 186 | } 187 | 188 | function getApplicationTraceDetails(orgUuid, appId, traceId, expand){ 189 | var path = `${orgUuid}/traces/${appId}/trace/${traceId}`; 190 | return this._get(path, {'expand': expand}); 191 | } 192 | 193 | function getApplicationTraceRequirements(orgUuid, appId, traceId, expand){ 194 | var path = `${orgUuid}/traces/${appId}/trace/${traceId}/requirements`; 195 | return this._get(path, {'expand': expand}); 196 | } 197 | 198 | function getApplicationTraceServers(orgUuid, appId, traceId, expand){ 199 | var path = `${orgUuid}/traces/${appId}/trace/${traceId}/servers`; 200 | return this._get(path, {'expand': expand}); 201 | } 202 | 203 | function getApplicationTraceVisibility(orgUuid, appId, traceId){ 204 | var path = `${orgUuid}/traces/${appId}/${traceId}/visible`; 205 | return this._get(path); 206 | } 207 | 208 | module.exports.getInactiveApplications = getInactiveApplications; 209 | module.exports.getNewestApplications = getNewestApplications; 210 | module.exports.getRecentApplications = getRecentApplications; 211 | module.exports.getApplicationComponents = getApplicationComponents; 212 | module.exports.getApplicationCoverage = getApplicationCoverage; 213 | module.exports.getApplicationCoveragePastWeek = getApplicationCoveragePastWeek; 214 | module.exports.getApplicationHistory = getApplicationHistory; 215 | module.exports.getApplicationHistoryByInterval = getApplicationHistoryByInterval; 216 | module.exports.getApplicationLibraries = getApplicationLibraries; 217 | module.exports.getApplicationLibrarySubfilters = getApplicationLibrarySubfilters; 218 | module.exports.getApplicationLibraries = getApplicationLibraries; 219 | module.exports.filterApplicationLibraries = filterApplicationLibraries; 220 | module.exports.getApplicationLibrarySubfilters = getApplicationLibrarySubfilters; 221 | module.exports.getApplicationLibraryStats = getApplicationLibraryStats; 222 | module.exports.getApplicationStatusBreakdown = getApplicationStatusBreakdown; 223 | module.exports.getApplicationTraceBreakdown = getApplicationTraceBreakdown; 224 | module.exports.getApplicationTraceBreakdown = getApplicationTraceBreakdown; 225 | module.exports.getApplicationTraceRuleBreakdown = getApplicationTraceRuleBreakdown; 226 | module.exports.getApplicationTraceSeverityBreakdown = getApplicationTraceSeverityBreakdown; 227 | module.exports.getApplicationTraceStatusBreakdown = getApplicationTraceStatusBreakdown; 228 | module.exports.getApplicationServers = getApplicationServers; 229 | module.exports.getApplicationServersBreakdown = getApplicationServersBreakdown; 230 | module.exports.getApplicationServersCount = getApplicationServersCount; 231 | module.exports.getApplicationServersRecentlyActive = getApplicationServersRecentlyActive; 232 | module.exports.getApplicationServerProperties = getApplicationServerProperties; 233 | module.exports.getApplicationServerSettings = getApplicationServerSettings; 234 | module.exports.getApplicationTechnologies = getApplicationTechnologies; 235 | module.exports.getTechnologies = getTechnologies; 236 | module.exports.getTotalAllowedApplications = getTotalAllowedApplications; 237 | module.exports.filterApplications = filterApplications; 238 | module.exports.getApplicationFilters = getApplicationFilters; 239 | module.exports.getApplication = getApplication; 240 | module.exports.updateApplicationImportance = updateApplicationImportance; 241 | module.exports.getApplicationLicenseDetails = getApplicationLicenseDetails; 242 | module.exports.filterApplicationTraces = filterApplicationTraces; 243 | module.exports.getApplicationVulnDetails = getApplicationVulnDetails; 244 | module.exports.getApplicationTraceUuids = getApplicationTraceUuids; 245 | module.exports.getApplicationTracesWithPolicyViolations = getApplicationTracesWithPolicyViolations; 246 | module.exports.deleteApplicationTraces = deleteApplicationTraces; 247 | module.exports.getApplicationTraceDetails = getApplicationTraceDetails; 248 | module.exports.getApplicationTraceRequirements = getApplicationTraceRequirements; 249 | module.exports.getApplicationTraceServers = getApplicationTraceServers; 250 | module.exports.getApplicationTraceVisibility = getApplicationTraceVisibility; 251 | --------------------------------------------------------------------------------