Skip to content

Commit 84ae503

Browse files
committed
fix tests
1 parent 78a2be4 commit 84ae503

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

packages/api/src/controllers/access-control.test.ts

+26-10
Original file line numberDiff line numberDiff line change
@@ -243,29 +243,45 @@ describe("controllers/access-control", () => {
243243
});
244244

245245
it("should not allow playback if origin is not in playback.allowedOrigins", async () => {
246-
const webhook = await db.webhook.create({
247-
id: uuid(),
248-
name: "test",
249-
url: `http://localhost:3004/api/access-control/webhook-test`,
250-
events: ["playback.accessControl"],
251-
});
252-
gatedAsset.playbackPolicy.webhookId = webhook.id;
253-
gatedAsset.playbackPolicy.type = "webhook";
246+
gatedAsset.playbackPolicy.type = "jwt";
254247
gatedAsset.playbackPolicy.allowedOrigins = ["http://localhost:3000"];
255248
await db.asset.update(gatedAsset.id, {
256249
playbackPolicy: gatedAsset.playbackPolicy,
257250
});
251+
let asset = await db.asset.get(gatedAsset.id);
252+
expect(asset.playbackPolicy.allowedOrigins).toEqual([
253+
"http://localhost:3000",
254+
]);
258255
const res3 = await client.post("/access-control/gate", {
259256
stream: `video+${gatedAsset.playbackId}`,
260-
type: "accessKey",
261-
accessKey: signingKey.publicKey,
257+
type: "jwt",
258+
pub: "notExistingPubKey",
262259
webhookPayload: {
263260
headers: {
264261
origin: "https://example.com",
265262
},
266263
},
267264
});
268265
expect(res3.status).toBe(403);
266+
let resJson = await res3.json();
267+
expect(resJson.errors[0]).toBe(
268+
`Content is gated and origin not in allowed origins`
269+
);
270+
const res4 = await client.post("/access-control/gate", {
271+
stream: `video+${gatedAsset.playbackId}`,
272+
type: "jwt",
273+
pub: "notExistingPubKey",
274+
webhookPayload: {
275+
headers: {
276+
origin: "http://localhost:3000",
277+
},
278+
},
279+
});
280+
expect(res4.status).toBe(403);
281+
let resJson2 = await res4.json();
282+
expect(resJson2.errors[0]).toBe(
283+
"Content is gated and corresponding public key not found"
284+
);
269285
});
270286

271287
it("should allow playback on public playbackId with and without a public key provided", async () => {

packages/api/src/controllers/access-control.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ app.post(
245245

246246
let origin: string = null;
247247
if (req.body?.webhookPayload?.headers) {
248-
origin = req.body?.webhookPayload?.headers["Origin"];
248+
origin = req.body?.webhookPayload?.headers["origin"];
249249
}
250250

251-
if (req.body.origin) {
251+
if (origin) {
252252
if (allowedOrigins.length > 0) {
253253
if (!allowedOrigins.includes(origin)) {
254254
console.log(`
255255
access-control: gate: content with playbackId=${playbackId} is gated but origin=${origin} not in allowed origins=${allowedOrigins}, disallowing playback
256256
`);
257257
throw new ForbiddenError(
258-
"Content is gated and origin not in allowed origins"
258+
`Content is gated and origin not in allowed origins`
259259
);
260260
}
261261
}

0 commit comments

Comments
 (0)