From fb7996ce96660c5857bf8e0c28d273dc6df14607 Mon Sep 17 00:00:00 2001 From: Ulises Gascon Date: Fri, 3 Jan 2025 17:02:38 +0100 Subject: [PATCH] fix: revert boolean logic to match validation criteria --- __tests__/checks/adminRepoCreationOnly.test.js | 6 +++--- __tests__/checks/validators.test.js | 8 ++++---- src/checks/validators/adminRepoCreationOnly.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/__tests__/checks/adminRepoCreationOnly.test.js b/__tests__/checks/adminRepoCreationOnly.test.js index 1af2bd4..a3a340d 100644 --- a/__tests__/checks/adminRepoCreationOnly.test.js +++ b/__tests__/checks/adminRepoCreationOnly.test.js @@ -54,7 +54,7 @@ describe('Integration: adminRepoCreationOnly', () => { login: sampleGithubOrg.login, html_url: sampleGithubOrg.html_url, project_id: project.id, - members_can_create_public_repositories: true + members_can_create_public_repositories: false }) // Check that the database is empty let results = await getAllResults() @@ -82,7 +82,7 @@ describe('Integration: adminRepoCreationOnly', () => { login: sampleGithubOrg.login, html_url: sampleGithubOrg.html_url, project_id: project.id, - members_can_create_public_repositories: true + members_can_create_public_repositories: false }) await addAlert({ compliance_check_id: check.id, project_id: project.id, title: 'existing', description: 'existing', severity: 'critical' }) await addTask({ compliance_check_id: check.id, project_id: project.id, title: 'existing', description: 'existing', severity: 'critical' }) @@ -108,7 +108,7 @@ describe('Integration: adminRepoCreationOnly', () => { }) test('Should add (alerts and tasks) and update results', async () => { // Prepare the Scenario - await addGithubOrg({ login: sampleGithubOrg.login, html_url: sampleGithubOrg.html_url, project_id: project.id, members_can_create_public_repositories: false }) + await addGithubOrg({ login: sampleGithubOrg.login, html_url: sampleGithubOrg.html_url, project_id: project.id, members_can_create_public_repositories: true }) await addResult({ compliance_check_id: check.id, project_id: project.id, status: 'passed', rationale: 'failed previously', severity: 'critical' }) // Check that the database has the expected results let results = await getAllResults() diff --git a/__tests__/checks/validators.test.js b/__tests__/checks/validators.test.js index ae4a306..e52ba7d 100644 --- a/__tests__/checks/validators.test.js +++ b/__tests__/checks/validators.test.js @@ -286,17 +286,17 @@ describe('adminRepoCreationOnly', () => { { project_id: 1, login: 'org1', - members_can_create_public_repositories: true + members_can_create_public_repositories: false }, { project_id: 1, login: 'org2', - members_can_create_public_repositories: true + members_can_create_public_repositories: false }, { project_id: 2, login: 'org3', - members_can_create_public_repositories: true + members_can_create_public_repositories: false } ] @@ -340,7 +340,7 @@ describe('adminRepoCreationOnly', () => { }) it('should generate a failed result if some organizations have mixed permissions', () => { - organizations[0].members_can_create_public_repositories = false + organizations[0].members_can_create_public_repositories = true // IMPORTANT: If one organization fails, the whole project fails no matter how other organizations are in the project organizations[1].members_can_create_public_repositories = null diff --git a/src/checks/validators/adminRepoCreationOnly.js b/src/checks/validators/adminRepoCreationOnly.js index a031342..8ecbc01 100644 --- a/src/checks/validators/adminRepoCreationOnly.js +++ b/src/checks/validators/adminRepoCreationOnly.js @@ -28,10 +28,10 @@ module.exports = ({ organizations = [], check, projects = [] }) => { const task = { ...baseData } const alert = { ...baseData } - const failedOrgs = projectOrgs.filter(org => org.members_can_create_public_repositories === false).map(org => org.login) + const failedOrgs = projectOrgs.filter(org => org.members_can_create_public_repositories === true).map(org => org.login) const unknownOrgs = projectOrgs.filter(org => org.members_can_create_public_repositories === null).map(org => org.login) - if (projectOrgs.every(org => org.members_can_create_public_repositories === true)) { + if (projectOrgs.every(org => org.members_can_create_public_repositories === false)) { result.status = 'passed' result.rationale = 'Only Admins can create public repositories in the organization(s)' } else if (failedOrgs.length) {