Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the tests work again #1136

Merged
merged 33 commits into from Jan 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
efd02d2
Added Timeout, something is not always settled (node v0.12.x)
Dec 11, 2015
9489b60
Close zombie when done, use zombie asserts
Dec 11, 2015
01d0760
cleanup
Dec 11, 2015
95b811e
Close zombie, and other zombie related changes
Dec 12, 2015
bd08f80
use nodejs internal setImmediate
Dec 13, 2015
ba4e8ae
Use express-session.
Dec 13, 2015
9fa2484
Use internal setImmediate
Dec 13, 2015
ec9ee40
Cleaning Timers, using express-session, Showdown update
Dec 13, 2015
7419b72
zombie 2.x (0.10, 0.12)
Dec 13, 2015
d1f189b
patch files
Dec 13, 2015
e4c0880
Showdown upgrade
Dec 13, 2015
fb8d9a2
Zombie related updates
Dec 13, 2015
757b9d8
Zombie related updates
Dec 13, 2015
51da28d
Zombie related updates
Dec 13, 2015
4414357
Typo..
Dec 13, 2015
32d4eec
Zombie related changes and SIGKILL
Dec 13, 2015
d324044
cleanup
Dec 13, 2015
c8b0e15
cleanup
Dec 13, 2015
85bfb03
cleanup
Dec 13, 2015
ae4f72d
Run postinstall script
Dec 13, 2015
bd7ea99
Versions update, use 'npn test'
Dec 14, 2015
e929018
underscore update
Dec 15, 2015
f49aa2a
updated versions for: undersocre-contrib, node-uuid, optimist, bunyan…
Dec 15, 2015
3e3cc7e
use npm version of simplesmtp
Dec 15, 2015
4046e5e
xml2js update
Dec 15, 2015
49dcced
validator update, added sanitize-html
Dec 15, 2015
5226af3
connect-auth update
Dec 15, 2015
00bc3cf
merge style updates
Jan 8, 2016
29db2a6
updates, mostly codestyle
Jan 8, 2016
396e547
connect-databank#v0.13.0b, waiting for PR
Jan 8, 2016
ae9fb2a
promise style updates
Jan 12, 2016
c97c23c
removed connect-databank.patch, it's pulled straight from github for now
Jan 12, 2016
bcdae62
removed connect.patch, a patched version is pulled from github for now
Jan 13, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions .jscsrc
Expand Up @@ -10,8 +10,24 @@
"requireCamelCaseOrUpperCaseIdentifiers": null,
"requireCurlyBraces": null,
"maximumLineLength": null,
"requireSpaceBeforeBinaryOperators": null,
"requireSpaceAfterBinaryOperators": null,
"requireSpaceBeforeBinaryOperators": [
"=",
"==",
"===",
"!=",
"!==",
"&&",
"||"
],
"requireSpaceAfterBinaryOperators": [
"=",
"==",
"===",
"!=",
"!==",
"&&",
"||"
],
"validateCommentPosition": null,
"requireEarlyReturn": null,
"requireDotNotation": null
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "0.8"
- "0.10"
script: "./node_modules/.bin/vows --spec test/*-test.js"
- "0.12"
script: "npm test"
before_script:
- "./test/hosts.sh"
before_install:
Expand Down
26 changes: 20 additions & 6 deletions lib/app.js
Expand Up @@ -222,6 +222,17 @@ var makeApp = function(configBase, callback) {

app.config = config;

app.on("close", function() {
clearInterval(dialbackClient.cleanup);
if (nonceCleanerInterval) {
clearInterval(nonceCleanerInterval);
}
if (nonceCleanerTimeout) {
clearTimeout(nonceCleanerTimeout);
}
dbstore.close();
});

if (config.smtpserver) {
// harmless flag
config.haveEmail = true;
Expand All @@ -232,7 +243,6 @@ var makeApp = function(configBase, callback) {

// Each worker takes a turn cleaning up, so *this* worker does
// its cleanup once every config.workers cleanup periods

var dbstore = new DatabankStore(db, log, (config.cleanupSession) ? (config.cleanupSession * workers) : 0);

if (!config.noweb) {
Expand Down Expand Up @@ -401,8 +411,9 @@ var makeApp = function(configBase, callback) {

// Routes

api.addRoutes(app);
// It does seem to matter in which order they are put
webfinger.addRoutes(app);
api.addRoutes(app);
clientreg.addRoutes(app);
shared.addRoutes(app);

Expand All @@ -425,8 +436,8 @@ var makeApp = function(configBase, callback) {
// A route to show the API doc at root
app.get("/", function(req, res, next) {

var Showdown = require("showdown"),
converter = new Showdown.converter();
var showdown = require("showdown"),
converter = new showdown.Converter();

Step(
function() {
Expand Down Expand Up @@ -502,11 +513,14 @@ var makeApp = function(configBase, callback) {
// We set a timer so we start with an offset, instead of having
// all workers start at almost the same time

var nonceCleanerInterval,
nonceCleanerTimeout;

if (config.cleanupNonce) {
setTimeout(function() {
nonceCleanerTimeout = setTimeout(function() {
log.debug("Cleaning up old OAuth nonces");
Nonce.cleanup();
setInterval(function() {
nonceCleanerInterval = setInterval(function() {
log.debug("Cleaning up old OAuth nonces");
Nonce.cleanup();
}, config.cleanupNonce * (config.workers || 1));
Expand Down
5 changes: 2 additions & 3 deletions lib/model/activity.js
Expand Up @@ -29,8 +29,7 @@ var databank = require("databank"),
Favorite = require("./favorite").Favorite,
DatabankObject = databank.DatabankObject,
NoSuchThingError = databank.NoSuchThingError,
NotInStreamError = require("./stream").NotInStreamError,
sanitize = validator.sanitize;
NotInStreamError = require("./stream").NotInStreamError;

var AppError = function(msg) {
Error.captureStackTrace(this, AppError);
Expand Down Expand Up @@ -1128,7 +1127,7 @@ Activity.makeContent = function(props) {
}
},
reprOf = function(obj) {
var name = sanitize(nameOf(obj)).escape();
var name = validator.escape(nameOf(obj));
if (_.has(obj, "url")) {
return "<a href='"+obj.url+"'>"+name+"</a>";
} else {
Expand Down
2 changes: 0 additions & 2 deletions lib/provider.js
Expand Up @@ -14,8 +14,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

require("set-immediate");

var NoSuchThingError = require("databank").NoSuchThingError,
_ = require("underscore"),
url = require("url"),
Expand Down
10 changes: 6 additions & 4 deletions lib/scrubber.js
Expand Up @@ -16,14 +16,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

var validator = require("validator"),
_ = require("underscore"),
check = validator.check,
var _ = require("underscore"),
validator = require("validator"),
sanitize = validator.sanitize;
sanitizeHtml = require("sanitize-html");

var Scrubber = {
scrub: function(str) {
return sanitize(str).xss();
// using defaults
// { allowedTags: ['b', 'i', 'em', 'strong', 'a'], allowedAttributes: { a: ['href']}}
return sanitizeHtml(str);
},
scrubActivity: function(act) {

Expand Down
49 changes: 25 additions & 24 deletions package.json
Expand Up @@ -5,39 +5,40 @@
"version": "0.3.0",
"author": "Evan Prodromou <evan@e14n.com>",
"devDependencies": {
"vows": "0.7.x",
"node-mocks-http": "0.0.x",
"zombie": "1.4.x",
"xml2js": "0.1.x",
"vows": "0.8.x",
"node-mocks-http": "1.5.x",
"zombie": "2.x.x",
"xml2js": "0.4.x",
"simplesmtp": "0.3.x",
"rimraf": "2.0.x"
"rimraf": "2.4.x"
},
"dependencies": { "connect": "1.x",
"connect-auth": "0.5.3",
"dependencies": { "connect": "profOnno/connect#v1.9.3",
"connect-auth": "0.6.x",
"express": "2.5.x",
"utml": "0.2.x",
"underscore": "1.4.x",
"underscore-contrib": "0.1.x",
"node-uuid": "1.3.x",
"bcrypt": "0.8.x",
"dateformat": "1.x",
"databank": "0.19.x",
"underscore": "1.8.x",
"underscore-contrib": "0.3.x",
"node-uuid": "1.4.x",
"bcrypt": "0.8.x",
"dateformat": "1.x",
"express-session": "1.x.x",
"databank": "0.19.x",
"connect-databank": "profOnno/connect-databank#v0.13.0b",
"step": "0.0.x",
"oauth-evanp": "~0.9.10-evanp.2",
"optimist": "0.3.x",
"validator": "0.4.x",
"optimist": "0.6.x",
"validator": "4.4.x",
"sanitize-html": "1.11.x",
"webfinger": "~0.4.2",
"showdown": "0.3.x",
"showdown": "1.3.x",
"jankyqueue": "0.1.x",
"schlock": "~0.2.1",
"bunyan": "0.16.x",
"emailjs": "0.3.x",
"mkdirp": "0.3.x",
"connect-databank": "0.13.x",
"bunyan": "1.5.x",
"emailjs": "1.0.x",
"mkdirp": "0.5.x",
"sockjs": "0.3.x",
"dialback-client": "~0.1.5",
"gm": "1.9.x",
"set-immediate": "0.1.x",
"dialback-client": "0.2.x",
"gm": "1.21.x",
"crypto-cacerts": "0.1.x"
},
"bin": {
Expand All @@ -50,7 +51,7 @@
"pump-stop-following": "./bin/pump-stop-following"
},
"scripts": {
"test": "vows test/*-test.js",
"test": "vows -v test/*-test.js",
"start": "./bin/pump"
},
"repository": {
Expand Down
42 changes: 25 additions & 17 deletions routes/api.js
Expand Up @@ -17,15 +17,12 @@
// limitations under the License.

// Adds to globals
require("set-immediate");

var databank = require("databank"),
_ = require("underscore"),
Step = require("step"),
validator = require("validator"),
OAuth = require("oauth-evanp").OAuth,
check = validator.check,
sanitize = validator.sanitize,
filters = require("../lib/filters"),
version = require("../lib/version").version,
HTTPError = require("../lib/httperror").HTTPError,
Expand Down Expand Up @@ -97,7 +94,7 @@ var addRoutes = function(app) {
// Users
app.get("/api/user/:nickname", smw, anyReadAuth, reqUser, getUser);
app.put("/api/user/:nickname", userWriteOAuth, reqUser, sameUser, putUser);
app.del("/api/user/:nickname", userWriteOAuth, reqUser, sameUser, delUser);
app.delete("/api/user/:nickname", userWriteOAuth, reqUser, sameUser, delUser);

app.get("/api/user/:nickname/profile", smw, anyReadAuth, reqUser, personType, getObject);
app.put("/api/user/:nickname/profile", userWriteOAuth, reqUser, sameUser, personType, reqGenerator, putObject);
Expand Down Expand Up @@ -163,7 +160,7 @@ var addRoutes = function(app) {

app.get("/api/activity/:uuid", smw, anyReadAuth, reqActivity, actorOrRecipient, getActivity);
app.put("/api/activity/:uuid", userWriteOAuth, reqActivity, actorOnly, putActivity);
app.del("/api/activity/:uuid", userWriteOAuth, reqActivity, actorOnly, delActivity);
app.delete("/api/activity/:uuid", userWriteOAuth, reqActivity, actorOnly, delActivity);

// Collection members

Expand Down Expand Up @@ -193,7 +190,7 @@ var addRoutes = function(app) {

app.get("/api/:type/:uuid", smw, anyReadAuth, requestObject, authorOrRecipient, getObject);
app.put("/api/:type/:uuid", userWriteOAuth, requestObject, authorOnly, reqGenerator, putObject);
app.del("/api/:type/:uuid", userWriteOAuth, requestObject, authorOnly, reqGenerator, deleteObject);
app.delete("/api/:type/:uuid", userWriteOAuth, requestObject, authorOnly, reqGenerator, deleteObject);

app.get("/api/:type/:uuid/likes", smw, anyReadAuth, requestObject, authorOrRecipient, objectLikes);
app.get("/api/:type/:uuid/replies", smw, anyReadAuth, requestObject, authorOrRecipient, objectReplies);
Expand Down Expand Up @@ -739,11 +736,10 @@ var createUser = function(req, res, next) {
next(new HTTPError("No email address", 400));
return;
} else {
try {
check(props.email).isEmail();
if (validator.isEmail(props.email)) {
email = props.email;
delete props.email;
} catch (e) {
} else {
next(new HTTPError(e.message, 400));
return;
}
Expand Down Expand Up @@ -1538,8 +1534,11 @@ var streamArgs = function(req, defaultCount, maxCount) {
}

if (_(req.query).has("count")) {
check(req.query.count, "Count must be between 0 and " + maxCount).isInt().min(0).max(maxCount);
args.count = sanitize(req.query.count).toInt();
if (!validator.isInt(req.query.count, {min: 0, max: maxCount})) {
throw new Error("Count must be between 0 and " + maxCount);
}else {
args.count = validator.toInt(req.query.count);
}
} else {
args.count = defaultCount;
}
Expand All @@ -1548,16 +1547,22 @@ var streamArgs = function(req, defaultCount, maxCount) {
// XXX: Check "before" and "since" for URI...?

if (_(req.query).has("before")) {
check(req.query.before).notEmpty();
args.before = sanitize(req.query.before).trim();
if (validator.isNull(req.query.before)) {
throw new Error(req.query.before + " is null");
} else {
args.before = validator.trim(req.query.before);
}
}

if (_(req.query).has("since")) {
if (_(args).has("before")) {
throw new Error("Can't have both 'before' and 'since' parameters");
}
check(req.query.since).notEmpty();
args.since = sanitize(req.query.since).trim();
if (validator.isNull(req.query.since)) {
throw new Error(req.query.since + " is null");
}else {
args.since = validator.trim(req.query.since);
}
}

if (_(req.query).has("offset")) {
Expand All @@ -1567,8 +1572,11 @@ var streamArgs = function(req, defaultCount, maxCount) {
if (_(args).has("since")) {
throw new Error("Can't have both 'since' and 'offset' parameters");
}
check(req.query.offset, "Offset must be an integer greater than or equal to zero").isInt().min(0);
args.start = sanitize(req.query.offset).toInt();
if (!validator.isInt(req.query.offset, {min:0})) {
throw new Error("Offset must be an integer greater than or equal to zero");
}else {
args.start = validator.toInt(req.query.offset);
}
}

if (!_(req.query).has("offset") && !_(req.query).has("since") && !_(req.query).has("before")) {
Expand Down
21 changes: 4 additions & 17 deletions routes/clientreg.js
Expand Up @@ -19,7 +19,6 @@
var _ = require("underscore"),
Step = require("step"),
validator = require("validator"),
check = validator.check,
dialback = require("../lib/dialback"),
maybeDialback = dialback.maybeDialback,
Client = require("../lib/model/client").Client,
Expand Down Expand Up @@ -75,12 +74,7 @@ var clientReg = function(req, res, next) {
}
props.contacts = params.contacts.split(" ");
if (!props.contacts.every(function(contact) {
try {
check(contact).isEmail();
return true;
} catch (err) {
return false;
}
return validator.isEmail(contact);
})) {
next(new HTTPError("contacts must be space-separate email addresses.", 400));
return;
Expand All @@ -102,24 +96,17 @@ var clientReg = function(req, res, next) {
}

if (_(params).has("logo_url")) {
try {
check(params.logo_url).isUrl();
props.logo_url = params.logo_url;
} catch (e) {
if (!validator.isURL(params.logo_url)) {
next(new HTTPError("Invalid logo_url.", 400));
return;
}
props.logo_url = params.logo_url;
}

if (_(params).has("redirect_uris")) {
props.redirect_uris = params.redirect_uris.split(" ");
if (!props.redirect_uris.every(function(uri) {
try {
check(uri).isUrl();
return true;
} catch (err) {
return false;
}
return validator.isURL(uri);
})) {
next(new HTTPError("redirect_uris must be space-separated URLs.", 400));
return;
Expand Down