diff options
author | 2023-09-18 23:27:02 -0700 | |
---|---|---|
committer | 2023-09-18 23:27:02 -0700 | |
commit | cc54b62fac41c0977c7dfc4c6ba550a6408fa15f (patch) | |
tree | cf8f61c2dd1fa778e304c54e7fd92e4bece15268 /test | |
parent | 9d3f60d44ed90bcb581b590067b42d92e7cdecad (diff) | |
download | bun-cc54b62fac41c0977c7dfc4c6ba550a6408fa15f.tar.gz bun-cc54b62fac41c0977c7dfc4c6ba550a6408fa15f.tar.zst bun-cc54b62fac41c0977c7dfc4c6ba550a6408fa15f.zip |
Encode slashes in package names in the registry manifest request (#5716)
* Encode slashes in package names in the registry manifest request
Co-Authored-By: Max Brosnahan <1177034+gingermusketeer@users.noreply.github.com>
* Update dummy.registry.ts
* Fix tests
* Add guide for Azure Artifacts
* Update azure-artifacts.md
* Update azure-artifacts.md
* Typo
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Max Brosnahan <1177034+gingermusketeer@users.noreply.github.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/cli/install/bun-add.test.ts | 4 | ||||
-rw-r--r-- | test/cli/install/bun-install.test.ts | 10 | ||||
-rw-r--r-- | test/cli/install/bun-update.test.ts | 4 | ||||
-rw-r--r-- | test/cli/install/dummy.registry.ts | 11 |
4 files changed, 16 insertions, 13 deletions
diff --git a/test/cli/install/bun-add.test.ts b/test/cli/install/bun-add.test.ts index 4461584e4..c00c0ba7b 100644 --- a/test/cli/install/bun-add.test.ts +++ b/test/cli/install/bun-add.test.ts @@ -232,11 +232,11 @@ it("should handle @scoped names", async () => { }); expect(stderr).toBeDefined(); const err = await new Response(stderr).text(); - expect(err.split(/\r?\n/)).toContain('error: package "@bar/baz" not found localhost/@bar/baz 404'); + expect(err.split(/\r?\n/)).toContain('error: package "@bar/baz" not found localhost/@bar%2fbaz 404'); expect(stdout).toBeDefined(); expect(await new Response(stdout).text()).toBe(""); expect(await exited).toBe(1); - expect(urls.sort()).toEqual([`${root_url}/@bar/baz`]); + expect(urls.sort()).toEqual([`${root_url}/@bar%2fbaz`]); expect(requested).toBe(1); try { await access(join(package_dir, "bun.lockb")); diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts index c4accb1b4..25cd0aca7 100644 --- a/test/cli/install/bun-install.test.ts +++ b/test/cli/install/bun-install.test.ts @@ -39,7 +39,7 @@ it("should report connection errors", async () => { ` [install] cache = false -registry = "http://localhost:${server.port}/" +registry = "http://${server.hostname}:${server.port}/" `, ); await writeFile( @@ -62,7 +62,7 @@ registry = "http://localhost:${server.port}/" }); expect(stderr).toBeDefined(); const err = await new Response(stderr).text(); - expect(err.split(/\r?\n/)).toContain("error: ConnectionClosed downloading package manifest bar"); + expect(err.split(/\r?\n/)).toContain("error: ConnectionRefused downloading package manifest bar"); expect(stdout).toBeDefined(); expect(await new Response(stdout).text()).toBeEmpty(); expect(await exited).toBe(1); @@ -112,7 +112,7 @@ it("should handle missing package", async () => { it("should handle @scoped authentication", async () => { let seen_token = false; - const url = `${root_url}/@foo/bar`; + const url = `${root_url}/@foo%2fbar`; const urls: string[] = []; setHandler(async request => { expect(request.method).toBe("GET"); @@ -2197,7 +2197,7 @@ it("should handle unscoped alias on scoped dependency", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls.sort()).toEqual([`${root_url}/@barn/moo`, `${root_url}/@barn/moo-0.1.0.tgz`]); + expect(urls.sort()).toEqual([`${root_url}/@barn%2fmoo`, `${root_url}/@barn/moo-0.1.0.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "@barn", "moo"]); expect(await readdirSorted(join(package_dir, "node_modules", "@barn"))).toEqual(["moo"]); @@ -2327,7 +2327,7 @@ it("should handle aliased dependency with existing lockfile", async () => { ]); expect(await exited1).toBe(0); expect(urls.sort()).toEqual([ - `${root_url}/@barn/moo`, + `${root_url}/@barn%2fmoo`, `${root_url}/@barn/moo-0.1.0.tgz`, `${root_url}/bar`, `${root_url}/bar-0.0.2.tgz`, diff --git a/test/cli/install/bun-update.test.ts b/test/cli/install/bun-update.test.ts index 2a6ee4eaf..ff8e22c37 100644 --- a/test/cli/install/bun-update.test.ts +++ b/test/cli/install/bun-update.test.ts @@ -185,7 +185,7 @@ it("should update to latest versions of dependencies", async () => { ]); expect(await exited1).toBe(0); expect(urls.sort()).toEqual([ - `${root_url}/@barn/moo`, + `${root_url}/@barn%2fmoo`, `${root_url}/@barn/moo-0.1.0.tgz`, `${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`, @@ -236,7 +236,7 @@ it("should update to latest versions of dependencies", async () => { ]); expect(await exited2).toBe(0); expect(urls.sort()).toEqual([ - `${root_url}/@barn/moo`, + `${root_url}/@barn%2fmoo`, `${root_url}/@barn/moo-0.1.0.tgz`, `${root_url}/baz`, `${root_url}/baz-0.0.5.tgz`, diff --git a/test/cli/install/dummy.registry.ts b/test/cli/install/dummy.registry.ts index 69af0c381..5d0982f57 100644 --- a/test/cli/install/dummy.registry.ts +++ b/test/cli/install/dummy.registry.ts @@ -34,16 +34,19 @@ export let root_url: string; export function dummyRegistry(urls: string[], info: any = { "0.0.2": {} }) { const _handler: Handler = async request => { urls.push(request.url); + const url = request.url.replaceAll("%2f", "/"); + expect(request.method).toBe("GET"); - if (request.url.endsWith(".tgz")) { - return new Response(file(join(import.meta.dir, basename(request.url).toLowerCase()))); + if (url.endsWith(".tgz")) { + return new Response(file(join(import.meta.dir, basename(url).toLowerCase()))); } expect(request.headers.get("accept")).toBe( "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*", ); expect(request.headers.get("npm-auth-type")).toBe(null); expect(await request.text()).toBe(""); - const name = request.url.slice(request.url.indexOf("/", root_url.length) + 1); + + const name = url.slice(url.indexOf("/", root_url.length) + 1); const versions: Record<string, Pkg> = {}; let version; for (version in info) { @@ -52,7 +55,7 @@ export function dummyRegistry(urls: string[], info: any = { "0.0.2": {} }) { name, version, dist: { - tarball: `${request.url}-${info[version].as ?? version}.tgz`, + tarball: `${url}-${info[version].as ?? version}.tgz`, }, ...info[version], }; |