Introduce ESLint and Prettier

This commit is contained in:
Zaid Abdulla committed 2018-08-24 05:31:22 -07:00
1 parent 9c943d0bbf
commit e494bdca8a
26 files changed
+1585 -1594

No files matched your search

+34 -22
View File
@@ -23,7 +23,7 @@ const crypto = require("crypto");
function parseAuthHeader(authHeader) {
authHeader = authHeader.trim();
const method = authHeader.split(" ", 1)[0];
const res = {method: method};
const res = { method: method };
const parts = authHeader.slice(method.length + 1).split(",");
let part;
@@ -38,8 +38,7 @@ function parseAuthHeader(authHeader) {
} else {
while (!/[^\\]"\s*$/.test(value)) {
const p = parts.shift();
if (p == null)
throw new Error("Unable to parse auth header");
if (p == null) throw new Error("Unable to parse auth header");
value += "," + p;
}
@@ -55,7 +54,7 @@ function parseAuthHeader(authHeader) {
}
function basic(username, password) {
return "Basic " + (new Buffer(`${username}:${password}`).toString("base64"));
return "Basic " + new Buffer(`${username}:${password}`).toString("base64");
}
function digest(username, password, uri, httpMethod, body, authHeader) {
@@ -64,40 +63,53 @@ function digest(username, password, uri, httpMethod, body, authHeader) {
let qop;
if (authHeader.qop) {
if (authHeader.qop.indexOf(",") !== -1)
qop = "auth"; // Either auth or auth-int, prefer auth
else
qop = authHeader.qop;
if (authHeader.qop.indexOf(",") !== -1) qop = "auth";
// Either auth or auth-int, prefer auth
else qop = authHeader.qop;
}
let ha1 = crypto.createHash("md5");
ha1.update(username).update(":").update(authHeader.realm).update(":").update(password);
ha1
.update(username)
.update(":")
.update(authHeader.realm)
.update(":")
.update(password);
// TODO support "MD5-sess" algorithm directive
ha1 = ha1.digest("hex");
let ha2 = crypto.createHash("md5");
ha2.update(httpMethod).update(":").update(uri);
if (qop === "auth-int")
ha2.update(":").update(body);
ha2
.update(httpMethod)
.update(":")
.update(uri);
if (qop === "auth-int") ha2.update(":").update(body);
ha2 = ha2.digest("hex");
let hash = crypto.createHash("md5");
hash.update(ha1).update(":").update(authHeader.nonce);
if (qop)
hash.update(":").update(nc).update(":").update(cnonce).update(":").update(qop);
hash
.update(ha1)
.update(":")
.update(authHeader.nonce);
if (qop) {
hash
.update(":")
.update(nc)
.update(":")
.update(cnonce)
.update(":")
.update(qop);
}
hash.update(":").update(ha2);
let authString = `Digest username="${username}"`;
authString += `,realm="${authHeader.realm}"`;
authString += `,nonce="${authHeader.nonce}"`;
authString += `,uri="${url}"`;
if (authHeader.algorithm)
authString += `,algorithm=${authHeader.algorithm}`;
if (qop)
authString += `,qop=${qop},nc=${nc},cnonce="${cnonce}"`;
authString += `,uri="${uri}"`;
if (authHeader.algorithm) authString += `,algorithm=${authHeader.algorithm}`;
if (qop) authString += `,qop=${qop},nc=${nc},cnonce="${cnonce}"`;
authString += `,response="${hash.digest("hex")}"`;
if (authHeader.opaque)
authString += `,opaque="${authHeader.opaque}"`;
if (authHeader.opaque) authString += `,opaque="${authHeader.opaque}"`;
return authString;
}