mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 19:47:00 +03:00
added post and get test to hash prefix
This commit is contained in:
@@ -15,6 +15,8 @@ CREATE TABLE "sqlb_temp_table_3" (
|
||||
"shadowHidden" INTEGER NOT NULL,
|
||||
"hashedVideoID" TEXT NOT NULL
|
||||
);
|
||||
|
||||
/* hash upgade test sha256('vid') = '1ff838dc6ca9680d88455341118157d59a055fe6d0e3870f9c002847bebe4663' */
|
||||
INSERT INTO sqlb_temp_table_3 SELECT *, sha256(videoID) FROM sponsorTimes;
|
||||
|
||||
DROP TABLE sponsorTimes;
|
||||
|
||||
@@ -5,6 +5,7 @@ var path = require('path');
|
||||
var Sqlite = require('./Sqlite.js')
|
||||
var Mysql = require('./Mysql.js');
|
||||
const logger = require('../utils/logger.js');
|
||||
const getHash = require('../utils/getHash.js');
|
||||
|
||||
let options = {
|
||||
readonly: config.readOnly,
|
||||
@@ -34,8 +35,8 @@ if (config.mysql) {
|
||||
}
|
||||
|
||||
if (!config.readOnly) {
|
||||
db.function("sha256", function (string) {
|
||||
return require('crypto').createHash("sha256").update(string).digest("hex");
|
||||
db.function("sha256", (string) => {
|
||||
return getHash(string, 1);
|
||||
});
|
||||
|
||||
// Upgrade database if required
|
||||
|
||||
@@ -13,6 +13,10 @@ describe('getHash', () => {
|
||||
assert.equal(getHash("test"), "2f327ef967ade1ebf4319163f7debbda9cc17bb0c8c834b00b30ca1cf1c256ee");
|
||||
});
|
||||
|
||||
it ('Should be able to output the same has the DB upgrade script will output', () => {
|
||||
assert.equal(getHash("vid", 1), "1ff838dc6ca9680d88455341118157d59a055fe6d0e3870f9c002847bebe4663");
|
||||
});
|
||||
|
||||
it ('Should take a variable number of passes', () => {
|
||||
assert.equal(getHash("test", 1), "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
|
||||
assert.equal(getHash("test", 2), "7b3d979ca8330a94fa7e9e1b466d8b99e0bcdea1ec90596c0dcc8d7ef6b4300c");
|
||||
|
||||
@@ -84,4 +84,40 @@ describe('getSegmentsByHash', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be able to post a segment and get it using endpoint', (done) => {
|
||||
let testID = 'abc123goodVideo';
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
json: {
|
||||
userID: "test",
|
||||
videoID: testID,
|
||||
segments: [{
|
||||
segment: [13, 17],
|
||||
category: "sponsor"
|
||||
}]
|
||||
}
|
||||
},
|
||||
(err, res, body) => {
|
||||
if (err) done('(post) ' + err);
|
||||
else if (res.statusCode === 200) {
|
||||
request.get(utils.getbaseURL()
|
||||
+ '/api/skipSegments/'+getHash(testID, 1).substring(0,3), null,
|
||||
(err, res, body) => {
|
||||
if (err) done("(get) Couldn't call endpoint");
|
||||
else if (res.statusCode !== 200) done("(get) non 200 status code, was " + res.statusCode);
|
||||
else {
|
||||
body = JSON.parse(body);
|
||||
if (body.length !== 1) done("(get) expected 1 video, got " + body.length);
|
||||
else if (body[0].segments.length !== 1) done("(get) expected 1 segments for first video, got " + body[0].segments.length);
|
||||
else if (body[0].segments[0].category !== 'sponsor') done("(get) segment should be sponsor, was "+body[0].segments[0].category);
|
||||
else done();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("(post) non 200 status code, was " + res.statusCode);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user