-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into AL-SQS-Local
- Loading branch information
Showing
28 changed files
with
1,056 additions
and
924 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ProductInfo, connectToDatabase } from '../models'; | ||
import { wrapHandler, NotFound } from './helpers'; | ||
|
||
// TODO: Join cves to cpe get method | ||
// TODO: Create CpeFilters and CpeSearch classes to handle filtering and pagination of additional fields | ||
|
||
/** | ||
* @swagger | ||
* /cpes/{id}: | ||
* get: | ||
* description: Retrieve a CPE by ID | ||
* tags: | ||
* - CPEs | ||
* parameters: | ||
* - in: path | ||
* name: id | ||
* required: true | ||
* schema: | ||
* type: string | ||
*/ | ||
export const get = wrapHandler(async (event) => { | ||
const connection = await connectToDatabase(); | ||
const repository = connection.getRepository(ProductInfo); | ||
|
||
const id = event.pathParameters?.id; | ||
if (!id) { | ||
return NotFound; | ||
} | ||
|
||
const productInfo = await repository.findOne(id); | ||
if (!productInfo) { | ||
return NotFound; | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(productInfo) | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Cve, connectToDatabase } from '../models'; | ||
import { wrapHandler } from './helpers'; | ||
|
||
// TODO: Add test for joining product_info | ||
// TODO: Create CveFilters and CveSearch classes to handle filtering and pagination of additional fields | ||
|
||
/** | ||
* @swagger | ||
* /cves/{cve_uid}: | ||
* get: | ||
* description: Retrieve a CVE by ID. | ||
* tags: | ||
* - CVEs | ||
* parameters: | ||
* - in: path | ||
* name: cve_uid | ||
* required: true | ||
* schema: | ||
* type: string | ||
*/ | ||
export const get = wrapHandler(async (event) => { | ||
await connectToDatabase(); | ||
const cve_uid = event.pathParameters?.cve_uid; | ||
|
||
const cve = await Cve.createQueryBuilder('cve') | ||
.leftJoinAndSelect('cve.product_info', 'product_info') | ||
.where('cve.cve_uid = :cve_uid', { cve_uid: cve_uid }) | ||
.getOne(); | ||
|
||
if (!cve) { | ||
return { | ||
statusCode: 404, | ||
body: JSON.stringify(Error) | ||
}; | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(cve) | ||
}; | ||
}); | ||
|
||
//TODO: Remove getByName endpoint once a one-to-one relationship is established between vulnerability.cve and cve.cve_id | ||
/** | ||
* @swagger | ||
* | ||
* /cves/name/{cve_name}: | ||
* get: | ||
* description: Retrieve a single CVE record by its name. | ||
* tags: | ||
* - CVE | ||
* parameters: | ||
* - name: cve_name | ||
* in: path | ||
* required: true | ||
* schema: | ||
* type: string | ||
*/ | ||
export const getByName = wrapHandler(async (event) => { | ||
await connectToDatabase(); | ||
const cve_name = event.pathParameters?.cve_name; | ||
|
||
const cve = await Cve.createQueryBuilder('cve') | ||
.leftJoinAndSelect('cve.product_info', 'product_info') | ||
.where('cve.cve_name = :cve_name', { cve_name }) | ||
.getOne(); | ||
|
||
if (!cve) { | ||
return { | ||
statusCode: 404, | ||
body: JSON.stringify(Error) | ||
}; | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(cve) | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as request from 'supertest'; | ||
import app from '../src/api/app'; | ||
import { Organization, ProductInfo, connectToDatabase } from '../src/models'; | ||
import { createUserToken } from './util'; | ||
|
||
describe('cpes', () => { | ||
let connection; | ||
let organization: Organization; | ||
let productInfo: ProductInfo; | ||
beforeAll(async () => { | ||
connection = await connectToDatabase(); | ||
productInfo = ProductInfo.create({ | ||
last_seen: new Date(), | ||
cpe_product_name: 'Test Product', | ||
version_number: '1.0.0', | ||
vender: 'Test Vender' | ||
}); | ||
await productInfo.save(); | ||
organization = Organization.create({ | ||
name: 'test-' + Math.random(), | ||
rootDomains: ['test-' + Math.random()], | ||
ipBlocks: [], | ||
isPassive: false | ||
}); | ||
await organization.save(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await ProductInfo.delete(productInfo.id); | ||
await connection.close(); | ||
}); | ||
|
||
describe('CPE API', () => { | ||
it('should return a single CPE by id', async () => { | ||
const response = await request(app) | ||
.get(`/cpes/${productInfo.id}`) | ||
.set( | ||
'Authorization', | ||
createUserToken({ | ||
roles: [{ org: organization.id, role: 'user' }] | ||
}) | ||
) | ||
.send({}) | ||
.expect(200); | ||
expect(response.body.id).toEqual(productInfo.id); | ||
expect(response.body.cpe_product_name).toEqual( | ||
productInfo.cpe_product_name | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as request from 'supertest'; | ||
import app from '../src/api/app'; | ||
import { Cve, Organization, connectToDatabase } from '../src/models'; | ||
import { createUserToken } from './util'; | ||
|
||
// TODO: Add test for joining product_info | ||
describe('cves', () => { | ||
let connection; | ||
let cve: Cve; | ||
let organization: Organization; | ||
beforeAll(async () => { | ||
connection = await connectToDatabase(); | ||
cve = Cve.create({ | ||
cve_name: 'CVE-0001-0001' | ||
}); | ||
await cve.save(); | ||
organization = Organization.create({ | ||
name: 'test-' + Math.random(), | ||
rootDomains: ['test-' + Math.random()], | ||
ipBlocks: [], | ||
isPassive: false | ||
}); | ||
await organization.save(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await Cve.delete(cve.cve_uid); | ||
await Organization.delete(organization.id); | ||
await connection.close(); | ||
}); | ||
describe('CVE API', () => { | ||
it('should return a single CVE by cve_name', async () => { | ||
const response = await request(app) | ||
.get(`/cves/name/${cve.cve_name}`) | ||
.set( | ||
'Authorization', | ||
createUserToken({ | ||
roles: [{ org: organization.id, role: 'user' }] | ||
}) | ||
) | ||
.send({}) | ||
.expect(200); | ||
expect(response.body.cve_uid).toEqual(cve.cve_uid); | ||
expect(response.body.cve_name).toEqual(cve.cve_name); | ||
}); | ||
}); | ||
describe('CVE API', () => { | ||
it('should return a single CVE by cve_uid', async () => { | ||
const response = await request(app) | ||
.get(`/cves/${cve.cve_uid}`) | ||
.set( | ||
'Authorization', | ||
createUserToken({ | ||
roles: [{ org: organization.id, role: 'user' }] | ||
}) | ||
) | ||
.send({}) | ||
.expect(200); | ||
expect(response.body.cve_uid).toEqual(cve.cve_uid); | ||
expect(response.body.cve_name).toEqual(cve.cve_name); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.