Skip to content

Commit 981ce19

Browse files
authored
Merge pull request #244 from OpenPathfinder/ulises/v1-check-list
2 parents 5e7e681 + 7bb1e80 commit 981ce19

File tree

4 files changed

+124
-4
lines changed

4 files changed

+124
-4
lines changed

__tests__/httpServer/apiV1.test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ let knex
3636
let getAllProjects
3737
let addProject
3838
let getAllGithubOrganizationsByProjectsId
39+
let getAllChecks
3940

4041
beforeAll(async () => {
4142
// Initialize server asynchronously
@@ -47,7 +48,8 @@ beforeAll(async () => {
4748
({
4849
getAllProjects,
4950
addProject,
50-
getAllGithubOrganizationsByProjectsId
51+
getAllGithubOrganizationsByProjectsId,
52+
getAllChecks
5153
} = initializeStore(knex))
5254
})
5355

@@ -387,4 +389,17 @@ describe('HTTP Server API V1', () => {
387389

388390
test.todo('should return 500 for internal server error')
389391
})
392+
393+
describe('GET /api/v1/check', () => {
394+
test('should return 200 and a list of checks', async () => {
395+
const response = await app.get('/api/v1/check')
396+
const storedChecks = await getAllChecks()
397+
398+
expect(response.status).toBe(200)
399+
// @TODO: find a more elegant way to solve the issue with the date format
400+
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedChecks)))
401+
})
402+
403+
test.todo('should return 500 for internal server error')
404+
})
390405
})

src/httpServer/routers/apiV1.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const runWorkflow = ({ workflowName, knex, data } = {}) => new Promise((resolve,
2727
})
2828

2929
function createApiRouter (knex, express) {
30-
const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId } = initializeStore(knex)
30+
const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId, getAllChecks } = initializeStore(knex)
3131

3232
const router = express.Router()
3333

@@ -121,6 +121,16 @@ function createApiRouter (knex, express) {
121121
}
122122
})
123123

124+
router.get('/check', async (req, res) => {
125+
try {
126+
const checks = await getAllChecks()
127+
res.json(checks)
128+
} catch (error) {
129+
logger.error(error)
130+
res.status(500).json({ errors: [{ message: 'Failed to retrieve checks' }] })
131+
}
132+
})
133+
124134
router.get('/workflow', (req, res) => {
125135
try {
126136
const { workflowsList } = getWorkflowsDetails()

src/httpServer/swagger/api-v1.yml

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,28 @@ paths:
211211
application/json:
212212
schema:
213213
$ref: '#/components/schemas/ErrorResponse'
214-
214+
/api/v1/check:
215+
get:
216+
summary: List all checks
217+
description: Returns a list of all checks
218+
operationId: listChecks
219+
tags:
220+
- Checks
221+
responses:
222+
'200':
223+
description: A list of checks
224+
content:
225+
application/json:
226+
schema:
227+
type: array
228+
items:
229+
$ref: '#/components/schemas/Check'
230+
'500':
231+
description: Internal server error
232+
content:
233+
application/json:
234+
schema:
235+
$ref: '#/components/schemas/ErrorResponse'
215236
/api/v1/project:
216237
post:
217238
summary: Create a new project
@@ -266,6 +287,79 @@ paths:
266287

267288
components:
268289
schemas:
290+
Check:
291+
type: object
292+
additionalProperties: false
293+
properties:
294+
id:
295+
type: integer
296+
example: 53
297+
title:
298+
type: string
299+
maxLength: 255
300+
example: "Refresh dependencies with annual releases"
301+
description:
302+
type: string
303+
example: "Ensure dependencies are refreshed through a new release at least once annually"
304+
default_section_number:
305+
type: string
306+
maxLength: 255
307+
example: "5"
308+
default_section_name:
309+
type: string
310+
maxLength: 255
311+
example: "vulnerability management"
312+
code_name:
313+
type: string
314+
maxLength: 255
315+
example: "annualDependencyRefresh"
316+
default_priority_group:
317+
type: string
318+
enum: ["P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P11", "P12", "P13", "P14", "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12", "R13", "R14"]
319+
example: "P14"
320+
is_c_scrm:
321+
type: boolean
322+
default: false
323+
example: true
324+
implementation_status:
325+
type: string
326+
enum: ["pending", "completed"]
327+
default: "pending"
328+
example: "completed"
329+
# @TODO: Convert to enum when nullable values are removed
330+
implementation_type:
331+
type: string
332+
nullable: true
333+
example: "manual"
334+
implementation_details_reference:
335+
type: string
336+
nullable: true
337+
example: "https://github.com/OpenPathfinder/visionBoard/issues/112"
338+
details_url:
339+
type: string
340+
example: "https://openpathfinder.com/docs/checks/annualDependencyRefresh"
341+
created_at:
342+
type: string
343+
format: date-time
344+
example: "2025-02-21T18:53:00.485Z"
345+
updated_at:
346+
type: string
347+
format: date-time
348+
example: "2025-02-21T18:53:00.485Z"
349+
required:
350+
- id
351+
- title
352+
- description
353+
- default_section_number
354+
- default_section_name
355+
- code_name
356+
- default_priority_group
357+
- is_c_scrm
358+
- implementation_status
359+
- details_url
360+
- created_at
361+
- updated_at
362+
269363
GithubOrganization:
270364
type: object
271365
additionalProperties: false

src/store/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ const initializeStore = (knex) => {
248248
upsertOwaspTop10Training: upsertOwaspTop10Training(knex),
249249
getAllOSSFResults: () => getAll('ossf_scorecard_results'),
250250
getProjectById: (id) => getOne('projects', id),
251-
getProjectByName: getProjectByName(knex)
251+
getProjectByName: getProjectByName(knex),
252+
getAllChecks: () => getAll('compliance_checks')
252253
}
253254
}
254255

0 commit comments

Comments
 (0)