mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
PadMessageHandler: reversed condition to make core logic evident. No behavioural changes.
This one replaces a big "if (message)" negating its truthy condition. Being lame, I erred on the safe side and wrote a super ugly statement that is guaranteed to respect the original logic. In the hope that eventual logic errors become more evident now. See: https://stackoverflow.com/questions/36661748/what-is-the-exact-negation-of-ifvariable-in-javascript#36661843
This commit is contained in:
parent
324929ca2d
commit
b60c0b122c
1 changed files with 64 additions and 53 deletions
|
@ -244,60 +244,71 @@ exports.handleMessage = function(client, message)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (message) {
|
/*
|
||||||
async.series([
|
* In a previous version of this code, an "if (message)" wrapped the
|
||||||
handleMessageHook,
|
* following async.series().
|
||||||
//check permissions
|
* This ugly "!Boolean(message)" is a lame way to exactly negate the truthy
|
||||||
function(callback)
|
* condition and replace it with an early return, while being sure to leave
|
||||||
{
|
* the original behaviour unchanged.
|
||||||
// client tried to auth for the first time (first msg from the client)
|
*
|
||||||
if(message.type == "CLIENT_READY") {
|
* A shallower code could maybe make more evident latent logic errors.
|
||||||
createSessionInfo(client, message);
|
*/
|
||||||
}
|
if (!Boolean(message)) {
|
||||||
|
return;
|
||||||
// Note: message.sessionID is an entirely different kind of
|
|
||||||
// session from the sessions we use here! Beware!
|
|
||||||
// FIXME: Call our "sessions" "connections".
|
|
||||||
// FIXME: Use a hook instead
|
|
||||||
// FIXME: Allow to override readwrite access with readonly
|
|
||||||
|
|
||||||
// Simulate using the load testing tool
|
|
||||||
if(!sessioninfos[client.id].auth){
|
|
||||||
console.error("Auth was never applied to a session. If you are using the stress-test tool then restart Etherpad and the Stress test tool.")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var auth = sessioninfos[client.id].auth;
|
|
||||||
var checkAccessCallback = function(err, statusObject)
|
|
||||||
{
|
|
||||||
if(ERR(err, callback)) return;
|
|
||||||
|
|
||||||
//access was granted
|
|
||||||
if(statusObject.accessStatus == "grant")
|
|
||||||
{
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
//no access, send the client a message that tell him why
|
|
||||||
else
|
|
||||||
{
|
|
||||||
client.json.send({accessStatus: statusObject.accessStatus})
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//check if pad is requested via readOnly
|
|
||||||
if (auth.padID.indexOf("r.") === 0) {
|
|
||||||
//Pad is readOnly, first get the real Pad ID
|
|
||||||
readOnlyManager.getPadId(auth.padID, function(err, value) {
|
|
||||||
ERR(err);
|
|
||||||
securityManager.checkAccess(value, auth.sessionID, auth.token, auth.password, checkAccessCallback);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
securityManager.checkAccess(auth.padID, auth.sessionID, auth.token, auth.password, checkAccessCallback);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
finalHandler
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async.series([
|
||||||
|
handleMessageHook,
|
||||||
|
//check permissions
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
// client tried to auth for the first time (first msg from the client)
|
||||||
|
if(message.type == "CLIENT_READY") {
|
||||||
|
createSessionInfo(client, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: message.sessionID is an entirely different kind of
|
||||||
|
// session from the sessions we use here! Beware!
|
||||||
|
// FIXME: Call our "sessions" "connections".
|
||||||
|
// FIXME: Use a hook instead
|
||||||
|
// FIXME: Allow to override readwrite access with readonly
|
||||||
|
|
||||||
|
// Simulate using the load testing tool
|
||||||
|
if(!sessioninfos[client.id].auth){
|
||||||
|
console.error("Auth was never applied to a session. If you are using the stress-test tool then restart Etherpad and the Stress test tool.")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var auth = sessioninfos[client.id].auth;
|
||||||
|
var checkAccessCallback = function(err, statusObject)
|
||||||
|
{
|
||||||
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
|
//access was granted
|
||||||
|
if(statusObject.accessStatus == "grant")
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
//no access, send the client a message that tell him why
|
||||||
|
else
|
||||||
|
{
|
||||||
|
client.json.send({accessStatus: statusObject.accessStatus})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//check if pad is requested via readOnly
|
||||||
|
if (auth.padID.indexOf("r.") === 0) {
|
||||||
|
//Pad is readOnly, first get the real Pad ID
|
||||||
|
readOnlyManager.getPadId(auth.padID, function(err, value) {
|
||||||
|
ERR(err);
|
||||||
|
securityManager.checkAccess(value, auth.sessionID, auth.token, auth.password, checkAccessCallback);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
securityManager.checkAccess(auth.padID, auth.sessionID, auth.token, auth.password, checkAccessCallback);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
finalHandler
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue