Skip to content

Commit

Permalink
Changed the response code/message (to 401 Unauthorized) to ask the cl…
Browse files Browse the repository at this point in the history
…ient to authenticate the user
  • Loading branch information
AdrienCastex committed Jun 12, 2017
1 parent 4e8c78c commit 14e7c76
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/server/MethodCallArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var MethodCallArgs = (function () {
return;
}
if (!can) {
_this.setCode(HTTPCodes_1.HTTPCodes.Forbidden);
_this.setCode(HTTPCodes_1.HTTPCodes.Unauthorized);
_this.exit();
return;
}
Expand Down
24 changes: 18 additions & 6 deletions lib/server/commands/Propfind.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var WebDAVRequest_1 = require("../WebDAVRequest");
var IResource_1 = require("../../resource/IResource");
var XML_1 = require("../../helper/XML");
var FSPath_1 = require("../../manager/FSPath");
var Errors_1 = require("../../Errors");
var http = require("http");
function lockDiscovery(lockDiscoveryCache, arg, path, resource, callback) {
var cached = lockDiscoveryCache[path.toString()];
Expand Down Expand Up @@ -98,7 +99,17 @@ function default_1(arg, callback) {
});
resource.type(function (e, type) { return process.nextTick(function () {
if (!type.isDirectory || arg.depth === 0) {
addXMLInfo(resource, multistatus, function () { return done(multistatus); });
addXMLInfo(resource, multistatus, function (e) {
if (!e)
done(multistatus);
else {
if (e === Errors_1.Errors.BadAuthentication)
arg.setCode(WebDAVRequest_1.HTTPCodes.Unauthorized);
else
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
callback();
}
});
return;
}
arg.requirePrivilege('canGetChildren', resource, function () {
Expand All @@ -107,7 +118,10 @@ function default_1(arg, callback) {
function nbOut(error) {
if (nb > 0 && error) {
nb = -1;
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
if (error === Errors_1.Errors.BadAuthentication)
arg.setCode(WebDAVRequest_1.HTTPCodes.Unauthorized);
else
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
callback();
return;
}
Expand All @@ -133,13 +147,11 @@ function default_1(arg, callback) {
privileges.push('canSource');
arg.requireErPrivilege(privileges, resource, function (e, can) {
if (e) {
propstat.ele('D:status').add(propstatStatus(WebDAVRequest_1.HTTPCodes.InternalServerError));
callback();
callback(e);
return;
}
if (!can) {
propstat.ele('D:status').add(propstatStatus(WebDAVRequest_1.HTTPCodes.Forbidden));
callback();
callback(Errors_1.Errors.BadAuthentication);
return;
}
propstat.ele('D:status').add('HTTP/1.1 200 OK');
Expand Down
2 changes: 1 addition & 1 deletion src/server/MethodCallArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class MethodCallArgs

if(!can)
{
this.setCode(HTTPCodes.Forbidden);
this.setCode(HTTPCodes.Unauthorized);
this.exit();
return;
}
Expand Down
28 changes: 20 additions & 8 deletions src/server/commands/Propfind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,18 @@ export default function(arg : MethodCallArgs, callback)
resource.type((e, type) => process.nextTick(() => {
if(!type.isDirectory || arg.depth === 0)
{
addXMLInfo(resource, multistatus, () => done(multistatus))
addXMLInfo(resource, multistatus, (e) => {
if(!e)
done(multistatus);
else
{
if(e === Errors.BadAuthentication)
arg.setCode(HTTPCodes.Unauthorized);
else
arg.setCode(HTTPCodes.InternalServerError);
callback();
}
})
return;
}

Expand All @@ -148,7 +159,10 @@ export default function(arg : MethodCallArgs, callback)
if(nb > 0 && error)
{
nb = -1;
arg.setCode(HTTPCodes.InternalServerError);
if(error === Errors.BadAuthentication)
arg.setCode(HTTPCodes.Unauthorized);
else
arg.setCode(HTTPCodes.InternalServerError);
callback();
return;
}
Expand All @@ -158,8 +172,8 @@ export default function(arg : MethodCallArgs, callback)
done(multistatus);
}

addXMLInfo(resource, multistatus, nbOut)
addXMLInfo(resource, multistatus, nbOut);

children.forEach((child) => process.nextTick(() => {
addXMLInfo(child, multistatus, nbOut)
}))
Expand All @@ -183,15 +197,13 @@ export default function(arg : MethodCallArgs, callback)
arg.requireErPrivilege(privileges, resource, (e, can) => {
if(e)
{
propstat.ele('D:status').add(propstatStatus(HTTPCodes.InternalServerError));
callback();
callback(e);
return;
}

if(!can)
{
propstat.ele('D:status').add(propstatStatus(HTTPCodes.Forbidden));
callback();
callback(Errors.BadAuthentication);
return;
}

Expand Down

0 comments on commit 14e7c76

Please sign in to comment.