Files
return-youtube-dislike/Extensions/e2e/vote-protocol-contract.spec.js
Anarios e500088e65 Prepare 4.0.5 Firefox update and Shorts fixes
Add Firefox data consent, repair contributor sign-in, and introduce optional Hide clutter buttons. Harden video navigation, voting, and action layouts with shared browser regression coverage and reproducible release packaging.
2026-09-06 12:51:12 +02:00

48 lines
2.2 KiB
JavaScript

const { hasExactKeys, isFourByteProofSolution, isVoteProtocolBodyPairValid } = require("./vote-protocol-contract");
const USER_ID = "A".repeat(36);
const VIDEO_ID = "abcdefghijk";
const SOLUTION = Buffer.alloc(4).toString("base64");
function validBodies() {
return {
confirmation: { solution: SOLUTION, userId: USER_ID, videoId: VIDEO_ID },
vote: { userId: USER_ID, value: -1, videoId: VIDEO_ID },
};
}
test("accepts only the exact vote and four-byte confirmation protocol bodies", () => {
const bodies = validBodies();
expect(isVoteProtocolBodyPairValid(bodies.vote, bodies.confirmation, { value: -1, videoId: VIDEO_ID })).toBe(true);
});
test.each([
["short user ID", ({ vote }) => ({ ...vote, userId: "short" })],
["extra vote key", ({ vote }) => ({ ...vote, unexpected: true })],
["wrong video", ({ vote }) => ({ ...vote, videoId: "lmnopqrstuv" })],
["wrong value", ({ vote }) => ({ ...vote, value: 1 })],
])("rejects a vote body with a %s", (_label, changeVote) => {
const bodies = validBodies();
bodies.vote = changeVote(bodies);
expect(isVoteProtocolBodyPairValid(bodies.vote, bodies.confirmation, { value: -1, videoId: VIDEO_ID })).toBe(false);
});
test.each([
["different user ID", ({ confirmation }) => ({ ...confirmation, userId: "B".repeat(36) })],
["extra confirmation key", ({ confirmation }) => ({ ...confirmation, unexpected: true })],
["wrong video", ({ confirmation }) => ({ ...confirmation, videoId: "lmnopqrstuv" })],
["short proof", ({ confirmation }) => ({ ...confirmation, solution: "AA==" })],
["non-canonical proof", ({ confirmation }) => ({ ...confirmation, solution: "AAAAAA==\n" })],
])("rejects a confirmation body with a %s", (_label, changeConfirmation) => {
const bodies = validBodies();
bodies.confirmation = changeConfirmation(bodies);
expect(isVoteProtocolBodyPairValid(bodies.vote, bodies.confirmation, { value: -1, videoId: VIDEO_ID })).toBe(false);
});
test("exact-key and proof helpers fail closed", () => {
expect(hasExactKeys({ a: 1, b: 2 }, ["b", "a"])).toBe(true);
expect(hasExactKeys({ a: 1, b: 2, c: 3 }, ["a", "b"])).toBe(false);
expect(isFourByteProofSolution(SOLUTION)).toBe(true);
expect(isFourByteProofSolution("not-base64")).toBe(false);
});