Skip to content

Commit

Permalink
fix: skip validating package names outside of public registries
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal committed Jul 28, 2023
1 parent c7817c6 commit 3294cb1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,20 @@ describe('Validator: PackageName', () => {
errors: []
})
})

it('validator should skip if it doesnt recognize the official public registries', () => {
const mockedPackages = {
'@cxui/cypress-util@1.0.10': {
version: '1.0.10',
resolved:
'https://checkmarx.jfrog.io/artifactory/api/npm/team-npm/@cxui/cypress-util/-/@cxui/cypress-util-1.0.10.tgz#3134312351eb248c1c4561d393afc6d8c23b2943'
}
}

const validator = new ValidatePackageNames({packages: mockedPackages})
expect(validator.validate()).toEqual({
type: 'success',
errors: []
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const {REGISTRY} = require('../common/constants')

module.exports = class ValidatePackageNames {
constructor ({packages} = {}) {
if (typeof packages !== 'object') {
Expand All @@ -22,6 +24,13 @@ module.exports = class ValidatePackageNames {

try {
const packageResolvedURL = new URL(packageMetadata.resolved)

// Only handle package name validation matching per registry URL
// when the registry is one of the official public registries:
if (!Object.values(REGISTRY).includes(packageResolvedURL.host)) {
continue
}

const path = packageResolvedURL.pathname
const packageNameFromResolved = path.split('/-/')[0].slice(1)

Expand Down

0 comments on commit 3294cb1

Please sign in to comment.