mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 07:27:01 +03:00
Banned users can't vote
This commit is contained in:
@@ -249,6 +249,7 @@ async function voteOnSponsorTime(req, res) {
|
||||
// Only change the database if they have made a submission before and haven't voted recently
|
||||
let ableToVote = isVIP
|
||||
|| (db.prepare("get", "SELECT userID FROM sponsorTimes WHERE userID = ?", [nonAnonUserID]) !== undefined
|
||||
&& privateDB.prepare("get", "SELECT userID FROM shadowBannedUsers WHERE userID = ?", [nonAnonUserID]) === undefined
|
||||
&& privateDB.prepare("get", "SELECT UUID FROM votes WHERE UUID = ? AND hashedIP = ? AND userID != ?", [UUID, hashedIP, userID]) === undefined);
|
||||
|
||||
if (ableToVote) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var request = require('request');
|
||||
var db = require('../../src/databases/databases.js').db;
|
||||
var utils = require('../utils.js');
|
||||
var getHash = require('../../src/utils/getHash.js')
|
||||
const request = require('request');
|
||||
const { db, privateDB } = require('../../src/databases/databases.js');
|
||||
const utils = require('../utils.js');
|
||||
const getHash = require('../../src/utils/getHash.js');
|
||||
|
||||
describe('voteOnSponsorTime', () => {
|
||||
before(() => {
|
||||
@@ -9,6 +9,7 @@ describe('voteOnSponsorTime', () => {
|
||||
db.exec(startOfQuery + "('vote-testtesttest', 1, 11, 2, 'vote-uuid-0', 'testman', 0, 50, 'sponsor', 0)");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 2, 'vote-uuid-1', 'testman', 0, 50, 'sponsor', 0)");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.5', 'testman', 0, 50, 'outro', 0)");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.6', 'testman', 0, 50, 'interaction', 0)");
|
||||
db.exec(startOfQuery + "('vote-testtesttest3', 20, 33, 10, 'vote-uuid-2', 'testman', 0, 50, 'intro', 0)");
|
||||
db.exec(startOfQuery + "('vote-testtesttest,test', 1, 11, 100, 'vote-uuid-3', 'testman', 0, 50, 'sponsor', 0)");
|
||||
db.exec(startOfQuery + "('vote-test3', 1, 11, 2, 'vote-uuid-4', 'testman', 0, 50, 'sponsor', 0)");
|
||||
@@ -18,8 +19,10 @@ describe('voteOnSponsorTime', () => {
|
||||
db.exec(startOfQuery + "('voter-submitter', 1, 11, 2, 'vote-uuid-8', '" + getHash("randomID") + "', 0, 50, 'sponsor', 0)");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-9', '" + getHash("randomID2") + "', 0, 50, 'sponsor', 0)");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-10', '" + getHash("randomID3") + "', 0, 50, 'sponsor', 0)");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-11', '" + getHash("randomID4") + "', 0, 50, 'sponsor', 0)");
|
||||
|
||||
db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser") + "')");
|
||||
privateDB.exec("INSERT INTO shadowBannedUsers (userID) VALUES ('" + getHash("randomID4") + "')");
|
||||
});
|
||||
|
||||
it('Should be able to upvote a segment', (done) => {
|
||||
@@ -76,6 +79,24 @@ describe('voteOnSponsorTime', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("Should not be able to downvote a segment if the user is shadow banned", (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0", null,
|
||||
(err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
|
||||
if (row.votes === 10) {
|
||||
done()
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1", null,
|
||||
|
||||
Reference in New Issue
Block a user