Add more comprehensive tests
Problem: I've been worried about merging these version bump pull requests since we don't have many tests, and I *really* don't want to merge any catostrophic breaking changes anywhere. Solution: Add some tests that are more comprehensive, starting by creating a temporary SSB database and keypair and then editing the profile, previewing a message, publishing a message, etc., until we have a handful of small functions actually being tested. This won't ensure that everything works forever, and it *really* doesn't test replication, but it should help increase our confidence that test success means that fewer things are broken.
This commit is contained in:
parent
76789a0ed6
commit
c86865a5ca
|
@ -8588,6 +8588,26 @@
|
|||
"pull-stream": "^3.6.7",
|
||||
"ssb-keys": "^7.0.14",
|
||||
"ssb-ref": "^2.9.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssb-blobs": {
|
||||
|
@ -8623,6 +8643,26 @@
|
|||
"pull-stream": "^3.6.0",
|
||||
"ssb-config": "^3.4.4",
|
||||
"ssb-keys": "^7.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssb-config": {
|
||||
|
@ -8637,6 +8677,26 @@
|
|||
"rc": "^1.1.6",
|
||||
"ssb-caps": "^1.0.1",
|
||||
"ssb-keys": "^7.1.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssb-conn": {
|
||||
|
@ -8806,6 +8866,16 @@
|
|||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -8849,16 +8919,36 @@
|
|||
"ssb-client": "^4.7.4",
|
||||
"ssb-keys": "^7.1.3",
|
||||
"ssb-ref": "^2.13.9"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-8.0.0.tgz",
|
||||
"integrity": "sha512-PJnRSRtYjwEDS/I+UTCyC1JocGCOlK43ghp54Y5oQMJvv8tczuoz4oSUFZjBN6+ubLMqGkPLtgo4+58g1gXg9g==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"chloride": "~2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
"private-box": "~0.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
|
@ -8882,6 +8972,26 @@
|
|||
"secret-stack-decorators": "~1.0.0",
|
||||
"ssb-keys": "^7.2.0",
|
||||
"ssb-ref": "^2.13.9"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssb-logging": {
|
||||
|
@ -9028,6 +9138,16 @@
|
|||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -9146,6 +9266,14 @@
|
|||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
|
@ -9183,6 +9311,18 @@
|
|||
"pull-stream": "^3.6.0",
|
||||
"ssb-config": "^3.2.5",
|
||||
"ssb-keys": "^7.0.13"
|
||||
},
|
||||
"dependencies": {
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssb-config": {
|
||||
|
@ -9197,6 +9337,18 @@
|
|||
"rc": "^1.1.6",
|
||||
"ssb-caps": "^1.0.1",
|
||||
"ssb-keys": "^7.1.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssb-ref": {
|
||||
|
@ -9293,6 +9445,26 @@
|
|||
"monotonic-timestamp": "0.0.9",
|
||||
"ssb-keys": "^7.0.7",
|
||||
"ssb-ref": "^2.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"ssb-keys": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ssb-keys/-/ssb-keys-7.2.2.tgz",
|
||||
"integrity": "sha512-FPeyYU/3LpxcagnbmVWE+Q/qzg6keqeOBPbD7sEH9UKixUASeufPKiORDgh8nVX7J9Z+0vUaHt/WG999kGjvVQ==",
|
||||
"requires": {
|
||||
"chloride": "^2.2.8",
|
||||
"mkdirp": "~0.5.0",
|
||||
"private-box": "^0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssb-ws": {
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
"ssb-ebt": "^5.6.7",
|
||||
"ssb-friends": "^4.1.4",
|
||||
"ssb-invite": "^2.1.3",
|
||||
"ssb-keys": "^8.0.0",
|
||||
"ssb-lan": "^0.2.0",
|
||||
"ssb-logging": "^1.0.0",
|
||||
"ssb-markdown": "^6.0.7",
|
||||
|
|
|
@ -8,12 +8,22 @@ const { promisify } = require("util");
|
|||
const ssbClient = require("ssb-client");
|
||||
const ssbConfig = require("ssb-config");
|
||||
const ssbTangle = require("ssb-tangle");
|
||||
const ssbKeys = require("ssb-keys");
|
||||
const debug = require("debug")("oasis");
|
||||
const path = require("path");
|
||||
const lodash = require("lodash");
|
||||
const fs = require("fs");
|
||||
const os = require("os");
|
||||
|
||||
const flotilla = require("./flotilla");
|
||||
|
||||
// Use temporary path if we're running a test.
|
||||
// TODO: Refactor away 'OASIS_TEST' variable.
|
||||
if (process.env.OASIS_TEST) {
|
||||
ssbConfig.path = fs.mkdtempSync(path.join(os.tmpdir(), "oasis-"));
|
||||
ssbConfig.keys = ssbKeys.generate();
|
||||
}
|
||||
|
||||
const socketPath = path.join(ssbConfig.path, "socket");
|
||||
const publicInteger = ssbConfig.keys.public.replace(".ed25519", "");
|
||||
const remote = `unix:${socketPath}~noauth:${publicInteger}`;
|
||||
|
@ -51,7 +61,9 @@ const connect = (options) =>
|
|||
resolve(api);
|
||||
};
|
||||
|
||||
ssbClient(null, options).then(onSuccess).catch(reject);
|
||||
ssbClient(process.env.OASIS_TEST ? ssbConfig.keys : null, options)
|
||||
.then(onSuccess)
|
||||
.catch(reject);
|
||||
});
|
||||
|
||||
let closing = false;
|
||||
|
@ -65,7 +77,15 @@ let clientHandle;
|
|||
*/
|
||||
const attemptConnection = () =>
|
||||
new Promise((resolve, reject) => {
|
||||
connect({ remote })
|
||||
const originalConnect = process.env.OASIS_TEST
|
||||
? new Promise((resolve, reject) =>
|
||||
reject({
|
||||
message: "could not connect to sbot",
|
||||
})
|
||||
)
|
||||
: connect({ remote });
|
||||
|
||||
originalConnect
|
||||
.then((ssb) => {
|
||||
debug("Connected to existing Scuttlebutt service over Unix socket");
|
||||
resolve(ssb);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// HACK: Prevent Oasis from opening the web browser.
|
||||
process.argv.push("--no-open", "--offline");
|
||||
process.env.OASIS_TEST = true;
|
||||
|
||||
const app = require("../src");
|
||||
const supertest = require("supertest");
|
||||
|
@ -30,40 +31,80 @@ const paths = [
|
|||
|
||||
tap.setTimeout(0);
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
tap.test("DNS rebind attack fails", (t) => {
|
||||
t.plan(1);
|
||||
supertest(app)
|
||||
.get("/inbox")
|
||||
.set("Host", "example.com")
|
||||
.expect(400)
|
||||
.end(t.error);
|
||||
.end(t.end);
|
||||
});
|
||||
|
||||
tap.test("CSRF attack should fail with no referer", (t) => {
|
||||
t.plan(1);
|
||||
supertest(app).post("/conn/settings/stop").expect(400).end(t.error);
|
||||
supertest(app).post("/conn/settings/stop").expect(400).end(t.end);
|
||||
});
|
||||
|
||||
tap.test("CSRF attack should fail with wrong referer", (t) => {
|
||||
t.plan(1);
|
||||
supertest(app)
|
||||
.post("/conn/settings/stop")
|
||||
.set("Host", "example.com")
|
||||
.expect(400)
|
||||
.end(t.error);
|
||||
.end(t.end);
|
||||
});
|
||||
|
||||
paths.forEach((path) => {
|
||||
tap.test(path, (t) => {
|
||||
t.plan(1);
|
||||
supertest(app)
|
||||
.get(path)
|
||||
.set("Host", "localhost")
|
||||
.expect(200)
|
||||
.end((err) => {
|
||||
console.log(path);
|
||||
t.error(err);
|
||||
});
|
||||
supertest(app).get(path).set("Host", "localhost").expect(200).end(t.end);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue