Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion __tests__/httpServer/apiV1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ let knex
let getAllProjects
let addProject
let getAllGithubOrganizationsByProjectsId
let getAllChecks

beforeAll(async () => {
// Initialize server asynchronously
Expand All @@ -47,7 +48,8 @@ beforeAll(async () => {
({
getAllProjects,
addProject,
getAllGithubOrganizationsByProjectsId
getAllGithubOrganizationsByProjectsId,
getAllChecks
} = initializeStore(knex))
})

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

test.todo('should return 500 for internal server error')
})

describe('GET /api/v1/check', () => {
test('should return 200 and a list of checks', async () => {
const response = await app.get('/api/v1/check')
const storedChecks = await getAllChecks()

expect(response.status).toBe(200)
// @TODO: find a more elegant way to solve the issue with the date format
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedChecks)))
})

test.todo('should return 500 for internal server error')
})
})
12 changes: 11 additions & 1 deletion src/httpServer/routers/apiV1.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const runWorkflow = ({ workflowName, knex, data } = {}) => new Promise((resolve,
})

function createApiRouter (knex, express) {
const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId } = initializeStore(knex)
const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId, getAllChecks } = initializeStore(knex)

const router = express.Router()

Expand Down Expand Up @@ -121,6 +121,16 @@ function createApiRouter (knex, express) {
}
})

router.get('/check', async (req, res) => {
try {
const checks = await getAllChecks()
res.json(checks)
} catch (error) {
logger.error(error)
res.status(500).json({ errors: [{ message: 'Failed to retrieve checks' }] })
}
})

router.get('/workflow', (req, res) => {
try {
const { workflowsList } = getWorkflowsDetails()
Expand Down
96 changes: 95 additions & 1 deletion src/httpServer/swagger/api-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,28 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

/api/v1/check:
get:
summary: List all checks
description: Returns a list of all checks
operationId: listChecks
tags:
- Checks
responses:
'200':
description: A list of checks
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Check'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/v1/project:
post:
summary: Create a new project
Expand Down Expand Up @@ -266,6 +287,79 @@ paths:

components:
schemas:
Check:
type: object
additionalProperties: false
properties:
id:
type: integer
example: 53
title:
type: string
maxLength: 255
example: "Refresh dependencies with annual releases"
description:
type: string
example: "Ensure dependencies are refreshed through a new release at least once annually"
default_section_number:
type: string
maxLength: 255
example: "5"
default_section_name:
type: string
maxLength: 255
example: "vulnerability management"
code_name:
type: string
maxLength: 255
example: "annualDependencyRefresh"
default_priority_group:
type: string
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"]
example: "P14"
is_c_scrm:
type: boolean
default: false
example: true
implementation_status:
type: string
enum: ["pending", "completed"]
default: "pending"
example: "completed"
# @TODO: Convert to enum when nullable values are removed
implementation_type:
type: string
nullable: true
example: "manual"
implementation_details_reference:
type: string
nullable: true
example: "https://github.com/OpenPathfinder/visionBoard/issues/112"
details_url:
type: string
example: "https://openpathfinder.com/docs/checks/annualDependencyRefresh"
created_at:
type: string
format: date-time
example: "2025-02-21T18:53:00.485Z"
updated_at:
type: string
format: date-time
example: "2025-02-21T18:53:00.485Z"
required:
- id
- title
- description
- default_section_number
- default_section_name
- code_name
- default_priority_group
- is_c_scrm
- implementation_status
- details_url
- created_at
- updated_at

GithubOrganization:
type: object
additionalProperties: false
Expand Down
3 changes: 2 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ const initializeStore = (knex) => {
upsertOwaspTop10Training: upsertOwaspTop10Training(knex),
getAllOSSFResults: () => getAll('ossf_scorecard_results'),
getProjectById: (id) => getOne('projects', id),
getProjectByName: getProjectByName(knex)
getProjectByName: getProjectByName(knex),
getAllChecks: () => getAll('compliance_checks')
}
}

Expand Down
Loading