Skip to content

Commit 9de4dc2

Browse files
committed
test(server): DPoP authorization with a lowercase scheme
Authenticates a proof-bound session over HTTP with the DPoP scheme written as "DPoP", "dpop" and "dPoP". The canonical spelling already passes; the other two are rejected, and fail here.
1 parent 15707a8 commit 9de4dc2

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎apps/server/src/auth/EnvironmentAuth.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,45 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodePlatformCrypto.layer))(
785785
),
786786
);
787787

788+
it.effect.each(["DPoP", "dpop", "dPoP"])(
789+
"accepts %s for a proof-bound HTTP request",
790+
(scheme) =>
791+
Effect.gen(function* () {
792+
const serverAuth = yield* EnvironmentAuth.EnvironmentAuth;
793+
const key = makeDpopKey();
794+
const { access_token: token } =
795+
yield* serverAuth.exchangeBootstrapCredentialForAccessToken(
796+
"desktop-bootstrap-token",
797+
["orchestration:read"],
798+
requestMetadata,
799+
{ proofKeyThumbprint: key.thumbprint },
800+
);
801+
const iat = Math.floor((yield* DateTime.now).epochMilliseconds / 1_000);
802+
const request = {
803+
method: "GET",
804+
url: "/api/auth/session",
805+
cookies: {},
806+
headers: {
807+
host: "192.168.1.50:3773",
808+
authorization: `${scheme} ${token}`,
809+
dpop: key.sign({
810+
method: "GET",
811+
url: "http://192.168.1.50:3773/api/auth/session",
812+
token,
813+
iat,
814+
}),
815+
},
816+
} as never;
817+
expect((yield* serverAuth.authenticateHttpRequest(request)).sessionId).toBeTypeOf(
818+
"string",
819+
);
820+
}).pipe(
821+
Effect.provide(
822+
layerEnvironmentAuth({ desktopBootstrapToken: "desktop-bootstrap-token" }),
823+
),
824+
),
825+
);
826+
788827
it.effect("rejects a replayed proof on a bound RPC socket ticket", () =>
789828
Effect.gen(function* () {
790829
const serverAuth = yield* EnvironmentAuth.EnvironmentAuth;

‎apps/server/src/auth/http.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,36 @@ it.effect("sets the selected browser session cookies through the HTTP route", ()
158158
);
159159
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
160160
);
161+
162+
it.effect.each(["DPoP", "dpop"])("challenges a refused %s request with DPoP", (scheme) =>
163+
Effect.gen(function* () {
164+
const random = yield* SecureRandom.SecureRandom;
165+
const unusedSecretStore = ServerSecretStore.ServerSecretStore.of({
166+
get: () => Effect.succeedNone,
167+
set: () => Effect.void,
168+
create: () => Effect.void,
169+
getOrCreateRandom: () => Effect.die("Not used by these routes."),
170+
remove: () => Effect.void,
171+
});
172+
const requestContext = Context.make(SecureRandom.SecureRandom, random).pipe(
173+
Context.add(ServerSecretStore.ServerSecretStore, unusedSecretStore),
174+
);
175+
return yield* Effect.acquireUseRelease(
176+
Effect.sync(() => HttpRouter.toWebHandler(layerRoutes, { disableLogger: true })),
177+
(environment) =>
178+
Effect.tryPromise(async () => {
179+
const refused = await environment.handler(
180+
postJson(
181+
"/api/auth/pairing-token",
182+
{ scopes: ["orchestration:read"] },
183+
{ authorization: `${scheme} not-a-valid-token` },
184+
),
185+
requestContext,
186+
);
187+
expect(refused.status).toBe(401);
188+
expect(refused.headers.get("www-authenticate")).toBe("DPoP");
189+
}),
190+
(environment) => Effect.promise(() => environment.dispose()),
191+
);
192+
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
193+
);

0 commit comments

Comments
 (0)