Skip to content

Commit 033a0bd

Browse files
authored
Fix Prettier (#7066)
1 parent d494857 commit 033a0bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+697
-1887
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"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",
106106
"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",
107107
"start": "node ./bin/parse-server",
108-
"prettier": "prettier --write {src,spec}/{**/*,*}.js",
108+
"prettier": "prettier --write '{src,spec}/{**/*,*}.js'",
109109
"prepare": "npm run build",
110110
"postinstall": "node -p 'require(\"./postinstall.js\")()'"
111111
},

spec/LdapAuth.spec.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ it('Should delete the password from authData after validation', done => {
216216
const options = {
217217
suffix: 'o=example',
218218
url: `ldap://localhost:${port}`,
219-
dn: 'uid={{id}}, o=example'
219+
dn: 'uid={{id}}, o=example',
220220
};
221221

222222
const authData = { id: 'testuser', password: 'secret' };
@@ -237,22 +237,23 @@ it('Should not save the password in the user record after authentication', done
237237
const options = {
238238
suffix: 'o=example',
239239
url: `ldap://localhost:${port}`,
240-
dn: 'uid={{id}}, o=example'
240+
dn: 'uid={{id}}, o=example',
241241
};
242242
reconfigureServer({ auth: { ldap: options } }).then(() => {
243243
const authData = { authData: { id: 'testuser', password: 'secret' } };
244-
Parse.User.logInWith('ldap', authData).then((returnedUser) => {
245-
const query = new Parse.Query("User");
244+
Parse.User.logInWith('ldap', authData).then(returnedUser => {
245+
const query = new Parse.Query('User');
246246
query
247-
.equalTo('objectId', returnedUser.id).first({ useMasterKey: true })
248-
.then((user) => {
249-
expect(user.get('authData')).toEqual({ ldap:{ id: 'testuser' }});
247+
.equalTo('objectId', returnedUser.id)
248+
.first({ useMasterKey: true })
249+
.then(user => {
250+
expect(user.get('authData')).toEqual({ ldap: { id: 'testuser' } });
250251
expect(user.get('authData').ldap.password).toBeUndefined();
251252
done();
252253
})
253254
.catch(done.fail)
254-
.finally(() => server.close())
255-
})
255+
.finally(() => server.close());
256+
});
256257
});
257258
});
258259
});

src/Adapters/Auth/OAuth1Client.js

+26-57
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ var https = require('https'),
22
crypto = require('crypto');
33
var Parse = require('parse/node').Parse;
44

5-
var OAuth = function(options) {
5+
var OAuth = function (options) {
66
if (!options) {
7-
throw new Parse.Error(
8-
Parse.Error.INTERNAL_SERVER_ERROR,
9-
'No options passed to OAuth'
10-
);
7+
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'No options passed to OAuth');
118
}
129
this.consumer_key = options.consumer_key;
1310
this.consumer_secret = options.consumer_secret;
@@ -17,22 +14,22 @@ var OAuth = function(options) {
1714
this.oauth_params = options.oauth_params || {};
1815
};
1916

20-
OAuth.prototype.send = function(method, path, params, body) {
17+
OAuth.prototype.send = function (method, path, params, body) {
2118
var request = this.buildRequest(method, path, params, body);
2219
// Encode the body properly, the current Parse Implementation don't do it properly
23-
return new Promise(function(resolve, reject) {
20+
return new Promise(function (resolve, reject) {
2421
var httpRequest = https
25-
.request(request, function(res) {
22+
.request(request, function (res) {
2623
var data = '';
27-
res.on('data', function(chunk) {
24+
res.on('data', function (chunk) {
2825
data += chunk;
2926
});
30-
res.on('end', function() {
27+
res.on('end', function () {
3128
data = JSON.parse(data);
3229
resolve(data);
3330
});
3431
})
35-
.on('error', function() {
32+
.on('error', function () {
3633
reject('Failed to make an OAuth request');
3734
});
3835
if (request.body) {
@@ -42,7 +39,7 @@ OAuth.prototype.send = function(method, path, params, body) {
4239
});
4340
};
4441

45-
OAuth.prototype.buildRequest = function(method, path, params, body) {
42+
OAuth.prototype.buildRequest = function (method, path, params, body) {
4643
if (path.indexOf('/') != 0) {
4744
path = '/' + path;
4845
}
@@ -62,31 +59,26 @@ OAuth.prototype.buildRequest = function(method, path, params, body) {
6259
oauth_params['oauth_token'] = this.auth_token;
6360
}
6461

65-
request = OAuth.signRequest(
66-
request,
67-
oauth_params,
68-
this.consumer_secret,
69-
this.auth_token_secret
70-
);
62+
request = OAuth.signRequest(request, oauth_params, this.consumer_secret, this.auth_token_secret);
7163

7264
if (body && Object.keys(body).length > 0) {
7365
request.body = OAuth.buildParameterString(body);
7466
}
7567
return request;
7668
};
7769

78-
OAuth.prototype.get = function(path, params) {
70+
OAuth.prototype.get = function (path, params) {
7971
return this.send('GET', path, params);
8072
};
8173

82-
OAuth.prototype.post = function(path, params, body) {
74+
OAuth.prototype.post = function (path, params, body) {
8375
return this.send('POST', path, params, body);
8476
};
8577

8678
/*
8779
Proper string %escape encoding
8880
*/
89-
OAuth.encode = function(str) {
81+
OAuth.encode = function (str) {
9082
// discuss at: http://phpjs.org/functions/rawurlencode/
9183
// original by: Brett Zamir (http://brett-zamir.me)
9284
// input by: travc
@@ -126,25 +118,23 @@ OAuth.version = '1.0';
126118
/*
127119
Generate a nonce
128120
*/
129-
OAuth.nonce = function() {
121+
OAuth.nonce = function () {
130122
var text = '';
131-
var possible =
132-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
123+
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
133124

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

137127
return text;
138128
};
139129

140-
OAuth.buildParameterString = function(obj) {
130+
OAuth.buildParameterString = function (obj) {
141131
// Sort keys and encode values
142132
if (obj) {
143133
var keys = Object.keys(obj).sort();
144134

145135
// Map key=value, join them by &
146136
return keys
147-
.map(function(key) {
137+
.map(function (key) {
148138
return key + '=' + OAuth.encode(obj[key]);
149139
})
150140
.join('&');
@@ -157,33 +147,19 @@ OAuth.buildParameterString = function(obj) {
157147
Build the signature string from the object
158148
*/
159149

160-
OAuth.buildSignatureString = function(method, url, parameters) {
161-
return [
162-
method.toUpperCase(),
163-
OAuth.encode(url),
164-
OAuth.encode(parameters),
165-
].join('&');
150+
OAuth.buildSignatureString = function (method, url, parameters) {
151+
return [method.toUpperCase(), OAuth.encode(url), OAuth.encode(parameters)].join('&');
166152
};
167153

168154
/*
169155
Retuns encoded HMAC-SHA1 from key and text
170156
*/
171-
OAuth.signature = function(text, key) {
157+
OAuth.signature = function (text, key) {
172158
crypto = require('crypto');
173-
return OAuth.encode(
174-
crypto
175-
.createHmac('sha1', key)
176-
.update(text)
177-
.digest('base64')
178-
);
159+
return OAuth.encode(crypto.createHmac('sha1', key).update(text).digest('base64'));
179160
};
180161

181-
OAuth.signRequest = function(
182-
request,
183-
oauth_parameters,
184-
consumer_secret,
185-
auth_token_secret
186-
) {
162+
OAuth.signRequest = function (request, oauth_parameters, consumer_secret, auth_token_secret) {
187163
oauth_parameters = oauth_parameters || {};
188164

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

227-
var signatureString = OAuth.buildSignatureString(
228-
request.method,
229-
url,
230-
parameterString
231-
);
203+
var signatureString = OAuth.buildSignatureString(request.method, url, parameterString);
232204
// Hash the signature string
233-
var signatureKey = [
234-
OAuth.encode(consumer_secret),
235-
OAuth.encode(auth_token_secret),
236-
].join('&');
205+
var signatureKey = [OAuth.encode(consumer_secret), OAuth.encode(auth_token_secret)].join('&');
237206

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

@@ -246,7 +215,7 @@ OAuth.signRequest = function(
246215
// Set the authorization header
247216
var authHeader = Object.keys(oauth_parameters)
248217
.sort()
249-
.map(function(key) {
218+
.map(function (key) {
250219
var value = oauth_parameters[key];
251220
return key + '="' + value + '"';
252221
})

src/Adapters/Auth/apple.js

+5-21
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,15 @@ const getAppleKeyByKeyId = async (keyId, cacheMaxEntries, cacheMaxAge) => {
3333
const getHeaderFromToken = token => {
3434
const decodedToken = jwt.decode(token, { complete: true });
3535
if (!decodedToken) {
36-
throw new Parse.Error(
37-
Parse.Error.OBJECT_NOT_FOUND,
38-
`provided token does not decode as JWT`
39-
);
36+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `provided token does not decode as JWT`);
4037
}
4138

4239
return decodedToken.header;
4340
};
4441

45-
const verifyIdToken = async (
46-
{ token, id },
47-
{ clientId, cacheMaxEntries, cacheMaxAge }
48-
) => {
42+
const verifyIdToken = async ({ token, id }, { clientId, cacheMaxEntries, cacheMaxAge }) => {
4943
if (!token) {
50-
throw new Parse.Error(
51-
Parse.Error.OBJECT_NOT_FOUND,
52-
`id token is invalid for this user.`
53-
);
44+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `id token is invalid for this user.`);
5445
}
5546

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

63-
const appleKey = await getAppleKeyByKeyId(
64-
keyId,
65-
cacheMaxEntries,
66-
cacheMaxAge
67-
);
54+
const appleKey = await getAppleKeyByKeyId(keyId, cacheMaxEntries, cacheMaxAge);
6855
const signingKey = appleKey.publicKey || appleKey.rsaPublicKey;
6956

7057
try {
@@ -87,10 +74,7 @@ const verifyIdToken = async (
8774
}
8875

8976
if (jwtClaims.sub !== id) {
90-
throw new Parse.Error(
91-
Parse.Error.OBJECT_NOT_FOUND,
92-
`auth data is invalid for this user.`
93-
);
77+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `auth data is invalid for this user.`);
9478
}
9579
return jwtClaims;
9680
};

src/Adapters/Auth/facebook.js

+5-19
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,12 @@ function getAppSecretPath(authData, options = {}) {
1919
// Returns a promise that fulfills iff this user id is valid.
2020
function validateAuthData(authData, options) {
2121
return graphRequest(
22-
'me?fields=id&access_token=' +
23-
authData.access_token +
24-
getAppSecretPath(authData, options)
22+
'me?fields=id&access_token=' + authData.access_token + getAppSecretPath(authData, options)
2523
).then(data => {
26-
if (
27-
(data && data.id == authData.id) ||
28-
(process.env.TESTING && authData.id === 'test')
29-
) {
24+
if ((data && data.id == authData.id) || (process.env.TESTING && authData.id === 'test')) {
3025
return;
3126
}
32-
throw new Parse.Error(
33-
Parse.Error.OBJECT_NOT_FOUND,
34-
'Facebook auth is invalid for this user.'
35-
);
27+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is invalid for this user.');
3628
});
3729
}
3830

@@ -43,21 +35,15 @@ function validateAppId(appIds, authData, options) {
4335
return Promise.resolve();
4436
}
4537
if (!appIds.length) {
46-
throw new Parse.Error(
47-
Parse.Error.OBJECT_NOT_FOUND,
48-
'Facebook auth is not configured.'
49-
);
38+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is not configured.');
5039
}
5140
return graphRequest(
5241
'app?access_token=' + access_token + getAppSecretPath(authData, options)
5342
).then(data => {
5443
if (data && appIds.indexOf(data.id) != -1) {
5544
return;
5645
}
57-
throw new Parse.Error(
58-
Parse.Error.OBJECT_NOT_FOUND,
59-
'Facebook auth is invalid for this user.'
60-
);
46+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is invalid for this user.');
6147
});
6248
}
6349

src/Adapters/Auth/gcenter.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,14 @@ function verifySignature(publicKey, authData) {
9696
verifier.update(authData.salt, 'base64');
9797

9898
if (!verifier.verify(publicKey, authData.signature, 'base64')) {
99-
throw new Parse.Error(
100-
Parse.Error.OBJECT_NOT_FOUND,
101-
'Apple Game Center - invalid signature'
102-
);
99+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Apple Game Center - invalid signature');
103100
}
104101
}
105102

106103
// Returns a promise that fulfills if this user id is valid.
107104
async function validateAuthData(authData) {
108105
if (!authData.id) {
109-
throw new Parse.Error(
110-
Parse.Error.OBJECT_NOT_FOUND,
111-
'Apple Game Center - authData id missing'
112-
);
106+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Apple Game Center - authData id missing');
113107
}
114108
authData.playerId = authData.id;
115109
const publicKey = await getAppleCertificate(authData.publicKeyUrl);

src/Adapters/Auth/github.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ function validateAuthData(authData) {
88
if (data && data.id == authData.id) {
99
return;
1010
}
11-
throw new Parse.Error(
12-
Parse.Error.OBJECT_NOT_FOUND,
13-
'Github auth is invalid for this user.'
14-
);
11+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Github auth is invalid for this user.');
1512
});
1613
}
1714

0 commit comments

Comments
 (0)