Skip to content

Commit 20cd590

Browse files
Merge pull request #145 from cloudflare/mjp/misc
misc maintenance
2 parents dfccf0b + a1b2a0e commit 20cd590

8 files changed

Lines changed: 272 additions & 349 deletions

File tree

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,27 @@
1515
"test": "vitest run"
1616
},
1717
"dependencies": {
18-
"@cfworker/base64url": "^1.12.5",
19-
"@tsndr/cloudflare-worker-jwt": "^3.2.1",
18+
"@tsndr/cloudflare-worker-jwt": "^3.2.2",
2019
"itty-router": "^5.0.24",
20+
"rfc4648": "^1.5.4",
2121
"zod": "^4.4.3"
2222
},
2323
"devDependencies": {
24-
"@cloudflare/vitest-pool-workers": "^0.19.0",
24+
"@cloudflare/vitest-pool-workers": "^0.20.1",
2525
"@eslint/js": "^10.0.1",
2626
"@types/node": "26.1.2",
2727
"@typescript/native": "npm:typescript@^7.0.2",
2828
"eslint": "^10.8.0",
29-
"miniflare": "4.20260722.1",
3029
"prettier": "3.9.6",
3130
"typescript": "npm:@typescript/typescript6@^6.0.2",
32-
"typescript-eslint": "^8.65.0",
33-
"vite": "^8.1.5",
31+
"typescript-eslint": "^8.66.0",
3432
"vitest": "^4.1.10",
35-
"wrangler": "^4.115.0"
33+
"wrangler": "^4.118.0"
3634
},
3735
"engines": {
3836
"node": ">=24.0.0",
3937
"pnpm": ">=11.0.0"
4038
},
4139
"license": "Apache-2.0",
42-
"packageManager": "pnpm@11.17.0"
40+
"packageManager": "pnpm@11.20.0"
4341
}

pnpm-lock.yaml

Lines changed: 244 additions & 329 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/auth.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { decode } from "@cfworker/base64url";
2-
import { errorString } from "./utils";
1+
import { base64UrlDecode, errorString } from "./utils";
32

43
export type RegistryTokenCapability = "push" | "pull";
54
export type RegistryAuthProtocolTokenPayload = {
@@ -42,7 +41,7 @@ export function stripUsernamePasswordFromHeader(r: Request): [string, string] |
4241

4342
try {
4443
// Decodes the base64 value and performs unicode normalization.
45-
const decoded = decode(encoded);
44+
const decoded = base64UrlDecode(encoded);
4645

4746
// The username & password are split by the first colon.
4847
//=> example: "username:password"

src/token.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { decode } from "@cfworker/base64url";
21
import jwt from "@tsndr/cloudflare-worker-jwt";
32
import {
43
RegistryTokenCapability,
54
RegistryAuthProtocolTokenPayload,
65
stripUsernamePasswordFromHeader,
76
Authenticator,
87
} from "./auth";
8+
import { base64UrlDecode } from "./utils";
99

1010
export function importKeyFromBase64(key: string): JsonWebKeyWithKid {
1111
// Decodes the base64 value and performs unicode normalization.
1212
// The library's `JsonWebKeyWithKid` type requires `kid`, but ES256/HS256 sign
1313
// and verify only need the key material at runtime, so casting is safe.
14-
return JSON.parse(decode(key)) as JsonWebKeyWithKid;
14+
return JSON.parse(base64UrlDecode(key)) as JsonWebKeyWithKid;
1515
}
1616

1717
export async function newRegistryTokens(jwtPublicKey: string): Promise<RegistryTokens> {

src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { base64url } from "rfc4648";
12
import { prettifyError, ZodError } from "zod";
23

34
export async function readableToBlob(
@@ -64,3 +65,13 @@ export async function wrap<T, E = unknown>(fn: Promise<T>): Promise<[T, null] |
6465
export function jsonHeaders(): { "content-type": "application/json" } {
6566
return { "content-type": "application/json" };
6667
}
68+
69+
const textDecoder = new TextDecoder();
70+
71+
export function base64UrlDecode(s: string): string {
72+
return textDecoder.decode(base64url.parse(s, { loose: true }));
73+
}
74+
75+
export function base64UrlEncode(s: string): string {
76+
return Buffer.from(s, "utf8").toString("base64url");
77+
}

test/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { RegistryAuthProtocolTokenPayload } from "../src/auth";
77
import { registries } from "../src/registry/registry";
88
import type { ReferrerDescriptor } from "../src/registry/registry";
99
import { isDockerDotIO, RegistryHTTPClient } from "../src/registry/http";
10-
import { encode } from "@cfworker/base64url";
1110
import { ManifestSchema } from "../src/manifest";
1211
import { limit } from "../src/chunk";
1312
import worker from "../index";
1413
import { env } from "cloudflare:workers";
1514
import { createExecutionContext, reset, waitOnExecutionContext } from "cloudflare:test";
15+
import { base64UrlEncode } from "../src/utils";
1616

1717
afterEach(async () => {
1818
await reset();
@@ -149,14 +149,14 @@ describe("v2", () => {
149149
test("Username password authenticatiom fails gracefully when wrong format", async () => {
150150
const res = await fetchUnauth(
151151
createRequest("GET", `/v2/`, null, {
152-
Authorization: `Basic ${encode("hello")}:${encode("t")}`,
152+
Authorization: `Basic ${base64UrlEncode("hello")}:${base64UrlEncode("t")}`,
153153
}),
154154
);
155155
expect(res.status).toBe(401);
156156
});
157157

158158
test("Username password authenticatiom fails gracefully when password is wrong", async () => {
159-
const cred = encode(`hello:t`);
159+
const cred = base64UrlEncode(`hello:t`);
160160
const res = await fetchUnauth(
161161
createRequest("GET", `/v2/`, null, {
162162
Authorization: `Basic ${cred}`,
@@ -166,7 +166,7 @@ describe("v2", () => {
166166
});
167167

168168
test("Simple username password authenticatiom fails gracefully when password is wrong", async () => {
169-
const cred = encode(`hello:t`);
169+
const cred = base64UrlEncode(`hello:t`);
170170
const res = await fetchUnauth(
171171
createRequest("GET", `/v2/`, null, {
172172
Authorization: `Basic ${cred}`,
@@ -176,7 +176,7 @@ describe("v2", () => {
176176
});
177177

178178
test("Simple username password authenticatiom fails gracefully when username is wrong", async () => {
179-
const cred = encode(`hell0:world`);
179+
const cred = base64UrlEncode(`hell0:world`);
180180
const res = await fetchUnauth(
181181
createRequest("GET", `/v2/`, null, {
182182
Authorization: `Basic ${cred}`,

test/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"types": ["../worker-configuration.d.ts", "@cloudflare/vitest-pool-workers/types"],
3+
"types": ["../worker-configuration.d.ts", "@cloudflare/vitest-pool-workers/types", "node"],
44
"module": "esnext",
55
"target": "esnext",
66
"lib": ["esnext"],

worker-configuration.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
// Runtime types generated with workerd@1.20260722.1 2024-09-09 nodejs_compat
2+
// Runtime types generated with workerd@1.20260730.1 2024-09-09 nodejs_compat
33
// Begin runtime types
44
/*! *****************************************************************************
55
Copyright (c) Cloudflare. All rights reserved.

0 commit comments

Comments
 (0)