Skip to content

Commit

Permalink
Fix Prettier (#7066)
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis authored Dec 13, 2020
1 parent d494857 commit 033a0bd
Show file tree
Hide file tree
Showing 64 changed files with 697 additions and 1,887 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"posttest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} mongodb-runner stop",
"coverage": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 nyc jasmine",
"start": "node ./bin/parse-server",
"prettier": "prettier --write {src,spec}/{**/*,*}.js",
"prettier": "prettier --write '{src,spec}/{**/*,*}.js'",
"prepare": "npm run build",
"postinstall": "node -p 'require(\"./postinstall.js\")()'"
},
Expand Down
19 changes: 10 additions & 9 deletions spec/LdapAuth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ it('Should delete the password from authData after validation', done => {
const options = {
suffix: 'o=example',
url: `ldap://localhost:${port}`,
dn: 'uid={{id}}, o=example'
dn: 'uid={{id}}, o=example',
};

const authData = { id: 'testuser', password: 'secret' };
Expand All @@ -237,22 +237,23 @@ it('Should not save the password in the user record after authentication', done
const options = {
suffix: 'o=example',
url: `ldap://localhost:${port}`,
dn: 'uid={{id}}, o=example'
dn: 'uid={{id}}, o=example',
};
reconfigureServer({ auth: { ldap: options } }).then(() => {
const authData = { authData: { id: 'testuser', password: 'secret' } };
Parse.User.logInWith('ldap', authData).then((returnedUser) => {
const query = new Parse.Query("User");
Parse.User.logInWith('ldap', authData).then(returnedUser => {
const query = new Parse.Query('User');
query
.equalTo('objectId', returnedUser.id).first({ useMasterKey: true })
.then((user) => {
expect(user.get('authData')).toEqual({ ldap:{ id: 'testuser' }});
.equalTo('objectId', returnedUser.id)
.first({ useMasterKey: true })
.then(user => {
expect(user.get('authData')).toEqual({ ldap: { id: 'testuser' } });
expect(user.get('authData').ldap.password).toBeUndefined();
done();
})
.catch(done.fail)
.finally(() => server.close())
})
.finally(() => server.close());
});
});
});
});
83 changes: 26 additions & 57 deletions src/Adapters/Auth/OAuth1Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ var https = require('https'),
crypto = require('crypto');
var Parse = require('parse/node').Parse;

var OAuth = function(options) {
var OAuth = function (options) {
if (!options) {
throw new Parse.Error(
Parse.Error.INTERNAL_SERVER_ERROR,
'No options passed to OAuth'
);
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'No options passed to OAuth');
}
this.consumer_key = options.consumer_key;
this.consumer_secret = options.consumer_secret;
Expand All @@ -17,22 +14,22 @@ var OAuth = function(options) {
this.oauth_params = options.oauth_params || {};
};

OAuth.prototype.send = function(method, path, params, body) {
OAuth.prototype.send = function (method, path, params, body) {
var request = this.buildRequest(method, path, params, body);
// Encode the body properly, the current Parse Implementation don't do it properly
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
var httpRequest = https
.request(request, function(res) {
.request(request, function (res) {
var data = '';
res.on('data', function(chunk) {
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function() {
res.on('end', function () {
data = JSON.parse(data);
resolve(data);
});
})
.on('error', function() {
.on('error', function () {
reject('Failed to make an OAuth request');
});
if (request.body) {
Expand All @@ -42,7 +39,7 @@ OAuth.prototype.send = function(method, path, params, body) {
});
};

OAuth.prototype.buildRequest = function(method, path, params, body) {
OAuth.prototype.buildRequest = function (method, path, params, body) {
if (path.indexOf('/') != 0) {
path = '/' + path;
}
Expand All @@ -62,31 +59,26 @@ OAuth.prototype.buildRequest = function(method, path, params, body) {
oauth_params['oauth_token'] = this.auth_token;
}

request = OAuth.signRequest(
request,
oauth_params,
this.consumer_secret,
this.auth_token_secret
);
request = OAuth.signRequest(request, oauth_params, this.consumer_secret, this.auth_token_secret);

if (body && Object.keys(body).length > 0) {
request.body = OAuth.buildParameterString(body);
}
return request;
};

OAuth.prototype.get = function(path, params) {
OAuth.prototype.get = function (path, params) {
return this.send('GET', path, params);
};

OAuth.prototype.post = function(path, params, body) {
OAuth.prototype.post = function (path, params, body) {
return this.send('POST', path, params, body);
};

/*
Proper string %escape encoding
*/
OAuth.encode = function(str) {
OAuth.encode = function (str) {
// discuss at: http://phpjs.org/functions/rawurlencode/
// original by: Brett Zamir (http://brett-zamir.me)
// input by: travc
Expand Down Expand Up @@ -126,25 +118,23 @@ OAuth.version = '1.0';
/*
Generate a nonce
*/
OAuth.nonce = function() {
OAuth.nonce = function () {
var text = '';
var possible =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

for (var i = 0; i < 30; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
for (var i = 0; i < 30; i++) text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
};

OAuth.buildParameterString = function(obj) {
OAuth.buildParameterString = function (obj) {
// Sort keys and encode values
if (obj) {
var keys = Object.keys(obj).sort();

// Map key=value, join them by &
return keys
.map(function(key) {
.map(function (key) {
return key + '=' + OAuth.encode(obj[key]);
})
.join('&');
Expand All @@ -157,33 +147,19 @@ OAuth.buildParameterString = function(obj) {
Build the signature string from the object
*/

OAuth.buildSignatureString = function(method, url, parameters) {
return [
method.toUpperCase(),
OAuth.encode(url),
OAuth.encode(parameters),
].join('&');
OAuth.buildSignatureString = function (method, url, parameters) {
return [method.toUpperCase(), OAuth.encode(url), OAuth.encode(parameters)].join('&');
};

/*
Retuns encoded HMAC-SHA1 from key and text
*/
OAuth.signature = function(text, key) {
OAuth.signature = function (text, key) {
crypto = require('crypto');
return OAuth.encode(
crypto
.createHmac('sha1', key)
.update(text)
.digest('base64')
);
return OAuth.encode(crypto.createHmac('sha1', key).update(text).digest('base64'));
};

OAuth.signRequest = function(
request,
oauth_parameters,
consumer_secret,
auth_token_secret
) {
OAuth.signRequest = function (request, oauth_parameters, consumer_secret, auth_token_secret) {
oauth_parameters = oauth_parameters || {};

// Set default values
Expand Down Expand Up @@ -224,16 +200,9 @@ OAuth.signRequest = function(
// Build the signature string
var url = 'https://' + request.host + '' + request.path;

var signatureString = OAuth.buildSignatureString(
request.method,
url,
parameterString
);
var signatureString = OAuth.buildSignatureString(request.method, url, parameterString);
// Hash the signature string
var signatureKey = [
OAuth.encode(consumer_secret),
OAuth.encode(auth_token_secret),
].join('&');
var signatureKey = [OAuth.encode(consumer_secret), OAuth.encode(auth_token_secret)].join('&');

var signature = OAuth.signature(signatureString, signatureKey);

Expand All @@ -246,7 +215,7 @@ OAuth.signRequest = function(
// Set the authorization header
var authHeader = Object.keys(oauth_parameters)
.sort()
.map(function(key) {
.map(function (key) {
var value = oauth_parameters[key];
return key + '="' + value + '"';
})
Expand Down
26 changes: 5 additions & 21 deletions src/Adapters/Auth/apple.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,15 @@ const getAppleKeyByKeyId = async (keyId, cacheMaxEntries, cacheMaxAge) => {
const getHeaderFromToken = token => {
const decodedToken = jwt.decode(token, { complete: true });
if (!decodedToken) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
`provided token does not decode as JWT`
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `provided token does not decode as JWT`);
}

return decodedToken.header;
};

const verifyIdToken = async (
{ token, id },
{ clientId, cacheMaxEntries, cacheMaxAge }
) => {
const verifyIdToken = async ({ token, id }, { clientId, cacheMaxEntries, cacheMaxAge }) => {
if (!token) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
`id token is invalid for this user.`
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `id token is invalid for this user.`);
}

const { kid: keyId, alg: algorithm } = getHeaderFromToken(token);
Expand All @@ -60,11 +51,7 @@ const verifyIdToken = async (
cacheMaxAge = cacheMaxAge || ONE_HOUR_IN_MS;
cacheMaxEntries = cacheMaxEntries || 5;

const appleKey = await getAppleKeyByKeyId(
keyId,
cacheMaxEntries,
cacheMaxAge
);
const appleKey = await getAppleKeyByKeyId(keyId, cacheMaxEntries, cacheMaxAge);
const signingKey = appleKey.publicKey || appleKey.rsaPublicKey;

try {
Expand All @@ -87,10 +74,7 @@ const verifyIdToken = async (
}

if (jwtClaims.sub !== id) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
`auth data is invalid for this user.`
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `auth data is invalid for this user.`);
}
return jwtClaims;
};
Expand Down
24 changes: 5 additions & 19 deletions src/Adapters/Auth/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ function getAppSecretPath(authData, options = {}) {
// Returns a promise that fulfills iff this user id is valid.
function validateAuthData(authData, options) {
return graphRequest(
'me?fields=id&access_token=' +
authData.access_token +
getAppSecretPath(authData, options)
'me?fields=id&access_token=' + authData.access_token + getAppSecretPath(authData, options)
).then(data => {
if (
(data && data.id == authData.id) ||
(process.env.TESTING && authData.id === 'test')
) {
if ((data && data.id == authData.id) || (process.env.TESTING && authData.id === 'test')) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Facebook auth is invalid for this user.'
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is invalid for this user.');
});
}

Expand All @@ -43,21 +35,15 @@ function validateAppId(appIds, authData, options) {
return Promise.resolve();
}
if (!appIds.length) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Facebook auth is not configured.'
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is not configured.');
}
return graphRequest(
'app?access_token=' + access_token + getAppSecretPath(authData, options)
).then(data => {
if (data && appIds.indexOf(data.id) != -1) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Facebook auth is invalid for this user.'
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is invalid for this user.');
});
}

Expand Down
10 changes: 2 additions & 8 deletions src/Adapters/Auth/gcenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,14 @@ function verifySignature(publicKey, authData) {
verifier.update(authData.salt, 'base64');

if (!verifier.verify(publicKey, authData.signature, 'base64')) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Apple Game Center - invalid signature'
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Apple Game Center - invalid signature');
}
}

// Returns a promise that fulfills if this user id is valid.
async function validateAuthData(authData) {
if (!authData.id) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Apple Game Center - authData id missing'
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Apple Game Center - authData id missing');
}
authData.playerId = authData.id;
const publicKey = await getAppleCertificate(authData.publicKeyUrl);
Expand Down
5 changes: 1 addition & 4 deletions src/Adapters/Auth/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ function validateAuthData(authData) {
if (data && data.id == authData.id) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Github auth is invalid for this user.'
);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Github auth is invalid for this user.');
});
}

Expand Down
Loading

0 comments on commit 033a0bd

Please sign in to comment.