mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 03:26:59 +03:00
make eslint scream about promises, then fix all lints
also rewrite a bunch of test suites from using done callbacks to using async functions - it's way too easy to forget about a .catch() clause
This commit is contained in:
@@ -31,15 +31,15 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
files: ["src/**/*.ts"],
|
files: ["**/*.ts"],
|
||||||
|
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
project: ["./tsconfig.json"],
|
project: ["./tsconfig.eslint.json"],
|
||||||
},
|
},
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
"@typescript-eslint/no-misused-promises": "warn",
|
"@typescript-eslint/no-misused-promises": "error",
|
||||||
"@typescript-eslint/no-floating-promises" : "warn"
|
"@typescript-eslint/no-floating-promises" : "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ function chooseSegment<T extends DBSegment>(choices: T[]): FullVideoSegmentVideo
|
|||||||
return {
|
return {
|
||||||
segments: transformDBSegments(choices),
|
segments: transformDBSegments(choices),
|
||||||
hasStartSegment
|
hasStartSegment
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
// if locked, only choose from locked
|
// if locked, only choose from locked
|
||||||
const locked = choices.filter((segment) => segment.locked);
|
const locked = choices.filter((segment) => segment.locked);
|
||||||
|
|||||||
@@ -73,11 +73,11 @@ describe("getUserID", () => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
it("Should be able to get multiple fuzzy user info from middle", () => {
|
it("Should be able to get multiple fuzzy user info from middle", () =>
|
||||||
validateSearch("user",
|
validateSearch("user",
|
||||||
[users["fuzzy_1"], users["fuzzy_2"], users["specific_1"]]
|
[users["fuzzy_1"], users["fuzzy_2"], users["specific_1"]]
|
||||||
);
|
)
|
||||||
});
|
);
|
||||||
|
|
||||||
it("Should be able to get with fuzzy public ID", () => {
|
it("Should be able to get with fuzzy public ID", () => {
|
||||||
const userID = users["public_1"].pubID.substring(0,60);
|
const userID = users["public_1"].pubID.substring(0,60);
|
||||||
@@ -117,4 +117,4 @@ describe("getUserID 400/ 404", () => {
|
|||||||
it("Should not allow usernames less than 3 characters", () => validateStatus("aa", 400));
|
it("Should not allow usernames less than 3 characters", () => validateStatus("aa", 400));
|
||||||
it("Should return 404 if escaped backslashes present", () => validateStatus("%redos\\\\_", 404));
|
it("Should return 404 if escaped backslashes present", () => validateStatus("%redos\\\\_", 404));
|
||||||
it("Should return 404 if backslashes present", () => validateStatus(`\\%redos\\_`, 404));
|
it("Should return 404 if backslashes present", () => validateStatus(`\\%redos\\_`, 404));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -81,19 +81,19 @@ describe("getUserInfo", () => {
|
|||||||
|
|
||||||
// warnings & bans
|
// warnings & bans
|
||||||
// warn-0
|
// warn-0
|
||||||
insertWarning(db, users["warn-0"].pubID, { reason: "warning0-0", issueTime: 10 });
|
await insertWarning(db, users["warn-0"].pubID, { reason: "warning0-0", issueTime: 10 });
|
||||||
// warn-1
|
// warn-1
|
||||||
insertWarning(db, users["warn-1"].pubID, { reason: "warning1-0", issueTime: 20 });
|
await insertWarning(db, users["warn-1"].pubID, { reason: "warning1-0", issueTime: 20 });
|
||||||
insertWarning(db, users["warn-1"].pubID, { reason: "warning1-1", issueTime: 30 });
|
await insertWarning(db, users["warn-1"].pubID, { reason: "warning1-1", issueTime: 30 });
|
||||||
// warn -2
|
// warn -2
|
||||||
insertWarning(db, users["warn-2"].pubID, { reason: "warning2-0", issueTime: 40, enabled: false });
|
await insertWarning(db, users["warn-2"].pubID, { reason: "warning2-0", issueTime: 40, enabled: false });
|
||||||
// warn-3
|
// warn-3
|
||||||
insertWarning(db, users["warn-3"].pubID, { reason: "warning3-0", issueTime: 50 });
|
await insertWarning(db, users["warn-3"].pubID, { reason: "warning3-0", issueTime: 50 });
|
||||||
insertWarning(db, users["warn-3"].pubID, { reason: "warning3-1", issueTime: 60, enabled: false });
|
await insertWarning(db, users["warn-3"].pubID, { reason: "warning3-1", issueTime: 60, enabled: false });
|
||||||
|
|
||||||
// ban-
|
// ban-
|
||||||
insertBan(db, users["ban-1"].pubID);
|
await insertBan(db, users["ban-1"].pubID);
|
||||||
insertBan(db, users["ban-2"].pubID);
|
await insertBan(db, users["ban-2"].pubID);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", () => statusTest(200, { userID: users["n-1"].privID }));
|
it("Should be able to get a 200", () => statusTest(200, { userID: users["n-1"].privID }));
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ describe("postBranding", () => {
|
|||||||
const userID5 = `PostBrandingUser5${".".repeat(16)}`;
|
const userID5 = `PostBrandingUser5${".".repeat(16)}`;
|
||||||
const userID6 = `PostBrandingUser6${".".repeat(16)}`;
|
const userID6 = `PostBrandingUser6${".".repeat(16)}`;
|
||||||
const userID7 = `PostBrandingUser7${".".repeat(16)}`;
|
const userID7 = `PostBrandingUser7${".".repeat(16)}`;
|
||||||
const userID8 = `PostBrandingUser8${".".repeat(16)}`;
|
|
||||||
const bannedUser = `BannedPostBrandingUser${".".repeat(16)}`;
|
const bannedUser = `BannedPostBrandingUser${".".repeat(16)}`;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,11 @@
|
|||||||
import { getHash } from "../../src/utils/getHash";
|
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import { client } from "../utils/httpClient";
|
import { client } from "../utils/httpClient";
|
||||||
|
import { usersForSuite } from "../utils/randomUsers";
|
||||||
|
|
||||||
describe("postSkipSegments Warnings", () => {
|
describe("postSkipSegments Warnings", () => {
|
||||||
// Constant and helpers
|
// Constant and helpers
|
||||||
const warnUser01 = "warn-user01";
|
const users = usersForSuite("postSkipSegmentsWarnings");
|
||||||
const warnUser01Hash = getHash(warnUser01);
|
|
||||||
const warnUser02 = "warn-user02";
|
|
||||||
const warnUser02Hash = getHash(warnUser02);
|
|
||||||
const warnUser03 = "warn-user03";
|
|
||||||
const warnUser03Hash = getHash(warnUser03);
|
|
||||||
const warnUser04 = "warn-user04";
|
|
||||||
const warnUser04Hash = getHash(warnUser04);
|
|
||||||
|
|
||||||
const warnVideoID = "postSkipSegments-warn-video";
|
const warnVideoID = "postSkipSegments-warn-video";
|
||||||
|
|
||||||
const endpoint = "/api/skipSegments";
|
const endpoint = "/api/skipSegments";
|
||||||
@@ -26,107 +18,89 @@ describe("postSkipSegments Warnings", () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
const warnVip01Hash = getHash("postSkipSegmentsWarnVIP");
|
|
||||||
|
|
||||||
const reason01 = "Reason01";
|
const reason01 = "Reason01";
|
||||||
const reason02 = "";
|
const reason02 = "";
|
||||||
const reason03 = "Reason03";
|
const reason03 = "Reason03";
|
||||||
|
|
||||||
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issuerUserID", "enabled", "reason", "issueTime") VALUES(?, ?, ?, ?, ?)';
|
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issuerUserID", "enabled", "reason", "issueTime") VALUES(?, ?, ?, ?, ?)';
|
||||||
// User 1 | 1 active | custom reason
|
// User 1 | 1 active | custom reason
|
||||||
await db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, now]);
|
await db.prepare("run", insertWarningQuery, [users.u01.public, users.vip01.public, 1, reason01, now]);
|
||||||
// User 2 | 1 inactive | default reason
|
// User 2 | 1 inactive | default reason
|
||||||
await db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 0, reason02, now]);
|
await db.prepare("run", insertWarningQuery, [users.u02.public, users.vip01.public, 0, reason02, now]);
|
||||||
// User 3 | 1 inactive, 1 active | different reasons
|
// User 3 | 1 inactive, 1 active | different reasons
|
||||||
await db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason01, now]);
|
await db.prepare("run", insertWarningQuery, [users.u03.public, users.vip01.public, 0, reason01, now]);
|
||||||
await db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, now+1]);
|
await db.prepare("run", insertWarningQuery, [users.u03.public, users.vip01.public, 1, reason03, now+1]);
|
||||||
// User 4 | 1 active | default reason
|
// User 4 | 1 active | default reason
|
||||||
await db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 1, reason02, now]);
|
await db.prepare("run", insertWarningQuery, [users.u04.public, users.vip01.public, 1, reason02, now]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected with custom message if user has active warnings", (done) => {
|
it("Should be rejected with custom message if user has active warnings", async () => {
|
||||||
postSkipSegmentJSON({
|
const res = await postSkipSegmentJSON({
|
||||||
userID: warnUser01,
|
userID: users.u01.private,
|
||||||
videoID: warnVideoID,
|
videoID: warnVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
})
|
});
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 403);
|
||||||
assert.strictEqual(res.status, 403);
|
const errorMessage = res.data;
|
||||||
const errorMessage = res.data;
|
const reason = "Reason01";
|
||||||
const reason = "Reason01";
|
const expected = "Submission rejected due to a tip from a moderator. This means that we noticed you were making some common mistakes"
|
||||||
const expected = "Submission rejected due to a tip from a moderator. This means that we noticed you were making some common mistakes"
|
+ " that are not malicious, and we just want to clarify the rules. "
|
||||||
+ " that are not malicious, and we just want to clarify the rules. "
|
+ "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? "
|
||||||
+ "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? "
|
+ `Your userID is ${users.u01.public}.\n\nTip message: '${reason}'`;
|
||||||
+ `Your userID is ${warnUser01Hash}.\n\nTip message: '${reason}'`;
|
|
||||||
|
|
||||||
assert.strictEqual(errorMessage, expected);
|
assert.strictEqual(errorMessage, expected);
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be accepted if user has inactive warning", (done) => {
|
it("Should be accepted if user has inactive warning", async () => {
|
||||||
postSkipSegmentJSON({
|
const res = await postSkipSegmentJSON({
|
||||||
userID: warnUser02,
|
userID: users.u02.private,
|
||||||
videoID: warnVideoID,
|
videoID: warnVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [50, 60],
|
segment: [50, 60],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
})
|
});
|
||||||
.then(res => {
|
assert.ok(res.status === 200, `Status code was ${res.status} ${res.data}`);
|
||||||
assert.ok(res.status === 200, `Status code was ${res.status} ${res.data}`);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected with custom message if user has active warnings, even if has one inactive warning, should use current message", (done) => {
|
it("Should be rejected with custom message if user has active warnings, even if has one inactive warning, should use current message", async () => {
|
||||||
postSkipSegmentJSON({
|
const res = await postSkipSegmentJSON({
|
||||||
userID: warnUser03,
|
userID: users.u03.private,
|
||||||
videoID: warnVideoID,
|
videoID: warnVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [10, 20],
|
segment: [10, 20],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
})
|
});
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 403);
|
||||||
assert.strictEqual(res.status, 403);
|
const errorMessage = res.data;
|
||||||
const errorMessage = res.data;
|
const reason = "Reason03";
|
||||||
const reason = "Reason03";
|
const expected = "Submission rejected due to a tip from a moderator. This means that we noticed you were making some common mistakes"
|
||||||
const expected = "Submission rejected due to a tip from a moderator. This means that we noticed you were making some common mistakes"
|
+ " that are not malicious, and we just want to clarify the rules. "
|
||||||
+ " that are not malicious, and we just want to clarify the rules. "
|
+ "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? "
|
||||||
+ "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? "
|
+ `Your userID is ${users.u03.public}.\n\nTip message: '${reason}'`;
|
||||||
+ `Your userID is ${warnUser03Hash}.\n\nTip message: '${reason}'`;
|
|
||||||
|
|
||||||
assert.strictEqual(errorMessage, expected);
|
assert.strictEqual(errorMessage, expected);
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected with default message if user has active warning", (done) => {
|
it("Should be rejected with default message if user has active warning", async () => {
|
||||||
postSkipSegmentJSON({
|
const res = await postSkipSegmentJSON({
|
||||||
userID: warnUser04,
|
userID: users.u04.private,
|
||||||
videoID: warnVideoID,
|
videoID: warnVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
})
|
});
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 403);
|
||||||
assert.strictEqual(res.status, 403);
|
const errorMessage = res.data;
|
||||||
const errorMessage = res.data;
|
const expected = "Submission rejected due to a tip from a moderator. This means that we noticed you were making some common mistakes"
|
||||||
const expected = "Submission rejected due to a tip from a moderator. This means that we noticed you were making some common mistakes"
|
+ " that are not malicious, and we just want to clarify the rules. "
|
||||||
+ " that are not malicious, and we just want to clarify the rules. "
|
+ "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? "
|
||||||
+ "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? "
|
+ `Your userID is ${users.u04.public}.`;
|
||||||
+ `Your userID is ${warnUser04Hash}.`;
|
assert.strictEqual(errorMessage, expected);
|
||||||
assert.strictEqual(errorMessage, expected);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,73 +34,61 @@ describe("postWarning", () => {
|
|||||||
await db.prepare("run", insertWarningQuery, [users.u14.public, users.vip1.public, 1, "another reason 14", Date.now()]);
|
await db.prepare("run", insertWarningQuery, [users.u14.public, users.vip1.public, 1, "another reason 14", Date.now()]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to create warning if vip (exp 200)", (done) => {
|
it("Should be able to create warning if vip (exp 200)", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip1.private,
|
issuerUserID: users.vip1.private,
|
||||||
userID: users.u0.public,
|
userID: users.u0.public,
|
||||||
reason: "warning-reason-0"
|
reason: "warning-reason-0"
|
||||||
};
|
};
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = {
|
||||||
const expected = {
|
enabled: 1,
|
||||||
enabled: 1,
|
issuerUserID: getHash(json.issuerUserID),
|
||||||
issuerUserID: getHash(json.issuerUserID),
|
reason: json.reason,
|
||||||
reason: json.reason,
|
};
|
||||||
};
|
assert.equal(row.length, 1);
|
||||||
assert.equal(row.length, 1);
|
assert.ok(partialDeepEquals(row[0], expected));
|
||||||
assert.ok(partialDeepEquals(row[0], expected));
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be not be able to edit a warning if past deadline and same vip", (done) => {
|
it("Should be not be able to edit a warning if past deadline and same vip", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip1.private,
|
issuerUserID: users.vip1.private,
|
||||||
userID: users.u1.public,
|
userID: users.u1.public,
|
||||||
reason: "edited reason 1",
|
reason: "edited reason 1",
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 409);
|
||||||
assert.strictEqual(res.status, 409);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = {
|
||||||
const expected = {
|
enabled: 1,
|
||||||
enabled: 1,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
};
|
||||||
};
|
assert.equal(row.length, 1);
|
||||||
assert.equal(row.length, 1);
|
assert.ok(partialDeepEquals(row[0], expected));
|
||||||
assert.ok(partialDeepEquals(row[0], expected));
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be not be able to edit a warning if past deadline and different vip", (done) => {
|
it("Should be not be able to edit a warning if past deadline and different vip", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip2.private,
|
issuerUserID: users.vip2.private,
|
||||||
userID: users.u2.public,
|
userID: users.u2.public,
|
||||||
reason: "edited reason 2",
|
reason: "edited reason 2",
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 409);
|
||||||
assert.strictEqual(res.status, 409);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = {
|
||||||
const expected = {
|
enabled: 1,
|
||||||
enabled: 1,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
};
|
||||||
};
|
assert.equal(row.length, 1);
|
||||||
assert.equal(row.length, 1);
|
assert.ok(partialDeepEquals(row[0], expected));
|
||||||
assert.ok(partialDeepEquals(row[0], expected));
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to remove warning if same vip as issuer", (done) => {
|
it("Should be able to remove warning if same vip as issuer", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip1.private,
|
issuerUserID: users.vip1.private,
|
||||||
userID: users.u3.public,
|
userID: users.u3.public,
|
||||||
@@ -108,24 +96,20 @@ describe("postWarning", () => {
|
|||||||
};
|
};
|
||||||
const beforeTime = Date.now();
|
const beforeTime = Date.now();
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
const afterTime = Date.now();
|
||||||
const afterTime = Date.now();
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = {
|
||||||
const expected = {
|
enabled: 0
|
||||||
enabled: 0
|
};
|
||||||
};
|
assert.equal(row.length, 1);
|
||||||
assert.equal(row.length, 1);
|
assert.ok(partialDeepEquals(row[0], expected));
|
||||||
assert.ok(partialDeepEquals(row[0], expected));
|
// check disableTime
|
||||||
// check disableTime
|
assert.ok(row[0].disableTime >= beforeTime && row[0].disableTime <= afterTime, "expected disableTime to be somewhere between execution start and end");
|
||||||
assert.ok(row[0].disableTime >= beforeTime && row[0].disableTime <= afterTime, "expected disableTime to be somewhere between execution start and end");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to remove warning if not the same vip as issuer", (done) => {
|
it("Should be able to remove warning if not the same vip as issuer", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip2.private,
|
issuerUserID: users.vip2.private,
|
||||||
userID: users.u4.public,
|
userID: users.u4.public,
|
||||||
@@ -133,119 +117,91 @@ describe("postWarning", () => {
|
|||||||
};
|
};
|
||||||
const beforeTime = Date.now();
|
const beforeTime = Date.now();
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
const afterTime = Date.now();
|
||||||
const afterTime = Date.now();
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = {
|
||||||
const expected = {
|
enabled: 0
|
||||||
enabled: 0
|
};
|
||||||
};
|
assert.equal(row.length, 1);
|
||||||
assert.equal(row.length, 1);
|
assert.ok(partialDeepEquals(row[0], expected));
|
||||||
assert.ok(partialDeepEquals(row[0], expected));
|
// check disableTime
|
||||||
// check disableTime
|
assert.ok(row[0].disableTime >= beforeTime && row[0].disableTime <= afterTime, "expected disableTime to be somewhere between execution start and end");
|
||||||
assert.ok(row[0].disableTime >= beforeTime && row[0].disableTime <= afterTime, "expected disableTime to be somewhere between execution start and end");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to create warning if not vip (exp 403)", (done) => {
|
it("Should not be able to create warning if not vip (exp 403)", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.nonvip.private,
|
issuerUserID: users.nonvip.private,
|
||||||
userID: users.u5.public,
|
userID: users.u5.public,
|
||||||
reason: "warn reason 5",
|
reason: "warn reason 5",
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 403);
|
||||||
assert.strictEqual(res.status, 403);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if missing body", (done) => {
|
it("Should return 400 if missing body", async () => {
|
||||||
client.post(endpoint, {})
|
const res = await client.post(endpoint, {});
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to remove your own warning", (done) => {
|
it("Should be able to remove your own warning", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
userID: users.u6.private,
|
userID: users.u6.private,
|
||||||
enabled: false
|
enabled: false
|
||||||
};
|
};
|
||||||
const beforeTime = Date.now();
|
const beforeTime = Date.now();
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
const afterTime = Date.now();
|
||||||
const afterTime = Date.now();
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getWarning(users.u6.public);
|
||||||
const row = await getWarning(users.u6.public);
|
const expected = {
|
||||||
const expected = {
|
enabled: 0
|
||||||
enabled: 0
|
};
|
||||||
};
|
assert.equal(row.length, 1);
|
||||||
assert.equal(row.length, 1);
|
assert.ok(partialDeepEquals(row[0], expected));
|
||||||
assert.ok(partialDeepEquals(row[0], expected));
|
// check disableTime
|
||||||
// check disableTime
|
assert.ok(row[0].disableTime >= beforeTime && row[0].disableTime <= afterTime, "expected disableTime to be somewhere between execution start and end");
|
||||||
assert.ok(row[0].disableTime >= beforeTime && row[0].disableTime <= afterTime, "expected disableTime to be somewhere between execution start and end");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to add your own warning", (done) => {
|
it("Should not be able to add your own warning", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
userID: users.u7.private,
|
userID: users.u7.private,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
reason: "warn reason 7",
|
reason: "warn reason 7",
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 403);
|
||||||
assert.strictEqual(res.status, 403);
|
const data = await getWarning(users.u7.public);
|
||||||
const data = await getWarning(users.u7.public);
|
assert.equal(data.length, 0);
|
||||||
assert.equal(data.length, 0);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to warn a user without reason", (done) => {
|
it("Should not be able to warn a user without reason", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip1.private,
|
issuerUserID: users.vip1.private,
|
||||||
userID: users.u8.public,
|
userID: users.u8.public,
|
||||||
enabled: true
|
enabled: true
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to re-warn a user without reason", (done) => {
|
it("Should not be able to re-warn a user without reason", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip1.private,
|
issuerUserID: users.vip1.private,
|
||||||
userID: users.u9.public,
|
userID: users.u9.public,
|
||||||
enabled: true
|
enabled: true
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to edit a warning if within deadline and same vip", (done) => {
|
it("Should be able to edit a warning if within deadline and same vip", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip1.private,
|
issuerUserID: users.vip1.private,
|
||||||
userID: users.u10.public,
|
userID: users.u10.public,
|
||||||
@@ -253,23 +209,19 @@ describe("postWarning", () => {
|
|||||||
reason: "edited reason 10",
|
reason: "edited reason 10",
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = {
|
||||||
const expected = {
|
enabled: 1,
|
||||||
enabled: 1,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
reason: json.reason,
|
||||||
reason: json.reason,
|
};
|
||||||
};
|
assert.equal(row.length, 1);
|
||||||
assert.equal(row.length, 1);
|
assert.ok(partialDeepEquals(row[0], expected));
|
||||||
assert.ok(partialDeepEquals(row[0], expected));
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to edit a warning if within deadline and different vip", (done) => {
|
it("Should not be able to edit a warning if within deadline and different vip", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip2.private,
|
issuerUserID: users.vip2.private,
|
||||||
userID: users.u11.public,
|
userID: users.u11.public,
|
||||||
@@ -277,23 +229,19 @@ describe("postWarning", () => {
|
|||||||
reason: "edited reason 11",
|
reason: "edited reason 11",
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 409);
|
||||||
assert.strictEqual(res.status, 409);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = {
|
||||||
const expected = {
|
enabled: 1,
|
||||||
enabled: 1,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
reason: "warn reason 11",
|
||||||
reason: "warn reason 11",
|
};
|
||||||
};
|
assert.equal(row.length, 1);
|
||||||
assert.equal(row.length, 1);
|
assert.ok(partialDeepEquals(row[0], expected));
|
||||||
assert.ok(partialDeepEquals(row[0], expected));
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to warn a previously warned user again (same vip)", (done) => {
|
it("Should be able to warn a previously warned user again (same vip)", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip1.private,
|
issuerUserID: users.vip1.private,
|
||||||
userID: users.u12.public,
|
userID: users.u12.public,
|
||||||
@@ -301,31 +249,27 @@ describe("postWarning", () => {
|
|||||||
reason: "new reason 12",
|
reason: "new reason 12",
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = [
|
||||||
const expected = [
|
{
|
||||||
{
|
enabled: 0,
|
||||||
enabled: 0,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
reason: "warn reason 12",
|
||||||
reason: "warn reason 12",
|
},
|
||||||
},
|
{
|
||||||
{
|
enabled: 1,
|
||||||
enabled: 1,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
reason: "new reason 12",
|
||||||
reason: "new reason 12",
|
}
|
||||||
}
|
];
|
||||||
];
|
assert.equal(row.length, 2);
|
||||||
assert.equal(row.length, 2);
|
assert.ok(partialDeepEquals(row[0], expected[0]), "warning 1");
|
||||||
assert.ok(partialDeepEquals(row[0], expected[0]), "warning 1");
|
assert.ok(partialDeepEquals(row[1], expected[1]), "warning 2");
|
||||||
assert.ok(partialDeepEquals(row[1], expected[1]), "warning 2");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to warn a previously warned user again (different vip)", (done) => {
|
it("Should be able to warn a previously warned user again (different vip)", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip2.private,
|
issuerUserID: users.vip2.private,
|
||||||
userID: users.u13.public,
|
userID: users.u13.public,
|
||||||
@@ -333,31 +277,27 @@ describe("postWarning", () => {
|
|||||||
reason: "new reason 13",
|
reason: "new reason 13",
|
||||||
};
|
};
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = [
|
||||||
const expected = [
|
{
|
||||||
{
|
enabled: 0,
|
||||||
enabled: 0,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
reason: "warn reason 13",
|
||||||
reason: "warn reason 13",
|
},
|
||||||
},
|
{
|
||||||
{
|
enabled: 1,
|
||||||
enabled: 1,
|
issuerUserID: users.vip2.public,
|
||||||
issuerUserID: users.vip2.public,
|
reason: "new reason 13",
|
||||||
reason: "new reason 13",
|
}
|
||||||
}
|
];
|
||||||
];
|
assert.equal(row.length, 2);
|
||||||
assert.equal(row.length, 2);
|
assert.ok(partialDeepEquals(row[0], expected[0]), "warning 1");
|
||||||
assert.ok(partialDeepEquals(row[0], expected[0]), "warning 1");
|
assert.ok(partialDeepEquals(row[1], expected[1]), "warning 2");
|
||||||
assert.ok(partialDeepEquals(row[1], expected[1]), "warning 2");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Disabling a warning should only set disableTime for the active warning", (done) => {
|
it("Disabling a warning should only set disableTime for the active warning", async () => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: users.vip2.private,
|
issuerUserID: users.vip2.private,
|
||||||
userID: users.u14.public,
|
userID: users.u14.public,
|
||||||
@@ -365,31 +305,27 @@ describe("postWarning", () => {
|
|||||||
};
|
};
|
||||||
const beforeTime = Date.now();
|
const beforeTime = Date.now();
|
||||||
|
|
||||||
client.post(endpoint, json)
|
const res = await client.post(endpoint, json);
|
||||||
.then(async res => {
|
const afterTime = Date.now();
|
||||||
const afterTime = Date.now();
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getWarning(json.userID);
|
||||||
const row = await getWarning(json.userID);
|
const expected = [
|
||||||
const expected = [
|
{
|
||||||
{
|
enabled: 0,
|
||||||
enabled: 0,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
reason: "warn reason 14",
|
||||||
reason: "warn reason 14",
|
disableTime: 12345,
|
||||||
disableTime: 12345,
|
},
|
||||||
},
|
{
|
||||||
{
|
enabled: 0,
|
||||||
enabled: 0,
|
issuerUserID: users.vip1.public,
|
||||||
issuerUserID: users.vip1.public,
|
reason: "another reason 14",
|
||||||
reason: "another reason 14",
|
}
|
||||||
}
|
];
|
||||||
];
|
assert.equal(row.length, 2);
|
||||||
assert.equal(row.length, 2);
|
assert.ok(partialDeepEquals(row[0], expected[0]), "warning 1");
|
||||||
assert.ok(partialDeepEquals(row[0], expected[0]), "warning 1");
|
assert.ok(partialDeepEquals(row[1], expected[1]), "warning 2");
|
||||||
assert.ok(partialDeepEquals(row[1], expected[1]), "warning 2");
|
// check disableTime
|
||||||
// check disableTime
|
assert.ok(row[1].disableTime >= beforeTime && row[1].disableTime <= afterTime, "expected disableTime to be somewhere between execution start and end");
|
||||||
assert.ok(row[1].disableTime >= beforeTime && row[1].disableTime <= afterTime, "expected disableTime to be somewhere between execution start and end");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,44 +9,32 @@ const randKey2 = genRandom(16);
|
|||||||
const randKey3 = genRandom();
|
const randKey3 = genRandom();
|
||||||
const randValue3 = genRandom();
|
const randValue3 = genRandom();
|
||||||
|
|
||||||
const redisGetCheck = (key: string, expected: string | null, done: Mocha.Done): Promise<void> =>
|
|
||||||
redis.get(key)
|
|
||||||
.then(res => {
|
|
||||||
assert.strictEqual(res, expected);
|
|
||||||
done();
|
|
||||||
}).catch(err => done(err));
|
|
||||||
|
|
||||||
describe("redis test", function() {
|
describe("redis test", function() {
|
||||||
before(async function() {
|
before(async function() {
|
||||||
if (!config.redis?.enabled) this.skip();
|
if (!config.redis?.enabled) this.skip();
|
||||||
await redis.set(randKey1, randValue1);
|
await redis.set(randKey1, randValue1);
|
||||||
});
|
});
|
||||||
it("Should get stored value", (done) => {
|
it("Should get stored value", async () => {
|
||||||
redisGetCheck(randKey1, randValue1, done);
|
const res = await redis.get(randKey1);
|
||||||
|
assert.strictEqual(res, randValue1);
|
||||||
});
|
});
|
||||||
it("Should not be able to get not stored value", (done) => {
|
it("Should not be able to get not stored value", async () => {
|
||||||
redis.get(randKey2)
|
const res = await redis.get(randKey2);
|
||||||
.then(res => {
|
assert.strictEqual(res, null, "Value should not be found");
|
||||||
if (res) done("Value should not be found");
|
|
||||||
done();
|
|
||||||
}).catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should be able to delete stored value", (done) => {
|
it("Should be able to delete stored value", async () => {
|
||||||
redis.del(randKey1)
|
await redis.del(randKey1);
|
||||||
.catch(err => done(err))
|
const res = await redis.get(randKey1);
|
||||||
.then(() => redisGetCheck(randKey1, null, done));
|
assert.strictEqual(res, null, "Deleted key should not be found");
|
||||||
});
|
});
|
||||||
it("Should be able to set expiring value", (done) => {
|
it("Should be able to set expiring value", async () => {
|
||||||
redis.setEx(randKey3, 8400, randValue3)
|
await redis.setEx(randKey3, 8400, randValue3);
|
||||||
.catch(err => done(err))
|
const res = await redis.get(randKey3);
|
||||||
.then(() => redisGetCheck(randKey3, randValue3, done));
|
assert.strictEqual(res, randValue3);
|
||||||
});
|
});
|
||||||
it("Should continue when undefined value is fetched", (done) => {
|
it("Should continue when undefined value is fetched", async () => {
|
||||||
const undefkey = `undefined.${genRandom()}`;
|
const undefkey = `undefined.${genRandom()}`;
|
||||||
redis.get(undefkey)
|
const res = await redis.get(undefkey);
|
||||||
.then(result => {
|
assert.strictEqual(res, null);
|
||||||
assert.ok(!result); // result should be falsy
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,12 +56,11 @@ function wellFormatUserName(userName: string) {
|
|||||||
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
|
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testUserNameChangelog(userID: string, newUserName: string, oldUserName: string, byAdmin: boolean, done: Mocha.Done) {
|
async function testUserNameChangelog(userID: string, newUserName: string, oldUserName: string, byAdmin: boolean) {
|
||||||
const log = await getLastLogUserNameChange(userID);
|
const log = await getLastLogUserNameChange(userID);
|
||||||
assert.strictEqual(newUserName, log.newUserName);
|
assert.strictEqual(newUserName, log.newUserName);
|
||||||
assert.strictEqual(oldUserName, log.oldUserName);
|
assert.strictEqual(oldUserName, log.oldUserName);
|
||||||
assert.strictEqual(byAdmin, Boolean(log.updatedByAdmin));
|
assert.strictEqual(byAdmin, Boolean(log.updatedByAdmin));
|
||||||
return done();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const endpoint = "/api/setUsername";
|
const endpoint = "/api/setUsername";
|
||||||
@@ -111,147 +110,104 @@ describe("setUsername", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to set username that has never been set", (done) => {
|
it("Should be able to set username that has never been set", async () => {
|
||||||
postSetUserName(user00PrivateUserID, username00)
|
const res = await postSetUserName(user00PrivateUserID, username00);
|
||||||
.then(async res => {
|
const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID));
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID));
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(usernameInfo.userName, username00);
|
||||||
assert.strictEqual(usernameInfo.userName, username00);
|
assert.notStrictEqual(usernameInfo.locked, 1, "username should not be locked");
|
||||||
assert.notStrictEqual(usernameInfo.locked, 1, "username should not be locked");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 200", (done) => {
|
it("Should return 200", async () => {
|
||||||
const username = "Changed%20Username";
|
const username = "Changed%20Username";
|
||||||
postSetUserName(user01PrivateUserID, username)
|
const res = await postSetUserName(user01PrivateUserID, username);
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
await testUserNameChangelog(user01PrivateUserID, username, username01, false);
|
||||||
testUserNameChangelog(user01PrivateUserID, username, username01, false, done);
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for missing param "userID"', (done) => {
|
it('Should return 400 for missing param "userID"', async () => {
|
||||||
client({
|
const res = await client({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: endpoint,
|
url: endpoint,
|
||||||
data: {
|
data: {
|
||||||
userName: "MyUsername"
|
userName: "MyUsername"
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for missing param "username"', (done) => {
|
it('Should return 400 for missing param "username"', async () => {
|
||||||
client({
|
const res = await client({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: endpoint,
|
url: endpoint,
|
||||||
data: {
|
data: {
|
||||||
userID: "test"
|
userID: "test"
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for "username" longer then 64 characters', (done) => {
|
it('Should return 400 for "username" longer then 64 characters', async () => {
|
||||||
const username65 = "0000000000000000000000000000000000000000000000000000000000000000X";
|
const username65 = "0000000000000000000000000000000000000000000000000000000000000000X";
|
||||||
postSetUserName("test", username65)
|
const res = await postSetUserName("test", username65);
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not change username if it contains "discord"', (done) => {
|
it('Should not change username if it contains "discord"', async () => {
|
||||||
const newUsername = "discord.me";
|
const newUsername = "discord.me";
|
||||||
postSetUserName(user02PrivateUserID, newUsername)
|
const res = await postSetUserName(user02PrivateUserID, newUsername);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const userNameInfo = await getUsernameInfo(getHash(user02PrivateUserID));
|
||||||
const userNameInfo = await getUsernameInfo(getHash(user02PrivateUserID));
|
assert.notStrictEqual(userNameInfo.userName, newUsername);
|
||||||
assert.notStrictEqual(userNameInfo.userName, newUsername);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to change username", (done) => {
|
it("Should be able to change username", async () => {
|
||||||
const newUsername = "newUsername";
|
const newUsername = "newUsername";
|
||||||
postSetUserName(user03PrivateUserID, newUsername)
|
await postSetUserName(user03PrivateUserID, newUsername);
|
||||||
.then(async () => {
|
const usernameInfo = await getUsernameInfo(getHash(user03PrivateUserID));
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user03PrivateUserID));
|
assert.strictEqual(usernameInfo.userName, newUsername, "Username should change");
|
||||||
assert.strictEqual(usernameInfo.userName, newUsername, "Username should change");
|
assert.notStrictEqual(usernameInfo.locked, 1, "Username should not be locked");
|
||||||
assert.notStrictEqual(usernameInfo.locked, 1, "Username should not be locked");
|
await testUserNameChangelog(user03PrivateUserID, newUsername, username03, false);
|
||||||
testUserNameChangelog(user03PrivateUserID, newUsername, username03, false, done);
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to change locked username", (done) => {
|
it("Should not be able to change locked username", async () => {
|
||||||
const newUsername = "newUsername";
|
const newUsername = "newUsername";
|
||||||
postSetUserName(user04PrivateUserID, newUsername)
|
await postSetUserName(user04PrivateUserID, newUsername);
|
||||||
.then(async () => {
|
const usernameInfo = await getUsernameInfo(getHash(user04PrivateUserID));
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user04PrivateUserID));
|
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not be changed");
|
||||||
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not be changed");
|
assert.strictEqual(usernameInfo.locked, 1, "username should be locked");
|
||||||
assert.strictEqual(usernameInfo.locked, 1, "username should be locked");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should filter out unicode control characters", (done) => {
|
it("Should filter out unicode control characters", async () => {
|
||||||
const newUsername = "This\nUsername+has\tInvalid+Characters";
|
const newUsername = "This\nUsername+has\tInvalid+Characters";
|
||||||
postSetUserName(user05PrivateUserID, newUsername)
|
await postSetUserName(user05PrivateUserID, newUsername);
|
||||||
.then(async () => {
|
const usernameInfo = await getUsernameInfo(getHash(user05PrivateUserID));
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user05PrivateUserID));
|
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not contain control characters");
|
||||||
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not contain control characters");
|
await testUserNameChangelog(user05PrivateUserID, wellFormatUserName(newUsername), username05, false);
|
||||||
testUserNameChangelog(user05PrivateUserID, wellFormatUserName(newUsername), username05, false, done);
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Incorrect adminUserID should return 403", (done) => {
|
it("Incorrect adminUserID should return 403", async () => {
|
||||||
const newUsername = "New Username";
|
const newUsername = "New Username";
|
||||||
postSetUserNameAdmin(getHash(user06PrivateUserID), newUsername,"invalidAdminID")
|
const res = await postSetUserNameAdmin(getHash(user06PrivateUserID), newUsername,"invalidAdminID");
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 403);
|
||||||
assert.strictEqual(res.status, 403);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Admin should be able to change username", (done) => {
|
it("Admin should be able to change username", async () => {
|
||||||
const newUsername = "New Username";
|
const newUsername = "New Username";
|
||||||
postSetUserNameAdmin(getHash(user06PrivateUserID), newUsername, adminPrivateUserID)
|
await postSetUserNameAdmin(getHash(user06PrivateUserID), newUsername, adminPrivateUserID);
|
||||||
.then(async () => {
|
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
assert.strictEqual(usernameInfo.userName, newUsername, "username should be changed");
|
||||||
assert.strictEqual(usernameInfo.userName, newUsername, "username should be changed");
|
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
||||||
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
await testUserNameChangelog(user06PrivateUserID, newUsername, username06, true);
|
||||||
testUserNameChangelog(user06PrivateUserID, newUsername, username06, true, done);
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Admin should be able to change locked username", (done) => {
|
it("Admin should be able to change locked username", async () => {
|
||||||
const newUsername = "New Username";
|
const newUsername = "New Username";
|
||||||
postSetUserNameAdmin(getHash(user07PrivateUserID), newUsername, adminPrivateUserID)
|
await postSetUserNameAdmin(getHash(user07PrivateUserID), newUsername, adminPrivateUserID);
|
||||||
.then(async () => {
|
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
assert.strictEqual(usernameInfo.userName, newUsername, "Username should be changed");
|
||||||
assert.strictEqual(usernameInfo.userName, newUsername, "Username should be changed");
|
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
||||||
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
await testUserNameChangelog(user07PrivateUserID, newUsername, username07, true);
|
||||||
testUserNameChangelog(user07PrivateUserID, newUsername, username07, true, done);
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should delete existing username if new username is same as publicID", async () => {
|
it("Should delete existing username if new username is same as publicID", async () => {
|
||||||
|
|||||||
@@ -59,71 +59,47 @@ describe("setUsernamePrivate tests", () => {
|
|||||||
before(() => sinon.stub(config, "minUserIDLength").value(USERID_LIMIT));
|
before(() => sinon.stub(config, "minUserIDLength").value(USERID_LIMIT));
|
||||||
after(() => sinon.restore());
|
after(() => sinon.restore());
|
||||||
|
|
||||||
it("Existing privateID = username under Limit should retreive successfully", (done) => {
|
it("Existing privateID = username under Limit should retreive successfully", async () => {
|
||||||
const privateID = preExisting_underLimit;
|
const privateID = preExisting_underLimit;
|
||||||
hasSetUsername(getHash(privateID))
|
assert.ok(await hasSetUsername(getHash(privateID)));
|
||||||
.then((usernameInfo) => {
|
|
||||||
assert.ok(usernameInfo);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Existing privateID = username over Limit should retreive successfully", (done) => {
|
it("Existing privateID = username over Limit should retreive successfully", async () => {
|
||||||
const privateID = preExisting_overLimit;
|
const privateID = preExisting_overLimit;
|
||||||
hasSetUsername(getHash(privateID))
|
assert.ok(await hasSetUsername(getHash(privateID)));
|
||||||
.then((usernameInfo) => {
|
|
||||||
assert.ok(usernameInfo);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return error if trying to set userID = username under limit", (done) => {
|
it("Should return error if trying to set userID = username under limit", async () => {
|
||||||
const privateID = newUser_underLimit;
|
const privateID = newUser_underLimit;
|
||||||
postSetUserName(privateID, privateID)
|
const res = await postSetUserName(privateID, privateID);
|
||||||
.then(async (res) => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
const usernameInfo = await hasSetUsername(getHash(privateID));
|
||||||
const usernameInfo = await hasSetUsername(getHash(privateID));
|
assert.ok(!usernameInfo);
|
||||||
assert.ok(!usernameInfo);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return error if trying to set username = other privateID over limit", (done) => {
|
it("Should return error if trying to set username = other privateID over limit", async () => {
|
||||||
const privateID = newUser_overLimit;
|
const privateID = newUser_overLimit;
|
||||||
postSetUserName(privateID, privateID)
|
const res = await postSetUserName(privateID, privateID);
|
||||||
.then(async (res) => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
const usernameInfo = await hasSetUsername(getHash(privateID));
|
||||||
const usernameInfo = await hasSetUsername(getHash(privateID));
|
assert.ok(!usernameInfo);
|
||||||
assert.ok(!usernameInfo);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return error if trying to set username = other privateID over limit", (done) => {
|
it("Should return error if trying to set username = other privateID over limit", async () => {
|
||||||
const privateID = otherUser;
|
const privateID = otherUser;
|
||||||
const otherUserPrivate = preExisting_overLimit;
|
const otherUserPrivate = preExisting_overLimit;
|
||||||
postSetUserName(privateID, otherUserPrivate)
|
const res = await postSetUserName(privateID, otherUserPrivate);
|
||||||
.then(async (res) => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
const usernameInfo = await hasSetUsername(getHash(privateID));
|
||||||
const usernameInfo = await hasSetUsername(getHash(privateID));
|
assert.ok(!usernameInfo);
|
||||||
assert.ok(!usernameInfo);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not return error if trying to set username = other privateID under limit", (done) => {
|
it("Should not return error if trying to set username = other privateID under limit", async () => {
|
||||||
const privateID = otherUser;
|
const privateID = otherUser;
|
||||||
const otherUserPrivate = preExisting_underLimit;
|
const otherUserPrivate = preExisting_underLimit;
|
||||||
postSetUserName(privateID, otherUserPrivate)
|
const res = await postSetUserName(privateID, otherUserPrivate);
|
||||||
.then(async (res) => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const usernameInfo = await hasSetUsername(getHash(privateID));
|
||||||
const usernameInfo = await hasSetUsername(getHash(privateID));
|
assert.ok(usernameInfo);
|
||||||
assert.ok(usernameInfo);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((err) => done(err));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { db, privateDB } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import { Category, Service } from "../../src/types/segments.model";
|
import { Category, Service } from "../../src/types/segments.model";
|
||||||
|
|||||||
@@ -68,191 +68,118 @@ describe("tempVIP test", function() {
|
|||||||
await redis.del(tempVIPKey(publicTempVIPOne));
|
await redis.del(tempVIPKey(publicTempVIPOne));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should update db version when starting the application", () => {
|
it("Should update db version when starting the application", async () => {
|
||||||
privateDB.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])
|
const row = await privateDB.prepare("get", "SELECT key, value FROM config where key = ?", ["version"]);
|
||||||
.then(row => {
|
assert.ok(row.value >= 5, `Versions are not at least 5. private is ${row.value}`);
|
||||||
assert.ok(row.value >= 5, `Versions are not at least 5. private is ${row.value}`);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it("User should not already be temp VIP", (done) => {
|
it("User should not already be temp VIP", async () => {
|
||||||
checkUserVIP(publicTempVIPOne)
|
assert.ok(!await checkUserVIP(publicTempVIPOne));
|
||||||
.then(result => {
|
const row = await privateDB.prepare("get", `SELECT * FROM "tempVipLog" WHERE "targetUserID" = ?`, [publicTempVIPOne]);
|
||||||
assert.ok(!result);
|
assert.ok(!row?.enabled);
|
||||||
})
|
|
||||||
.then(async () => {
|
|
||||||
const row = await privateDB.prepare("get", `SELECT * FROM "tempVipLog" WHERE "targetUserID" = ?`, [publicTempVIPOne]);
|
|
||||||
assert.ok(!row?.enabled);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should be able to normal upvote as a user", (done) => {
|
it("Should be able to normal upvote as a user", async () => {
|
||||||
postVote(tempVIPOne, UUID0, 1)
|
const res = await postVote(tempVIPOne, UUID0, 1);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getSegment(UUID0);
|
||||||
const row = await getSegment(UUID0);
|
assert.strictEqual(row.votes, 1);
|
||||||
assert.strictEqual(row.votes, 1);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should be able to add tempVIP", (done) => {
|
it("Should be able to add tempVIP", async () => {
|
||||||
addTempVIP("true", permVIP1, publicTempVIPOne)
|
const res = await addTempVIP("true", permVIP1, publicTempVIPOne);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
// check redis
|
||||||
// check redis
|
const vip = await checkUserVIP(publicTempVIPOne);
|
||||||
const vip = await checkUserVIP(publicTempVIPOne);
|
assert.strictEqual(vip, "ChannelID");
|
||||||
assert.strictEqual(vip, "ChannelID");
|
assert.strictEqual(res.data, "Temp VIP added on channel ChannelAuthor");
|
||||||
assert.strictEqual(res.data, "Temp VIP added on channel ChannelAuthor");
|
// check privateDB
|
||||||
// check privateDB
|
const row = await privateDB.prepare("get", `SELECT * FROM "tempVipLog" WHERE "targetUserID" = ?`, [publicTempVIPOne]);
|
||||||
const row = await privateDB.prepare("get", `SELECT * FROM "tempVipLog" WHERE "targetUserID" = ?`, [publicTempVIPOne]);
|
assert.ok(row.enabled);
|
||||||
assert.ok(row.enabled);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should be able to VIP downvote", (done) => {
|
it("Should be able to VIP downvote", async () => {
|
||||||
postVote(tempVIPOne, UUID0, 0)
|
const res = await postVote(tempVIPOne, UUID0, 0);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getSegment(UUID0);
|
||||||
const row = await getSegment(UUID0);
|
assert.strictEqual(row.votes, -2);
|
||||||
assert.strictEqual(row.votes, -2);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should not be able to lock segment", (done) => {
|
it("Should not be able to lock segment", async () => {
|
||||||
postVote(tempVIPOne, UUID0, 1)
|
const res = await postVote(tempVIPOne, UUID0, 1);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getSegment(UUID0);
|
||||||
const row = await getSegment(UUID0);
|
assert.strictEqual(row.votes, 1);
|
||||||
assert.strictEqual(row.votes, 1);
|
assert.strictEqual(row.locked, 0);
|
||||||
assert.strictEqual(row.locked, 0);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should be able to change category but not lock", (done) => {
|
it("Should be able to change category but not lock", async () => {
|
||||||
postVoteCategory(tempVIPOne, UUID0, "filler")
|
const res = await postVoteCategory(tempVIPOne, UUID0, "filler");
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getSegment(UUID0);
|
||||||
const row = await getSegment(UUID0);
|
assert.strictEqual(row.category, "filler");
|
||||||
assert.strictEqual(row.category, "filler");
|
assert.strictEqual(row.locked, 0);
|
||||||
assert.strictEqual(row.locked, 0);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should be able to remove tempVIP prematurely", (done) => {
|
it("Should be able to remove tempVIP prematurely", async () => {
|
||||||
addTempVIP("false", permVIP1, publicTempVIPOne)
|
const res = await addTempVIP("false", permVIP1, publicTempVIPOne);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const vip = await checkUserVIP(publicTempVIPOne);
|
||||||
const vip = await checkUserVIP(publicTempVIPOne);
|
assert.strictEqual(res.data, "Temp VIP removed");
|
||||||
assert.strictEqual(res.data, "Temp VIP removed");
|
assert.ok(!vip, "Should be no listed channelID");
|
||||||
assert.ok(!vip, "Should be no listed channelID");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should not be able to VIP downvote", (done) => {
|
it("Should not be able to VIP downvote", async () => {
|
||||||
postVote(tempVIPOne, UUID1, 0)
|
const res = await postVote(tempVIPOne, UUID1, 0);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getSegment(UUID1);
|
||||||
const row = await getSegment(UUID1);
|
assert.strictEqual(row.votes, 0);
|
||||||
assert.strictEqual(row.votes, 0);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should not be able to VIP change category", (done) => {
|
it("Should not be able to VIP change category", async () => {
|
||||||
postVoteCategory(tempVIPOne, UUID1, "filler")
|
const res = await postVoteCategory(tempVIPOne, UUID1, "filler");
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const row = await getSegment(UUID1);
|
||||||
const row = await getSegment(UUID1);
|
assert.strictEqual(row.category, "sponsor");
|
||||||
assert.strictEqual(row.category, "sponsor");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
// error code testing
|
// error code testing
|
||||||
it("Should be able to add tempVIP after removal", (done) => {
|
it("Should be able to add tempVIP after removal", async () => {
|
||||||
addTempVIP("true", permVIP1, publicTempVIPOne)
|
const res = await addTempVIP("true", permVIP1, publicTempVIPOne);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(res.status, 200);
|
const vip = await checkUserVIP(publicTempVIPOne);
|
||||||
const vip = await checkUserVIP(publicTempVIPOne);
|
assert.strictEqual(vip, "ChannelID");
|
||||||
assert.strictEqual(vip, "ChannelID");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should not be able to add VIP without existing VIP (403)", (done) => {
|
it("Should not be able to add VIP without existing VIP (403)", async () => {
|
||||||
const privateID = "non-vip-privateid";
|
const privateID = "non-vip-privateid";
|
||||||
addTempVIP("true", privateID, publicTempVIPOne)
|
const res = await addTempVIP("true", privateID, publicTempVIPOne);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 403);
|
||||||
assert.strictEqual(res.status, 403);
|
const vip = await checkUserVIP(getHash(privateID) as HashedUserID);
|
||||||
const vip = await checkUserVIP(getHash(privateID) as HashedUserID);
|
assert.ok(!vip, "Should be no listed channelID");
|
||||||
assert.ok(!vip, "Should be no listed channelID");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should not be able to add permanant VIP as temporary VIP (409)", (done) => {
|
it("Should not be able to add permanant VIP as temporary VIP (409)", async () => {
|
||||||
addTempVIP("true", permVIP1, publicPermVIP2)
|
const res = await addTempVIP("true", permVIP1, publicPermVIP2);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 409);
|
||||||
assert.strictEqual(res.status, 409);
|
const vip = await checkUserVIP(publicPermVIP2);
|
||||||
const vip = await checkUserVIP(publicPermVIP2);
|
assert.ok(!vip, "Should be no listed channelID");
|
||||||
assert.ok(!vip, "Should be no listed channelID");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Temp VIP should not be able to add another Temp VIP (403)", (done) => {
|
it("Temp VIP should not be able to add another Temp VIP (403)", async () => {
|
||||||
const privateID = "non-vip-privateid";
|
const privateID = "non-vip-privateid";
|
||||||
const publicID = getHash(privateID) as HashedUserID;
|
const publicID = getHash(privateID) as HashedUserID;
|
||||||
addTempVIP("true", tempVIPOne, publicID)
|
const res = await addTempVIP("true", tempVIPOne, publicID);
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 403);
|
||||||
assert.strictEqual(res.status, 403);
|
const vip = await checkUserVIP(publicID);
|
||||||
const vip = await checkUserVIP(publicID);
|
assert.ok(!vip, "Should be no listed channelID");
|
||||||
assert.ok(!vip, "Should be no listed channelID");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
// error 40X testing
|
// error 40X testing
|
||||||
it("Should return 404 with invalid videoID", (done) => {
|
it("Should return 404 with invalid videoID", async () => {
|
||||||
const privateID = "non-vip-privateid";
|
const privateID = "non-vip-privateid";
|
||||||
const publicID = getHash(privateID) as HashedUserID;
|
const publicID = getHash(privateID) as HashedUserID;
|
||||||
addTempVIP("true", permVIP1, publicID, "knownWrongID")
|
const res = await addTempVIP("true", permVIP1, publicID, "knownWrongID");
|
||||||
.then(async res => {
|
assert.strictEqual(res.status, 404);
|
||||||
assert.strictEqual(res.status, 404);
|
const vip = await checkUserVIP(publicID);
|
||||||
const vip = await checkUserVIP(publicID);
|
assert.ok(!vip, "Should be no listed channelID");
|
||||||
assert.ok(!vip, "Should be no listed channelID");
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should return 400 with invalid userID", (done) => {
|
it("Should return 400 with invalid userID", async () => {
|
||||||
addTempVIP("true", permVIP1, "" as HashedUserID, "knownWrongID")
|
const res = await addTempVIP("true", permVIP1, "" as HashedUserID, "knownWrongID");
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should return 400 with invalid adminUserID", (done) => {
|
it("Should return 400 with invalid adminUserID", async () => {
|
||||||
addTempVIP("true", "", publicTempVIPOne)
|
const res = await addTempVIP("true", "", publicTempVIPOne);
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
it("Should return 400 with invalid channelID", (done) => {
|
it("Should return 400 with invalid channelID", async () => {
|
||||||
addTempVIP("true", permVIP1, publicTempVIPOne, "")
|
const res = await addTempVIP("true", permVIP1, publicTempVIPOne, "");
|
||||||
.then(res => {
|
assert.strictEqual(res.status, 400);
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,32 +16,24 @@ describe("tokenUtils test", function() {
|
|||||||
mock.onGet(/identity/).reply(200, patreon.activeIdentity);
|
mock.onGet(/identity/).reply(200, patreon.activeIdentity);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to create patreon token", function (done) {
|
it("Should be able to create patreon token", async function () {
|
||||||
if (!config?.patreon) this.skip();
|
if (!config?.patreon) return this.skip();
|
||||||
tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code").then((licenseKey) => {
|
const licenseKey = await tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code");
|
||||||
assert.ok(validateToken(licenseKey[0]));
|
assert.ok(validateToken(licenseKey[0]));
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it("Should be able to create local token", (done) => {
|
it("Should be able to create local token", async () => {
|
||||||
tokenUtils.createAndSaveToken(tokenUtils.TokenType.local).then((licenseKey) => {
|
const licenseKey = await tokenUtils.createAndSaveToken(tokenUtils.TokenType.local);
|
||||||
assert.ok(validateToken(licenseKey[0]));
|
assert.ok(validateToken(licenseKey[0]));
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it("Should be able to get patreon identity", function (done) {
|
it("Should be able to get patreon identity", async function () {
|
||||||
if (!config?.patreon) this.skip();
|
if (!config?.patreon) return this.skip();
|
||||||
tokenUtils.getPatreonIdentity("fake_access_token").then((result) => {
|
const result = await tokenUtils.getPatreonIdentity("fake_access_token");
|
||||||
assert.deepEqual(result, patreon.activeIdentity);
|
assert.deepEqual(result, patreon.activeIdentity);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it("Should be able to refresh token", function (done) {
|
it("Should be able to refresh token", async function () {
|
||||||
if (!config?.patreon) this.skip();
|
if (!config?.patreon) return this.skip();
|
||||||
tokenUtils.refreshToken(tokenUtils.TokenType.patreon, "fake-licence-Key", "fake_refresh_token").then((result) => {
|
const result = await tokenUtils.refreshToken(tokenUtils.TokenType.patreon, "fake-licence-Key", "fake_refresh_token");
|
||||||
assert.strictEqual(result, true);
|
assert.strictEqual(result, true);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
@@ -56,20 +48,16 @@ describe("tokenUtils failing tests", function() {
|
|||||||
mock.onGet(/identity/).reply(204, patreon.activeIdentity);
|
mock.onGet(/identity/).reply(204, patreon.activeIdentity);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should fail if patreon is not correctly stubbed", function (done) {
|
it("Should fail if patreon is not correctly stubbed", async () => {
|
||||||
tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code").then((licenseKey) => {
|
const licenseKey = await tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code");
|
||||||
assert.strictEqual(licenseKey, null);
|
assert.strictEqual(licenseKey, null);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it("Should fail if token type is invalid", (done) => {
|
it("Should fail if token type is invalid", async () => {
|
||||||
tokenUtils.createAndSaveToken("invalidTokenType" as tokenUtils.TokenType).then((licenseKey) => {
|
const licenseKey = await tokenUtils.createAndSaveToken("invalidTokenType" as tokenUtils.TokenType);
|
||||||
assert.strictEqual(licenseKey, null);
|
assert.strictEqual(licenseKey, null);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
mock.restore();
|
mock.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -59,12 +59,13 @@ async function init() {
|
|||||||
mocha.run((failures) => {
|
mocha.run((failures) => {
|
||||||
mockServer.close();
|
mockServer.close();
|
||||||
server.close();
|
server.close();
|
||||||
redis.quit();
|
redis.quit().finally(() => {
|
||||||
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
|
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
|
||||||
process.exit();
|
process.exit();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
void init();
|
||||||
|
|||||||
4
tsconfig.eslint.json
Normal file
4
tsconfig.eslint.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"include": ["**/*"],
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user