mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 11:36:58 +03:00
add userCounter mocks and rearrange webhook path
This commit is contained in:
9
ci.json
9
ci.json
@@ -4,11 +4,12 @@
|
|||||||
"globalSalt": "testSalt",
|
"globalSalt": "testSalt",
|
||||||
"adminUserID": "4bdfdc9cddf2c7d07a8a87b57bf6d25389fb75d1399674ee0e0938a6a60f4c3b",
|
"adminUserID": "4bdfdc9cddf2c7d07a8a87b57bf6d25389fb75d1399674ee0e0938a6a60f4c3b",
|
||||||
"newLeafURLs": ["placeholder"],
|
"newLeafURLs": ["placeholder"],
|
||||||
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/ReportChannelWebhook",
|
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/webhook/ReportChannel",
|
||||||
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/FirstTimeSubmissionsWebhook",
|
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/webhook/FirstTimeSubmissions",
|
||||||
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/CompletelyIncorrectReportWebhook",
|
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/webhook/CompletelyIncorrectReport",
|
||||||
"discordNeuralBlockRejectWebhookURL": "http://127.0.0.1:8081/NeuralBlockRejectWebhook",
|
"discordNeuralBlockRejectWebhookURL": "http://127.0.0.1:8081/webhook/NeuralBlockReject",
|
||||||
"neuralBlockURL": "http://127.0.0.1:8081/NeuralBlock",
|
"neuralBlockURL": "http://127.0.0.1:8081/NeuralBlock",
|
||||||
|
"userCounterURL": "https://127.0.0.1:8081/UserCounter",
|
||||||
"behindProxy": true,
|
"behindProxy": true,
|
||||||
"postgres": {
|
"postgres": {
|
||||||
"user": "ci_db_user",
|
"user": "ci_db_user",
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ import { Request } from "express";
|
|||||||
import { IPAddress } from "../types/segments.model";
|
import { IPAddress } from "../types/segments.model";
|
||||||
|
|
||||||
export function getIP(req: Request): IPAddress {
|
export function getIP(req: Request): IPAddress {
|
||||||
|
// if in testing mode, return immediately
|
||||||
|
if (config.mode === "test") return "127.0.0.1" as IPAddress;
|
||||||
|
|
||||||
if (config.behindProxy === true || config.behindProxy === "true") {
|
if (config.behindProxy === true || config.behindProxy === "true") {
|
||||||
config.behindProxy = "X-Forwarded-For";
|
config.behindProxy = "X-Forwarded-For";
|
||||||
}
|
}
|
||||||
@@ -15,6 +18,6 @@ export function getIP(req: Request): IPAddress {
|
|||||||
case "X-Real-IP":
|
case "X-Real-IP":
|
||||||
return req.headers["x-real-ip"] as IPAddress;
|
return req.headers["x-real-ip"] as IPAddress;
|
||||||
default:
|
default:
|
||||||
return (req.connection?.remoteAddress || req.socket?.remoteAddress) as IPAddress;
|
return req.socket?.remoteAddress as IPAddress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,12 @@
|
|||||||
"globalSalt": "testSalt",
|
"globalSalt": "testSalt",
|
||||||
"adminUserID": "4bdfdc9cddf2c7d07a8a87b57bf6d25389fb75d1399674ee0e0938a6a60f4c3b",
|
"adminUserID": "4bdfdc9cddf2c7d07a8a87b57bf6d25389fb75d1399674ee0e0938a6a60f4c3b",
|
||||||
"newLeafURLs": ["placeholder"],
|
"newLeafURLs": ["placeholder"],
|
||||||
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/ReportChannelWebhook",
|
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/webhook/ReportChannel",
|
||||||
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/FirstTimeSubmissionsWebhook",
|
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/webhook/FirstTimeSubmissions",
|
||||||
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/CompletelyIncorrectReportWebhook",
|
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/webhook/CompletelyIncorrectReport",
|
||||||
"discordNeuralBlockRejectWebhookURL": "http://127.0.0.1:8081/NeuralBlockRejectWebhook",
|
"discordNeuralBlockRejectWebhookURL": "http://127.0.0.1:8081/webhook/NeuralBlockReject",
|
||||||
"neuralBlockURL": "http://127.0.0.1:8081/NeuralBlock",
|
"neuralBlockURL": "http://127.0.0.1:8081/NeuralBlock",
|
||||||
|
"userCounterURL": "http://127.0.0.1:8081/UserCounter",
|
||||||
"behindProxy": true,
|
"behindProxy": true,
|
||||||
"db": ":memory:",
|
"db": ":memory:",
|
||||||
"privateDB": ":memory:",
|
"privateDB": ":memory:",
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import { getHash } from "../../src/utils/getHash";
|
|||||||
|
|
||||||
|
|
||||||
describe("userCounter", () => {
|
describe("userCounter", () => {
|
||||||
it("Should return 200", (done) => {
|
it("Should return 200", function (done) {
|
||||||
if (!config.userCounterURL) return done(); // skip if no userCounterURL is set
|
if (!config.userCounterURL) this.skip(); // skip if no userCounterURL is set
|
||||||
axios.request({
|
axios.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
baseURL: config.userCounterURL,
|
baseURL: config.userCounterURL,
|
||||||
|
|||||||
@@ -1,23 +1,24 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { config } from "../src/config";
|
import { config } from "../src/config";
|
||||||
import { Server } from "http";
|
import { Server } from "http";
|
||||||
|
import { UserCounter } from "./mocks/UserCounter";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.post("/ReportChannelWebhook", (req, res) => {
|
app.post("/webhook/ReportChannel", (req, res) => {
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/FirstTimeSubmissionsWebhook", (req, res) => {
|
app.post("/webhook/FirstTimeSubmissions", (req, res) => {
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/CompletelyIncorrectReportWebhook", (req, res) => {
|
app.post("/webhook/CompletelyIncorrectReport", (req, res) => {
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Testing NeuralBlock
|
// Testing NeuralBlock
|
||||||
app.post("/NeuralBlockRejectWebhook", (req, res) => {
|
app.post("/webhook/NeuralBlockReject", (req, res) => {
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,6 +48,9 @@ app.post("/CustomWebhook", (req, res) => {
|
|||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// mocks
|
||||||
|
app.use("/UserCounter", UserCounter);
|
||||||
|
|
||||||
export function createMockServer(callback: () => void): Server {
|
export function createMockServer(callback: () => void): Server {
|
||||||
return app.listen(config.mockPort, callback);
|
return app.listen(config.mockPort, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
11
test/mocks/UserCounter.ts
Normal file
11
test/mocks/UserCounter.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
export const UserCounter = Router();
|
||||||
|
|
||||||
|
UserCounter.post("/api/v1/addIP", (req, res) => {
|
||||||
|
res.sendStatus(200);
|
||||||
|
});
|
||||||
|
UserCounter.get("/api/v1/userCount", (req, res) => {
|
||||||
|
res.send({
|
||||||
|
userCount: 100
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user