2020-04-03 16:07:39 +00:00
|
|
|
// HACK: Prevent Oasis from opening the web browser.
|
2020-04-06 19:14:58 +00:00
|
|
|
process.argv.push("--no-open", "--offline");
|
2020-04-03 16:07:39 +00:00
|
|
|
|
|
|
|
const app = require("../src");
|
|
|
|
const supertest = require("supertest");
|
|
|
|
const tap = require("tap");
|
|
|
|
|
|
|
|
// TODO: Generate programmatically?
|
|
|
|
const paths = [
|
|
|
|
"/inbox",
|
|
|
|
"/mentions",
|
|
|
|
"/profile",
|
2020-05-23 18:48:43 +00:00
|
|
|
"/profile?gt=0",
|
|
|
|
"/profile?lt=100",
|
2020-04-03 16:07:39 +00:00
|
|
|
"/profile/edit",
|
|
|
|
"/public/latest",
|
|
|
|
"/public/latest/extended",
|
2020-11-11 14:19:05 +00:00
|
|
|
// "/public/latest/summaries",
|
2020-04-03 16:07:39 +00:00
|
|
|
"/public/latest/threads",
|
|
|
|
"/public/latest/topics",
|
|
|
|
"/public/popular/day",
|
|
|
|
"/public/popular/week",
|
|
|
|
"/publish",
|
|
|
|
"/publish/custom",
|
|
|
|
"/search",
|
|
|
|
"/search?query=foo",
|
|
|
|
"/settings",
|
|
|
|
"/settings/readme",
|
|
|
|
];
|
|
|
|
|
2020-04-06 19:14:58 +00:00
|
|
|
tap.setTimeout(0);
|
2020-04-03 16:07:39 +00:00
|
|
|
|
2020-04-10 19:33:22 +00:00
|
|
|
tap.test("DNS rebind attack fails", (t) => {
|
2020-10-21 12:53:18 +00:00
|
|
|
t.plan(1);
|
2020-04-10 19:33:22 +00:00
|
|
|
supertest(app)
|
|
|
|
.get("/inbox")
|
|
|
|
.set("Host", "example.com")
|
|
|
|
.expect(400)
|
2020-10-21 12:53:18 +00:00
|
|
|
.end(t.error);
|
2020-04-10 19:33:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test("CSRF attack should fail with no referer", (t) => {
|
2020-10-21 12:53:18 +00:00
|
|
|
t.plan(1);
|
|
|
|
supertest(app).post("/conn/settings/stop").expect(400).end(t.error);
|
2020-04-10 19:33:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test("CSRF attack should fail with wrong referer", (t) => {
|
2020-10-21 12:53:18 +00:00
|
|
|
t.plan(1);
|
2020-04-10 19:33:22 +00:00
|
|
|
supertest(app)
|
|
|
|
.post("/conn/settings/stop")
|
|
|
|
.set("Host", "example.com")
|
|
|
|
.expect(400)
|
2020-10-21 12:53:18 +00:00
|
|
|
.end(t.error);
|
2020-04-10 19:33:22 +00:00
|
|
|
});
|
|
|
|
|
2020-04-06 19:14:58 +00:00
|
|
|
paths.forEach((path) => {
|
|
|
|
tap.test(path, (t) => {
|
2020-10-21 12:53:18 +00:00
|
|
|
t.plan(1);
|
2020-04-10 19:33:22 +00:00
|
|
|
supertest(app)
|
2020-04-06 19:14:58 +00:00
|
|
|
.get(path)
|
2020-04-10 19:33:22 +00:00
|
|
|
.set("Host", "localhost")
|
2020-04-06 19:14:58 +00:00
|
|
|
.expect(200)
|
|
|
|
.end((err) => {
|
2020-10-21 12:53:18 +00:00
|
|
|
console.log(path);
|
|
|
|
t.error(err);
|
2020-04-06 19:14:58 +00:00
|
|
|
});
|
|
|
|
});
|
2020-04-03 16:07:39 +00:00
|
|
|
});
|
|
|
|
|
2020-04-06 19:14:58 +00:00
|
|
|
// HACK: This closes the database.
|
|
|
|
tap.teardown(() => {
|
|
|
|
app.close();
|
|
|
|
app._close();
|
|
|
|
});
|