| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { servicePath } from "./registry-paths.ts"; |
| 5 | |
| 6 | test("the container registry's paths go to the packages service", () => { |
| 7 | for (const path of [ |
| 8 | "/v2", |
| 9 | "/v2/", |
| 10 | "/v2/token", |
| 11 | "/v2/acme/web/manifests/latest", |
| 12 | "/v2/acme/web/api/blobs/uploads/upl_1", |
| 13 | "/v2/acme/web/tags/list", |
| 14 | "/v2/acme/web/referrers/sha256:abc", |
| 15 | ]) { |
| 16 | assert.equal(servicePath(path), "packages", path); |
| 17 | } |
| 18 | }); |
| 19 | |
| 20 | test("the npm registry's paths go to the packages service", () => { |
| 21 | for (const path of [ |
| 22 | "/-/npm", |
| 23 | "/-/npm/", |
| 24 | "/-/npm/@acme%2fweb", |
| 25 | "/-/npm/@acme/web/-/web-1.0.0.tgz", |
| 26 | "/-/npm/-/package/@acme%2fweb/dist-tags/next", |
| 27 | "/-/npm/-/whoami", |
| 28 | // A package named like a git endpoint is still npm's. |
| 29 | "/-/npm/@acme/info/refs", |
| 30 | ]) { |
| 31 | assert.equal(servicePath(path), "packages", path); |
| 32 | } |
| 33 | for (const path of ["/-/npmx", "/acme/-/npm", "/acme/-/packages"]) { |
| 34 | assert.equal(servicePath(path), null, path); |
| 35 | } |
| 36 | }); |
| 37 | |
| 38 | test("the Composer registries go to the packages service", () => { |
| 39 | for (const path of [ |
| 40 | "/-/composer/acme/packages.json", |
| 41 | "/-/composer/acme/p2/acme/lib.json", |
| 42 | "/-/composer/acme/p2/acme/lib~dev.json", |
| 43 | `/-/composer/acme/dist/acme/lib/${"a".repeat(40)}.zip`, |
| 44 | ]) { |
| 45 | assert.equal(servicePath(path), "packages", path); |
| 46 | } |
| 47 | assert.equal(servicePath("/-/composer"), null); |
| 48 | }); |
| 49 | |
| 50 | test("the Cargo registries go to the packages service", () => { |
| 51 | for (const path of [ |
| 52 | "/-/cargo/acme/index/config.json", |
| 53 | "/-/cargo/acme/index/se/rd/serde", |
| 54 | "/-/cargo/acme/index/3/a/abc", |
| 55 | "/-/cargo/acme/api/v1/crates/new", |
| 56 | "/-/cargo/acme/api/v1/crates/serde/1.0.0/download", |
| 57 | "/-/cargo/acme/api/v1/crates/serde/1.0.0/yank", |
| 58 | // A crate named like a git endpoint is still Cargo's. |
| 59 | "/-/cargo/acme/index/in/fo/info/refs", |
| 60 | ]) { |
| 61 | assert.equal(servicePath(path), "packages", path); |
| 62 | } |
| 63 | assert.equal(servicePath("/-/cargo"), null); |
| 64 | assert.equal(servicePath("/acme/-/cargo/x"), null); |
| 65 | }); |
| 66 | |
| 67 | test("the Maven repositories go to the packages service", () => { |
| 68 | for (const path of [ |
| 69 | "/-/maven/acme/com/acme/web/maven-metadata.xml", |
| 70 | "/-/maven/acme/com/acme/web/maven-metadata.xml.sha1", |
| 71 | "/-/maven/acme/com/acme/web/1.0.0/web-1.0.0.jar", |
| 72 | "/-/maven/acme/com/acme/web/1.0-SNAPSHOT/web-1.0-20261006.120000-1.pom", |
| 73 | // An artifact named like a git endpoint is still Maven's. |
| 74 | "/-/maven/acme/com/acme/info/refs", |
| 75 | ]) { |
| 76 | assert.equal(servicePath(path), "packages", path); |
| 77 | } |
| 78 | assert.equal(servicePath("/-/maven"), null); |
| 79 | assert.equal(servicePath("/acme/-/maven/x"), null); |
| 80 | }); |
| 81 | |
| 82 | test("the NuGet feeds go to the packages service", () => { |
| 83 | for (const path of [ |
| 84 | "/-/nuget/acme/v3/index.json", |
| 85 | "/-/nuget/acme/v3/flatcontainer/acme.web/index.json", |
| 86 | "/-/nuget/acme/v3/flatcontainer/acme.web/1.0.0/acme.web.1.0.0.nupkg", |
| 87 | "/-/nuget/acme/v3/registration/acme.web/index.json", |
| 88 | "/-/nuget/acme/v3/query", |
| 89 | "/-/nuget/acme/api/v2/package", |
| 90 | "/-/nuget/acme/api/v2/package/Acme.Web/1.0.0", |
| 91 | ]) { |
| 92 | assert.equal(servicePath(path), "packages", path); |
| 93 | } |
| 94 | assert.equal(servicePath("/-/nuget"), null); |
| 95 | assert.equal(servicePath("/acme/-/nuget/x"), null); |
| 96 | }); |
| 97 | |
| 98 | test("the RubyGems registries go to the packages service", () => { |
| 99 | for (const path of [ |
| 100 | "/-/rubygems/acme/versions", |
| 101 | "/-/rubygems/acme/info/hello", |
| 102 | "/-/rubygems/acme/names", |
| 103 | "/-/rubygems/acme/gems/hello-0.1.0.gem", |
| 104 | "/-/rubygems/acme/api/v1/gems", |
| 105 | "/-/rubygems/acme/api/v1/gems/yank", |
| 106 | ]) { |
| 107 | assert.equal(servicePath(path), "packages", path); |
| 108 | } |
| 109 | assert.equal(servicePath("/-/rubygems"), null); |
| 110 | assert.equal(servicePath("/acme/-/rubygems/x"), null); |
| 111 | }); |
| 112 | |
| 113 | test("git goes to repos, and everything else is the site's", () => { |
| 114 | assert.equal(servicePath("/acme/web.git/info/refs"), "git"); |
| 115 | assert.equal(servicePath("/acme/web/git-receive-pack"), "git"); |
| 116 | // A registry image named like a git endpoint is still the registry's. |
| 117 | assert.equal(servicePath("/v2/acme/info/refs"), "packages"); |
| 118 | for (const path of ["/", "/acme", "/acme/web", "/v2x", "/acme/v2", "/acme/-/packages"]) { |
| 119 | assert.equal(servicePath(path), null, path); |
| 120 | } |
| 121 | }); |