Skip to content

Commit

Permalink
prepare to async: stricter checks
Browse files Browse the repository at this point in the history
This change is in preparation of the future async refactoring by Ray. It tries
to extract as many changes in boolean conditions as possible, in order to make
more evident identifying eventual logic bugs in the future work.
This proved already useful in at least one case.
  • Loading branch information
muxator committed Mar 1, 2019
1 parent 089994e commit d520e28
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/node/db/AuthorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports.doesAuthorExists = function(authorID, callback)
db.get("globalAuthor:" + authorID, function(err, author) {
if (ERR(err, callback)) return;

callback(null, author != null);
callback(null, author !== null);
});
}

Expand Down Expand Up @@ -212,7 +212,7 @@ exports.listPadsOfAuthor = function(authorID, callback)
db.get("globalAuthor:" + authorID, function(err, author) {
if (ERR(err, callback)) return;

if (author == null) {
if (author === null) {
// author does not exist
callback(new customError("authorID does not exist", "apierror"));

Expand Down Expand Up @@ -242,7 +242,7 @@ exports.addPad = function(authorID, padID)
// get the entry
db.get("globalAuthor:" + authorID, function(err, author) {
if (ERR(err)) return;
if (author == null) return;
if (author === null) return;

if (author.padIDs == null) {
// the entry doesn't exist so far, let's create it
Expand All @@ -266,9 +266,9 @@ exports.removePad = function(authorID, padID)
{
db.get("globalAuthor:" + authorID, function(err, author) {
if (ERR(err)) return;
if (author == null) return;
if (author === null) return;

if (author.padIDs != null) {
if (author.padIDs !== null) {
// remove pad from author
delete author.padIDs[padID];
db.set("globalAuthor:" + authorID, author);
Expand Down
8 changes: 4 additions & 4 deletions src/node/db/GroupManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ exports.deleteGroup = function(groupID, callback)
if (ERR(err, callback)) return;
groups = groups? groups.groupIDs : [];

if (groups.indexOf(groupID) == -1) {
if (groups.indexOf(groupID) === -1) {
// it's not listed
callback();

Expand Down Expand Up @@ -198,7 +198,7 @@ exports.createGroup = function(callback)
exports.createGroupIfNotExistsFor = function(groupMapper, callback)
{
// ensure mapper is optional
if (typeof groupMapper != "string") {
if (typeof groupMapper !== "string") {
callback(new customError("groupMapper is not a string", "apierror"));
return;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ exports.createGroupPad = function(groupID, padName, text, callback)
exports.doesGroupExist(groupID, function(err, exists) {
if (ERR(err, callback)) return;

if (exists == false) {
if (!exists) {
// group does not exist
callback(new customError("groupID does not exist", "apierror"));
return;
Expand Down Expand Up @@ -303,7 +303,7 @@ exports.listPads = function(groupID, callback)
if (ERR(err, callback)) return;

// ensure the group exists
if (exists == false) {
if (!exists) {
callback(new customError("groupID does not exist", "apierror"));
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/node/db/SecurityManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ exports.checkAccess = function(padID, sessionCookie, token, password, callback)
}
} else {
// a session is not required, so we'll check if it's a public pad
if (padID.indexOf("$") == -1) {
if (padID.indexOf("$") === -1) {
// it's not a group pad, means we can grant access

// get author for this token
Expand Down Expand Up @@ -230,7 +230,7 @@ exports.checkAccess = function(padID, sessionCookie, token, password, callback)

// --> grant access
statusObject = { accessStatus: "grant", authorID: sessionAuthor };
} else if (isPasswordProtected && passwordStatus == "wrong") {
} else if (isPasswordProtected && passwordStatus === "wrong") {
// - the pad is password protected but wrong password given

// --> deny access, ask for new password and tell them that the password is wrong
Expand Down Expand Up @@ -261,12 +261,12 @@ exports.checkAccess = function(padID, sessionCookie, token, password, callback)
if (isPublic && !isPasswordProtected) {
// --> grant access, with author of token
statusObject = {accessStatus: "grant", authorID: tokenAuthor};
} else if (isPublic && isPasswordProtected && passwordStatus == "correct") {
} else if (isPublic && isPasswordProtected && passwordStatus === "correct") {
// - it's public and password protected and password is correct

// --> grant access, with author of token
statusObject = {accessStatus: "grant", authorID: tokenAuthor};
} else if (isPublic && isPasswordProtected && passwordStatus == "wrong") {
} else if (isPublic && isPasswordProtected && passwordStatus === "wrong") {
// - it's public and the pad is password protected but wrong password given

// --> deny access, ask for new password and tell them that the password is wrong
Expand Down
2 changes: 1 addition & 1 deletion src/node/handler/APIHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ exports.handle = function(apiVersion, functionName, fields, req, res)
// check the api key!
fields["apikey"] = fields["apikey"] || fields["api_key"];

if (fields["apikey"] != apikey.trim()) {
if (fields["apikey"] !== apikey.trim()) {
res.statusCode = 401;
res.send({code: 4, message: "no or wrong API Key", data: null});
return;
Expand Down
2 changes: 1 addition & 1 deletion src/node/handler/SocketIORouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ exports.setSocketIO = function(_socket) {
var checkAccessCallback = function(err, statusObject) {
ERR(err);

if (statusObject.accessStatus == "grant") {
if (statusObject.accessStatus === "grant") {
// access was granted, mark the client as authorized and handle the message
clientAuthorized = true;
handleMessage(client, message);
Expand Down
2 changes: 1 addition & 1 deletion src/node/padaccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function (req, res, callback) {
securityManager.checkAccess(req.params.pad, req.cookies.sessionID, req.cookies.token, req.cookies.password, function(err, accessObj) {
if (ERR(err, callback)) return;

if (accessObj.accessStatus == "grant") {
if (accessObj.accessStatus === "grant") {
// there is access, continue
callback();
} else {
Expand Down

0 comments on commit d520e28

Please sign in to comment.