Skip to content

Commit

Permalink
fix: revert boolean logic to match validation criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Jan 3, 2025
1 parent 0c8b874 commit fb7996c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions __tests__/checks/adminRepoCreationOnly.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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' })
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions __tests__/checks/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/checks/validators/adminRepoCreationOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fb7996c

Please sign in to comment.