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-11-22 23:35:15 +00:00
|
|
|
process.env.OASIS_TEST = true;
|
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 16:25:16 +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-11-22 23:35:15 +00:00
|
|
|
tap.test("edit profile", (t) => {
|
|
|
|
supertest(app)
|
|
|
|
.post("/profile/edit")
|
|
|
|
.field("name", "allison-wonderland")
|
|
|
|
.field("description", "example description **published**")
|
|
|
|
.attach("image", __filename)
|
|
|
|
.set("Referer", "http://localhost:3000/")
|
|
|
|
.set("Host", "localhost")
|
|
|
|
.expect(302)
|
|
|
|
.end(t.end);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test("preview", (t) => {
|
|
|
|
supertest(app)
|
|
|
|
.post("/publish/preview")
|
|
|
|
.field("text", "example message **previewed**")
|
|
|
|
.field("contentWarning", "")
|
|
|
|
.set("Referer", "http://localhost:3000/")
|
|
|
|
.set("Host", "localhost")
|
|
|
|
.expect(200)
|
|
|
|
.expect(({ text }) =>
|
|
|
|
text.includes("example message <strong>previewed</strong>")
|
|
|
|
)
|
|
|
|
.end(t.end);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test("publish", (t) => {
|
|
|
|
supertest(app)
|
|
|
|
.post("/publish")
|
|
|
|
.field("text", "example message **published**")
|
|
|
|
.set("Referer", "http://localhost:3000/")
|
|
|
|
.set("Host", "localhost")
|
|
|
|
.expect(302)
|
|
|
|
.end(t.end);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test("profile", (t) => {
|
|
|
|
supertest(app)
|
|
|
|
.get("/profile")
|
|
|
|
.set("Host", "localhost")
|
|
|
|
.expect(200)
|
|
|
|
.expect(({ text }) => text.includes("allison-wonderland"))
|
|
|
|
.expect(({ text }) =>
|
|
|
|
text.includes("example description <strong>published</strong>")
|
|
|
|
)
|
|
|
|
.expect(({ text }) =>
|
|
|
|
text.includes("example message <strong>published</strong>")
|
|
|
|
)
|
|
|
|
.end(t.end);
|
|
|
|
});
|
|
|
|
|
2020-04-10 19:33:22 +00:00
|
|
|
tap.test("DNS rebind attack fails", (t) => {
|
|
|
|
supertest(app)
|
|
|
|
.get("/inbox")
|
|
|
|
.set("Host", "example.com")
|
|
|
|
.expect(400)
|
2020-11-22 23:35:15 +00:00
|
|
|
.end(t.end);
|
2020-04-10 19:33:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test("CSRF attack should fail with no referer", (t) => {
|
2020-11-22 23:35:15 +00:00
|
|
|
supertest(app).post("/conn/settings/stop").expect(400).end(t.end);
|
2020-04-10 19:33:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test("CSRF attack should fail with wrong referer", (t) => {
|
|
|
|
supertest(app)
|
|
|
|
.post("/conn/settings/stop")
|
|
|
|
.set("Host", "example.com")
|
|
|
|
.expect(400)
|
2020-11-22 23:35:15 +00:00
|
|
|
.end(t.end);
|
2020-04-10 19:33:22 +00:00
|
|
|
});
|
|
|
|
|
2020-04-06 19:14:58 +00:00
|
|
|
paths.forEach((path) => {
|
|
|
|
tap.test(path, (t) => {
|
2020-11-22 23:35:15 +00:00
|
|
|
supertest(app).get(path).set("Host", "localhost").expect(200).end(t.end);
|
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();
|
|
|
|
});
|