From bb2a007ed160de96fa8719be3e77bf19baaedb15 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sat, 2 Oct 2021 04:39:54 +0200 Subject: [PATCH 1/7] first changes and timeout on 2nd test --- src/routes/voteOnSponsorTime.ts | 20 +++- test/cases/voteOnSponsorTime.ts | 203 +++++++++++++++++++++++++++----- 2 files changed, 190 insertions(+), 33 deletions(-) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index c3783b5..2c1f1f2 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -162,8 +162,8 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i return res.sendStatus(finalResponse.finalStatus); } - const videoInfo = (await db.prepare("get", `SELECT "category", "videoID", "hashedVideoID", "service", "userID" FROM "sponsorTimes" WHERE "UUID" = ?`, - [UUID])) as {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID}; + const videoInfo = (await db.prepare("get", `SELECT "category", "videoID", "hashedVideoID", "service", "userID", "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, + [UUID])) as {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID, locked: number}; if (!videoInfo) { // Submission doesn't exist return res.status(400).send("Submission doesn't exist."); @@ -176,6 +176,20 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i return res.status(400).send("Cannot vote for this category"); } + // Ignore vote if the next category is locked + const nextCategoryLocked = await db.prepare("get", `SELECT "videoID", "category" FROM "lockCategories" WHERE "videoID" = ? AND "category" = ?`, [videoInfo.videoID, category]); + if (nextCategoryLocked) { + if (!isVIP) { + return res.status(200); + } // In an else statement, add a warning in the future for VIPs, that the next category is locked + } + + // Ignore vote if the segment is locked + if (!isVIP && videoInfo.locked === 1) { + console.log("dalfäkjsdöfbsdfoöjasdökjb"); + return res.status(200); + } + const nextCategoryInfo = await db.prepare("get", `select votes from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category]); const timeSubmitted = Date.now(); @@ -424,7 +438,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise 0 && voteTypeEnum === voteTypes.normal) { - // Unide and Lock this submission + // Unhide and Lock this submission await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]); // Reset video duration in case that caused it to be hidden diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 32f937b..d6a3a77 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -12,6 +12,7 @@ const sinonStub = mockManager.mock("listVideos"); sinonStub.callsFake(YouTubeApiMock.listVideos); const vipUser = "VIPUser"; const randomID2 = "randomID2"; +const categoryChangeUser = "category-change-user"; describe("voteOnSponsorTime", () => { before(async () => { @@ -19,34 +20,43 @@ describe("voteOnSponsorTime", () => { const warnVip01Hash = getHash("warn-vip01"); const warnUser01Hash = getHash("warn-voteuser01"); const warnUser02Hash = getHash("warn-voteuser02"); + const categoryChangeUserHash = getHash(categoryChangeUser); const MILLISECONDS_IN_HOUR = 3600000; const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires; - const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden", "hidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, "vote-uuid-0", "testman", 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 2, "vote-uuid-1", "testman", 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, "vote-uuid-1.5", "testman", 0, 50, "outro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, "vote-uuid-1.6", "testman", 0, 50, "interaction", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest3", 20, 33, 10, "vote-uuid-2", "testman", 0, 50, "intro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, "vote-uuid-3", "testman", 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, "vote-uuid-4", "testman", 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, "vote-uuid-5", "testman", 0, 50, "intro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, "vote-uuid-5_1", "testman", 0, 50, "intro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-9", getHash(randomID2), 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["not-own-submission-video", 1, 11, 500, "not-own-submission-uuid", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category", 1, 11, 500, "incorrect-category", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category-change", 1, 11, 500, "incorrect-category-change", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, "warnvote-uuid-0", "testman", 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, "no-sponsor-segments-uuid-0", "no-sponsor-segments", 0, 50, "sponsor", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, "no-sponsor-segments-uuid-1", "no-sponsor-segments", 0, 50, "intro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["segment-locking-video", 1, 11, 2, "segment-locking-uuid-1", "segment-locking-user", 0, 50, "intro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["segment-hidden-video", 1, 11, 2, "segment-hidden-uuid-1", "segment-hidden-user", 0, 50, "intro", 0, 1]); + const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden", "hidden") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, 0, "vote-uuid-0", "testman", 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 2, 0, "vote-uuid-1", "testman", 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, 0, "vote-uuid-1.5", "testman", 0, 50, "outro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, 0, "vote-uuid-1.6", "testman", 0, 50, "interaction", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest3", 20, 33, 10, 0, "vote-uuid-2", "testman", 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, 0, "vote-uuid-3", "testman", 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, 0, "vote-uuid-4", "testman", 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5", "testman", 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5_1", "testman", 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, 0, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, 0, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, 0, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-9", getHash(randomID2), 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, 0, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["not-own-submission-video", 1, 11, 500, 0, "not-own-submission-uuid", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category", 1, 11, 500, 0, "incorrect-category", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category-change", 1, 11, 500, 0, "incorrect-category-change", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, 0, "warnvote-uuid-0", "testman", 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, 0, "no-sponsor-segments-uuid-0", "no-sponsor-segments", 0, 50, "sponsor", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, 0, "no-sponsor-segments-uuid-1", "no-sponsor-segments", 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["segment-locking-video", 1, 11, 2, 0, "segment-locking-uuid-1", "segment-locking-user", 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["segment-hidden-video", 1, 11, 2, 0, "segment-hidden-uuid-1", "segment-hidden-user", 0, 50, "intro", 0, 1]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 22, 0, 0, "category-change-uuid-1", categoryChangeUserHash, 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 8, 22, 0, 1, "category-change-uuid-2", categoryChangeUserHash, 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 9, 22, 0, 0, "category-change-uuid-3", categoryChangeUserHash, 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-4", categoryChangeUserHash, 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 13, 0, 0, "category-change-uuid-5", categoryChangeUserHash, 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 8, 12, 0, 1, "category-change-uuid-6", categoryChangeUserHash, 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 9, 14, 0, 0, "category-change-uuid-7", categoryChangeUserHash, 0, 50, "intro", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-8", categoryChangeUserHash, 0, 50, "intro", 0, 0]); const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)'; await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]); @@ -62,7 +72,9 @@ describe("voteOnSponsorTime", () => { await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash(vipUser)]); await db.prepare("run", 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)', [getHash("randomID4")]); - await db.prepare("run", 'INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES (?, ?, ?)', ["no-sponsor-segments-video", "someUser", "sponsor"]); + const insertlockCategoriesQuerry = 'INSERT INTO "lockCategories" ("videoID", "userID", "category", "reason") VALUES (?, ?, ?, ?)'; + await db.prepare("run", insertlockCategoriesQuerry, ["no-sponsor-segments-video", "someUser", "sponsor", ""]); + await db.prepare("run", insertlockCategoriesQuerry, ["category-change-test-1", "someUser", "preview", ""]); // sponsor should stay unlocked }); // constants const endpoint = "/api/voteOnSponsorTime"; @@ -172,7 +184,7 @@ describe("voteOnSponsorTime", () => { .catch(err => done(err)); }); - it("should be able to completely downvote your own segment", (done) => { + it("should be able to completely downvote your own segment (segment unlocked)", (done) => { const UUID = "own-submission-uuid"; postVote("own-submission-id", UUID, 0) .then(async res => { @@ -238,7 +250,7 @@ describe("voteOnSponsorTime", () => { .catch(err => done(err)); }); - it("Should be able to change your vote for a category and it should add your vote to the database", (done) => { + it("Should be able to change your vote for a category and it should add your vote to the database(segment unlocked, nextCatgeory unlocked)", (done) => { const UUID = "vote-uuid-4"; postVoteCategory(randomID2, UUID, "outro") .then(async res => { @@ -280,7 +292,7 @@ describe("voteOnSponsorTime", () => { }); }); - + /* it("VIP should be able to vote for a category and it should immediately change", (done) => { const UUID = "vote-uuid-5"; postVoteCategory(vipUser, UUID, "outro") @@ -294,7 +306,7 @@ describe("voteOnSponsorTime", () => { }) .catch(err => done(err)); }); - +// old test it("Submitter should be able to vote for a category and it should immediately change", (done) => { const UUID = "vote-uuid-5_1"; postVoteCategory("testman", UUID, "outro") @@ -305,8 +317,139 @@ describe("voteOnSponsorTime", () => { done(); }) .catch(err => done(err)); + });*/ + + it("Submitter should be able to vote for a category and it should immediately change (segment unlocked, nextCatgeory unlocked, notVip)", (done) => { + const userID = categoryChangeUser; + const UUID = "category-change-uuid-1"; + const category = "sponsor"; + postVoteCategory(userID, UUID, category) + .then(async res => { + assert.strictEqual(res.status, 200); + const row = await getSegmentCategory(UUID); + console.log(row.category) + assert.strictEqual(row.category, category); + done(); + }) + .catch(err => done(err)); }); + it("Submitter's vote on the category should not work (segment locked, nextCatgeory unlocked, notVip)", (done) => { + const userID = categoryChangeUser; + const UUID = "category-change-uuid-2"; + const category = "sponsor"; + postVoteCategory(userID, UUID, category) + .then(async res => { + assert.strictEqual(res.status, 200); + const row = await getSegmentCategory(UUID); + console.log(row.category) + assert.strictEqual(row.category, "intro"); + done(); + }) + .catch(err => done(err)); + }); + + it("Submitter's vote on the category should not work (segment unlocked, nextCatgeory locked, notVip)", (done) => { + const userID = categoryChangeUser; + const UUID = "category-change-uuid-3"; + const category = "preview"; + postVoteCategory(userID, UUID, category) + .then(async res => { + assert.strictEqual(res.status, 200); + const row = await getSegmentCategory(UUID); + console.log(row.category) + assert.strictEqual(row.category, "intro"); + done(); + }) + .catch(err => done(err)); + }); + + it("Submitter's vote on the category should not work (segment locked, nextCatgeory locked, notVip)", (done) => { + const userID = categoryChangeUser; + const UUID = "category-change-uuid-4"; + const category = "preview"; + postVoteCategory(userID, UUID, category) + .then(async res => { + assert.strictEqual(res.status, 200); + const row = await getSegmentCategory(UUID); + console.log(row.category) + assert.strictEqual(row.category, "intro"); + done(); + }) + .catch(err => done(err)); + }); +//adjbaelrfkbfjgöäkldfgölkndfgölfdngöfkdln + it("Vip should be able to vote for a category and it should immediately change (segment unlocked, nextCatgeory unlocked, Vip)", (done) => { + const userID = vipUser; + const UUID = "category-change-uuid-5"; + const category = "sponsor"; + postVoteCategory(userID, UUID, category) + .then(async res => { + assert.strictEqual(res.status, 200); + const row = await getSegmentCategory(UUID); + assert.strictEqual(row.category, category); + done(); + }) + .catch(err => done(err)); + }); + + it("Vip should be able to vote for a category and it should immediately change (segment locked, nextCatgeory unlocked, Vip)", (done) => { + const userID = vipUser; + const UUID = "category-change-uuid-6"; + const category = "sponsor"; + postVoteCategory(userID, UUID, category) + .then(async res => { + assert.strictEqual(res.status, 200); + const row = await getSegmentCategory(UUID); + assert.strictEqual(row.category, category); + done(); + }) + .catch(err => done(err)); + }); + + it("Vip should be able to vote for a category and it should immediately change (segment unlocked, nextCatgeory locked, Vip)", (done) => { + const userID = vipUser; + const UUID = "category-change-uuid-7"; + const category = "preview"; + postVoteCategory(userID, UUID, category) + .then(async res => { + assert.strictEqual(res.status, 200); + const row = await getSegmentCategory(UUID); + assert.strictEqual(row.category, category); + done(); + }) + .catch(err => done(err)); + }); + + it("Vip should be able to vote for a category and it should immediately change (segment locked, nextCatgeory locked, Vip)", (done) => { + const userID = vipUser; + const UUID = "category-change-uuid-8"; + const category = "preview"; + postVoteCategory(userID, UUID, category) + .then(async res => { + assert.strictEqual(res.status, 200); + const row = await getSegmentCategory(UUID); + assert.strictEqual(row.category, category); + done(); + }) + .catch(err => done(err)); + }); + + + + + + + + + + + + + + + + it("Should not be able to category-vote on an invalid UUID submission", (done) => { const UUID = "invalid-uuid"; postVoteCategory("randomID3", UUID, "intro") From aacd297b3b27621032e811a3448e138ccd58eb36 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sat, 2 Oct 2021 05:04:18 +0200 Subject: [PATCH 2/7] Fixed bugs where normal users could cirumvent vip locks by changing categories --- src/routes/voteOnSponsorTime.ts | 4 ++-- test/cases/voteOnSponsorTime.ts | 35 +++------------------------------ 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 2c1f1f2..10c4221 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -180,14 +180,14 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i const nextCategoryLocked = await db.prepare("get", `SELECT "videoID", "category" FROM "lockCategories" WHERE "videoID" = ? AND "category" = ?`, [videoInfo.videoID, category]); if (nextCategoryLocked) { if (!isVIP) { - return res.status(200); + return res.sendStatus(200); } // In an else statement, add a warning in the future for VIPs, that the next category is locked } // Ignore vote if the segment is locked if (!isVIP && videoInfo.locked === 1) { console.log("dalfäkjsdöfbsdfoöjasdökjb"); - return res.status(200); + return res.sendStatus(200); } const nextCategoryInfo = await db.prepare("get", `select votes from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category]); diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index d6a3a77..14751db 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -33,7 +33,7 @@ describe("voteOnSponsorTime", () => { await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, 0, "vote-uuid-3", "testman", 0, 50, "sponsor", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, 0, "vote-uuid-4", "testman", 0, 50, "sponsor", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5", "testman", 0, 50, "intro", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5_1", "testman", 0, 50, "intro", 0, 0]); + //await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5_1", getHash("testman"), 0, 50, "intro", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, 0, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, 0, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, 0, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0]); @@ -292,33 +292,6 @@ describe("voteOnSponsorTime", () => { }); }); - /* - it("VIP should be able to vote for a category and it should immediately change", (done) => { - const UUID = "vote-uuid-5"; - postVoteCategory(vipUser, UUID, "outro") - .then(async res => { - assert.strictEqual(res.status, 200); - const row = await getSegmentCategory(UUID); - const row2 = await db.prepare("get", `SELECT votes FROM "categoryVotes" WHERE "UUID" = ? and category = ?`, [UUID, "outro"]); - assert.strictEqual(row.category, "outro"); - assert.strictEqual(row2.votes, 500); - done(); - }) - .catch(err => done(err)); - }); -// old test - it("Submitter should be able to vote for a category and it should immediately change", (done) => { - const UUID = "vote-uuid-5_1"; - postVoteCategory("testman", UUID, "outro") - .then(async res => { - assert.strictEqual(res.status, 200); - const row = await getSegmentCategory("vote-uuid-5"); - assert.strictEqual(row.category, "outro"); - done(); - }) - .catch(err => done(err)); - });*/ - it("Submitter should be able to vote for a category and it should immediately change (segment unlocked, nextCatgeory unlocked, notVip)", (done) => { const userID = categoryChangeUser; const UUID = "category-change-uuid-1"; @@ -327,7 +300,7 @@ describe("voteOnSponsorTime", () => { .then(async res => { assert.strictEqual(res.status, 200); const row = await getSegmentCategory(UUID); - console.log(row.category) + console.log(row.category); assert.strictEqual(row.category, category); done(); }) @@ -342,7 +315,7 @@ describe("voteOnSponsorTime", () => { .then(async res => { assert.strictEqual(res.status, 200); const row = await getSegmentCategory(UUID); - console.log(row.category) + console.log(row.category); assert.strictEqual(row.category, "intro"); done(); }) @@ -357,7 +330,6 @@ describe("voteOnSponsorTime", () => { .then(async res => { assert.strictEqual(res.status, 200); const row = await getSegmentCategory(UUID); - console.log(row.category) assert.strictEqual(row.category, "intro"); done(); }) @@ -372,7 +344,6 @@ describe("voteOnSponsorTime", () => { .then(async res => { assert.strictEqual(res.status, 200); const row = await getSegmentCategory(UUID); - console.log(row.category) assert.strictEqual(row.category, "intro"); done(); }) From 7135aa33694f437a3fcf5822cf677101eb5b2aa5 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sat, 2 Oct 2021 05:11:26 +0200 Subject: [PATCH 3/7] removing console.log() commands --- src/routes/voteOnSponsorTime.ts | 1 - test/cases/voteOnSponsorTime.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 10c4221..95e6003 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -186,7 +186,6 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i // Ignore vote if the segment is locked if (!isVIP && videoInfo.locked === 1) { - console.log("dalfäkjsdöfbsdfoöjasdökjb"); return res.sendStatus(200); } diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 14751db..82f8375 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -33,7 +33,6 @@ describe("voteOnSponsorTime", () => { await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, 0, "vote-uuid-3", "testman", 0, 50, "sponsor", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, 0, "vote-uuid-4", "testman", 0, 50, "sponsor", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5", "testman", 0, 50, "intro", 0, 0]); - //await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5_1", getHash("testman"), 0, 50, "intro", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, 0, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, 0, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0]); await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, 0, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0]); From 0aa286442f2ec6af95a7c7c340d148ac3d577f81 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sun, 3 Oct 2021 18:53:06 +0200 Subject: [PATCH 4/7] Vip locked segment voting, handle client side Co-authored-by: Ajay Ramachandran --- src/routes/voteOnSponsorTime.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 95e6003..e0f31d0 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -178,10 +178,8 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i // Ignore vote if the next category is locked const nextCategoryLocked = await db.prepare("get", `SELECT "videoID", "category" FROM "lockCategories" WHERE "videoID" = ? AND "category" = ?`, [videoInfo.videoID, category]); - if (nextCategoryLocked) { - if (!isVIP) { - return res.sendStatus(200); - } // In an else statement, add a warning in the future for VIPs, that the next category is locked + if (nextCategoryLocked && !isVIP) { + return res.sendStatus(200); } // Ignore vote if the segment is locked From 178c4d97920431ce1499fb4ef10071e2b04f09b3 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sun, 3 Oct 2021 18:53:34 +0200 Subject: [PATCH 5/7] Remove comment Co-authored-by: Ajay Ramachandran --- test/cases/voteOnSponsorTime.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 82f8375..640e43f 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -348,7 +348,6 @@ describe("voteOnSponsorTime", () => { }) .catch(err => done(err)); }); -//adjbaelrfkbfjgöäkldfgölkndfgölfdngöfkdln it("Vip should be able to vote for a category and it should immediately change (segment unlocked, nextCatgeory unlocked, Vip)", (done) => { const userID = vipUser; const UUID = "category-change-uuid-5"; From 69e321c405a9679fd606afc62b8a7760dd561dcf Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sun, 3 Oct 2021 19:03:49 +0200 Subject: [PATCH 6/7] Improved formatting --- test/cases/voteOnSponsorTime.ts | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 640e43f..377c7d2 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -300,7 +300,7 @@ describe("voteOnSponsorTime", () => { assert.strictEqual(res.status, 200); const row = await getSegmentCategory(UUID); console.log(row.category); - assert.strictEqual(row.category, category); + assert.strictEqual(row.category, category); done(); }) .catch(err => done(err)); @@ -348,6 +348,7 @@ describe("voteOnSponsorTime", () => { }) .catch(err => done(err)); }); + it("Vip should be able to vote for a category and it should immediately change (segment unlocked, nextCatgeory unlocked, Vip)", (done) => { const userID = vipUser; const UUID = "category-change-uuid-5"; @@ -403,22 +404,7 @@ describe("voteOnSponsorTime", () => { }) .catch(err => done(err)); }); - - - - - - - - - - - - - - - - + it("Should not be able to category-vote on an invalid UUID submission", (done) => { const UUID = "invalid-uuid"; postVoteCategory("randomID3", UUID, "intro") From 7e23bc9eeb5c0f048a7af409d12fc68774e5d319 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 3 Oct 2021 13:12:14 -0400 Subject: [PATCH 7/7] Check for service in category vote --- src/routes/voteOnSponsorTime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index eb04ac1..2d12115 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -177,7 +177,7 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i } // Ignore vote if the next category is locked - const nextCategoryLocked = await db.prepare("get", `SELECT "videoID", "category" FROM "lockCategories" WHERE "videoID" = ? AND "category" = ?`, [videoInfo.videoID, category]); + const nextCategoryLocked = await db.prepare("get", `SELECT "videoID", "category" FROM "lockCategories" WHERE "videoID" = ? AND "service" = ? AND "category" = ?`, [videoInfo.videoID, videoInfo.service, category]); if (nextCategoryLocked && !isVIP) { return res.sendStatus(200); }