mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-16 02:48:44 -05:00
* fix(git-resolver): handle private git repo resolution In the case where: 1. No git auth token was specified by the user 2. The package requested to be fetched via https 3. The user does not have SSH access to the repo but has HTTPS access 4. The package was hosted in a private GitHub repo pnpm would fallback to using SSH since it was a "likely private repo" and would fail to resolve the package. Now, rather than only checking if there is an auth token specified, it also checks both: 1. Is the repo private 2. Does the user have access to ls-remote it. And if these conditions are true, it tries to use https anyway. This matches the behavior of npm and Yarn berry. Yarn classic also has this bug, and there's a code comment that alludes to it.
54 lines
3.5 KiB
TypeScript
54 lines
3.5 KiB
TypeScript
import { parsePref } from '../lib/parsePref'
|
|
|
|
test.each([
|
|
['ssh://username:password@example.com:repo.git', 'ssh://username:password@example.com/repo.git'],
|
|
['ssh://username:password@example.com:repo/@foo.git', 'ssh://username:password@example.com/repo/@foo.git'],
|
|
['ssh://username:password@example.com:22/repo/@foo.git', 'ssh://username:password@example.com:22/repo/@foo.git'],
|
|
['ssh://username:password@example.com:22repo/@foo.git', 'ssh://username:password@example.com/22repo/@foo.git'],
|
|
['ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b', 'ssh://username:password@example.com:22/repo/@foo.git'],
|
|
['ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b&dev', 'ssh://username:password@example.com:22/repo/@foo.git'],
|
|
['git+ssh://username:password@example.com:repo.git', 'ssh://username:password@example.com/repo.git'],
|
|
['git+ssh://username:password@example.com:repo/@foo.git', 'ssh://username:password@example.com/repo/@foo.git'],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git', 'ssh://username:password@example.com:22/repo/@foo.git'],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b', 'ssh://username:password@example.com:22/repo/@foo.git'],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b&dev', 'ssh://username:password@example.com:22/repo/@foo.git'],
|
|
])('the right colon is escaped in %s', async (input, output) => {
|
|
const parsed = await parsePref(input)
|
|
expect(parsed?.fetchSpec).toBe(output)
|
|
})
|
|
|
|
test.each([
|
|
['ssh://username:password@example.com:repo.git#path:/a/@b', '/a/@b'],
|
|
['ssh://username:password@example.com:repo/@foo.git#path:/a/@b', '/a/@b'],
|
|
['ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b', '/a/@b'],
|
|
['ssh://username:password@example.com:22repo/@foo.git#path:/a/@b', '/a/@b'],
|
|
['ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b', '/a/@b'],
|
|
['ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b&dev', '/a/@b'],
|
|
['git+ssh://username:password@example.com:repo.git#path:/a/@b', '/a/@b'],
|
|
['git+ssh://username:password@example.com:repo/@foo.git#path:/a/@b', '/a/@b'],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b', '/a/@b'],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b', '/a/@b'],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git#path:/a/@b&dev', '/a/@b'],
|
|
['ssh://username:password@example.com:repo.git', undefined],
|
|
['ssh://username:password@example.com:repo/@foo.git', undefined],
|
|
['ssh://username:password@example.com:22/repo/@foo.git', undefined],
|
|
['ssh://username:password@example.com:22repo/@foo.git', undefined],
|
|
['ssh://username:password@example.com:22/repo/@foo.git', undefined],
|
|
['ssh://username:password@example.com:22/repo/@foo.git#dev', undefined],
|
|
['git+ssh://username:password@example.com:repo.git', undefined],
|
|
['git+ssh://username:password@example.com:repo/@foo.git', undefined],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git', undefined],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git', undefined],
|
|
['git+ssh://username:password@example.com:22/repo/@foo.git#dev', undefined],
|
|
])('the path of %s should be %s', async (input, output) => {
|
|
const parsed = await parsePref(input)
|
|
expect(parsed?.path).toBe(output)
|
|
})
|
|
|
|
test.each([
|
|
['git+https://github.com/pnpm/pnpm.git', 'https://github.com/pnpm/pnpm.git'],
|
|
])('the fetchSpec of %s should be %s', async (input, output) => {
|
|
const parsed = await parsePref(input)
|
|
expect(parsed?.fetchSpec).toBe(output)
|
|
})
|