Skip to content

Commit 88e958a

Browse files
authored
Prettier some files + opti object relation (#7044)
1 parent de9c7dc commit 88e958a

File tree

4 files changed

+40
-133
lines changed

4 files changed

+40
-133
lines changed

spec/GridFSBucketStorageAdapter.spec.js

Lines changed: 18 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
4444
await expectMissingFile(encryptedAdapter, 'myFileName');
4545
const originalString = 'abcdefghi';
4646
await encryptedAdapter.createFile('myFileName', originalString);
47-
const unencryptedResult = await unencryptedAdapter.getFileData(
48-
'myFileName'
49-
);
47+
const unencryptedResult = await unencryptedAdapter.getFileData('myFileName');
5048
expect(unencryptedResult.toString('utf8')).not.toBe(originalString);
5149
const encryptedResult = await encryptedAdapter.getFileData('myFileName');
5250
expect(encryptedResult.toString('utf8')).toBe(originalString);
@@ -71,10 +69,7 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
7169
const unencryptedResult2 = await unencryptedAdapter.getFileData(fileName2);
7270
expect(unencryptedResult2.toString('utf8')).toBe(data2);
7371
//Check if encrypted adapter can read data and make sure it's not the same as unEncrypted adapter
74-
const {
75-
rotated,
76-
notRotated,
77-
} = await encryptedAdapter.rotateEncryptionKey();
72+
const { rotated, notRotated } = await encryptedAdapter.rotateEncryptionKey();
7873
expect(rotated.length).toEqual(2);
7974
expect(
8075
rotated.filter(function (value) {
@@ -101,30 +96,18 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
10196

10297
it('should rotate key of all old encrypted GridFS files to encrypted files', async () => {
10398
const oldEncryptionKey = 'oldKeyThatILoved';
104-
const oldEncryptedAdapter = new GridFSBucketAdapter(
105-
databaseURI,
106-
{},
107-
oldEncryptionKey
108-
);
109-
const encryptedAdapter = new GridFSBucketAdapter(
110-
databaseURI,
111-
{},
112-
'newKeyThatILove'
113-
);
99+
const oldEncryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, oldEncryptionKey);
100+
const encryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, 'newKeyThatILove');
114101
const fileName1 = 'file1.txt';
115102
const data1 = 'hello world';
116103
const fileName2 = 'file2.txt';
117104
const data2 = 'hello new world';
118105
//Store unecrypted files
119106
await oldEncryptedAdapter.createFile(fileName1, data1);
120-
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(
121-
fileName1
122-
);
107+
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(fileName1);
123108
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
124109
await oldEncryptedAdapter.createFile(fileName2, data2);
125-
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(
126-
fileName2
127-
);
110+
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(fileName2);
128111
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
129112
//Check if encrypted adapter can read data and make sure it's not the same as unEncrypted adapter
130113
const { rotated, notRotated } = await encryptedAdapter.rotateEncryptionKey({
@@ -170,32 +153,21 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
170153

171154
it('should rotate key of all old encrypted GridFS files to unencrypted files', async () => {
172155
const oldEncryptionKey = 'oldKeyThatILoved';
173-
const oldEncryptedAdapter = new GridFSBucketAdapter(
174-
databaseURI,
175-
{},
176-
oldEncryptionKey
177-
);
156+
const oldEncryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, oldEncryptionKey);
178157
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
179158
const fileName1 = 'file1.txt';
180159
const data1 = 'hello world';
181160
const fileName2 = 'file2.txt';
182161
const data2 = 'hello new world';
183162
//Store unecrypted files
184163
await oldEncryptedAdapter.createFile(fileName1, data1);
185-
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(
186-
fileName1
187-
);
164+
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(fileName1);
188165
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
189166
await oldEncryptedAdapter.createFile(fileName2, data2);
190-
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(
191-
fileName2
192-
);
167+
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(fileName2);
193168
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
194169
//Check if unEncrypted adapter can read data and make sure it's not the same as oldEncrypted adapter
195-
const {
196-
rotated,
197-
notRotated,
198-
} = await unEncryptedAdapter.rotateEncryptionKey({
170+
const { rotated, notRotated } = await unEncryptedAdapter.rotateEncryptionKey({
199171
oldKey: oldEncryptionKey,
200172
});
201173
expect(rotated.length).toEqual(2);
@@ -238,31 +210,19 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
238210

239211
it('should only encrypt specified fileNames', async () => {
240212
const oldEncryptionKey = 'oldKeyThatILoved';
241-
const oldEncryptedAdapter = new GridFSBucketAdapter(
242-
databaseURI,
243-
{},
244-
oldEncryptionKey
245-
);
246-
const encryptedAdapter = new GridFSBucketAdapter(
247-
databaseURI,
248-
{},
249-
'newKeyThatILove'
250-
);
213+
const oldEncryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, oldEncryptionKey);
214+
const encryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, 'newKeyThatILove');
251215
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
252216
const fileName1 = 'file1.txt';
253217
const data1 = 'hello world';
254218
const fileName2 = 'file2.txt';
255219
const data2 = 'hello new world';
256220
//Store unecrypted files
257221
await oldEncryptedAdapter.createFile(fileName1, data1);
258-
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(
259-
fileName1
260-
);
222+
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(fileName1);
261223
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
262224
await oldEncryptedAdapter.createFile(fileName2, data2);
263-
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(
264-
fileName2
265-
);
225+
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(fileName2);
266226
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
267227
//Inject unecrypted file to see if causes an issue
268228
const fileName3 = 'file3.txt';
@@ -318,31 +278,19 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
318278

319279
it("should return fileNames of those it can't encrypt with the new key", async () => {
320280
const oldEncryptionKey = 'oldKeyThatILoved';
321-
const oldEncryptedAdapter = new GridFSBucketAdapter(
322-
databaseURI,
323-
{},
324-
oldEncryptionKey
325-
);
326-
const encryptedAdapter = new GridFSBucketAdapter(
327-
databaseURI,
328-
{},
329-
'newKeyThatILove'
330-
);
281+
const oldEncryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, oldEncryptionKey);
282+
const encryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, 'newKeyThatILove');
331283
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
332284
const fileName1 = 'file1.txt';
333285
const data1 = 'hello world';
334286
const fileName2 = 'file2.txt';
335287
const data2 = 'hello new world';
336288
//Store unecrypted files
337289
await oldEncryptedAdapter.createFile(fileName1, data1);
338-
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(
339-
fileName1
340-
);
290+
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(fileName1);
341291
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
342292
await oldEncryptedAdapter.createFile(fileName2, data2);
343-
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(
344-
fileName2
345-
);
293+
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(fileName2);
346294
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
347295
//Inject unecrypted file to see if causes an issue
348296
const fileName3 = 'file3.txt';

spec/LdapAuth.spec.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ it('Should succeed with right credentials when LDAPS is used and certifcate is n
3939
suffix: 'o=example',
4040
url: `ldaps://localhost:${sslport}`,
4141
dn: 'uid={{id}}, o=example',
42-
tlsOptions: { rejectUnauthorized: false }
42+
tlsOptions: { rejectUnauthorized: false },
4343
};
4444
ldap
4545
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
@@ -57,8 +57,8 @@ it('Should succeed when LDAPS is used and the presented certificate is the expec
5757
dn: 'uid={{id}}, o=example',
5858
tlsOptions: {
5959
ca: fs.readFileSync(__dirname + '/support/cert/cert.pem'),
60-
rejectUnauthorized: true
61-
}
60+
rejectUnauthorized: true,
61+
},
6262
};
6363
ldap
6464
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
@@ -76,8 +76,8 @@ it('Should fail when LDAPS is used and the presented certificate is not the expe
7676
dn: 'uid={{id}}, o=example',
7777
tlsOptions: {
7878
ca: fs.readFileSync(__dirname + '/support/cert/anothercert.pem'),
79-
rejectUnauthorized: true
80-
}
79+
rejectUnauthorized: true,
80+
},
8181
};
8282
ldap
8383
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
@@ -98,8 +98,8 @@ it('Should fail when LDAPS is used certifcate matches but credentials are wrong'
9898
dn: 'uid={{id}}, o=example',
9999
tlsOptions: {
100100
ca: fs.readFileSync(__dirname + '/support/cert/cert.pem'),
101-
rejectUnauthorized: true
102-
}
101+
rejectUnauthorized: true,
102+
},
103103
};
104104
ldap
105105
.validateAuthData({ id: 'testuser', password: 'wrong!' }, options)
@@ -112,7 +112,6 @@ it('Should fail when LDAPS is used certifcate matches but credentials are wrong'
112112
});
113113
});
114114

115-
116115
it('Should fail with wrong credentials', done => {
117116
mockLdapServer(port, 'uid=testuser, o=example').then(server => {
118117
const options = {

spec/MockLdapServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const fs = require('fs');
33

44
const tlsOptions = {
55
key: fs.readFileSync(__dirname + '/support/cert/key.pem'),
6-
certificate: fs.readFileSync(__dirname + '/support/cert/cert.pem')
7-
}
6+
certificate: fs.readFileSync(__dirname + '/support/cert/cert.pem'),
7+
};
88

99
function newServer(port, dn, provokeSearchError = false, ssl = false) {
1010
const server = ssl ? ldapjs.createServer(tlsOptions) : ldapjs.createServer();

src/GraphQL/helpers/objectsQueries.js

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const needToGetAllKeys = (fields, keys, parseClasses) =>
1010
? keys.split(',').some(keyName => {
1111
const key = keyName.split('.');
1212
if (fields[key[0]]) {
13+
if (fields[key[0]].type === 'Relation') return false;
1314
if (fields[key[0]].type === 'Pointer') {
1415
const subClass = parseClasses.find(
15-
({ className: parseClassName }) =>
16-
fields[key[0]].targetClass === parseClassName
16+
({ className: parseClassName }) => fields[key[0]].targetClass === parseClassName
1717
);
1818
if (subClass && subClass.fields[key[1]]) {
1919
// Current sub key is not custom
@@ -50,9 +50,7 @@ const getObject = async (
5050
try {
5151
if (
5252
!needToGetAllKeys(
53-
parseClasses.find(
54-
({ className: parseClassName }) => className === parseClassName
55-
).fields,
53+
parseClasses.find(({ className: parseClassName }) => className === parseClassName).fields,
5654
keys,
5755
parseClasses
5856
)
@@ -141,15 +139,7 @@ const findObjects = async (
141139
preCountOptions.subqueryReadPreference = subqueryReadPreference;
142140
}
143141
preCount = (
144-
await rest.find(
145-
config,
146-
auth,
147-
className,
148-
where,
149-
preCountOptions,
150-
info.clientSDK,
151-
info.context
152-
)
142+
await rest.find(config, auth, className, where, preCountOptions, info.clientSDK, info.context)
153143
).count;
154144
if ((skip || 0) + limit < preCount) {
155145
skip = preCount - limit;
@@ -158,11 +148,7 @@ const findObjects = async (
158148

159149
const options = {};
160150

161-
if (
162-
selectedFields.find(
163-
field => field.startsWith('edges.') || field.startsWith('pageInfo.')
164-
)
165-
) {
151+
if (selectedFields.find(field => field.startsWith('edges.') || field.startsWith('pageInfo.'))) {
166152
if (limit || limit === 0) {
167153
options.limit = limit;
168154
} else {
@@ -181,9 +167,7 @@ const findObjects = async (
181167
}
182168
if (
183169
!needToGetAllKeys(
184-
parseClasses.find(
185-
({ className: parseClassName }) => className === parseClassName
186-
).fields,
170+
parseClasses.find(({ className: parseClassName }) => className === parseClassName).fields,
187171
keys,
188172
parseClasses
189173
)
@@ -245,9 +229,7 @@ const findObjects = async (
245229

246230
pageInfo = {
247231
hasPreviousPage:
248-
((preCount && preCount > 0) || (count && count > 0)) &&
249-
skip !== undefined &&
250-
skip > 0,
232+
((preCount && preCount > 0) || (count && count > 0)) && skip !== undefined && skip > 0,
251233
startCursor: offsetToCursor(skip || 0),
252234
endCursor: offsetToCursor((skip || 0) + (results.length || 1) - 1),
253235
hasNextPage: (preCount || count) > (skip || 0) + results.length,
@@ -261,25 +243,15 @@ const findObjects = async (
261243
};
262244
};
263245

264-
const calculateSkipAndLimit = (
265-
skipInput,
266-
first,
267-
after,
268-
last,
269-
before,
270-
maxLimit
271-
) => {
246+
const calculateSkipAndLimit = (skipInput, first, after, last, before, maxLimit) => {
272247
let skip = undefined;
273248
let limit = undefined;
274249
let needToPreCount = false;
275250

276251
// Validates the skip input
277252
if (skipInput || skipInput === 0) {
278253
if (skipInput < 0) {
279-
throw new Parse.Error(
280-
Parse.Error.INVALID_QUERY,
281-
'Skip should be a positive number'
282-
);
254+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Skip should be a positive number');
283255
}
284256
skip = skipInput;
285257
}
@@ -288,10 +260,7 @@ const calculateSkipAndLimit = (
288260
if (after) {
289261
after = cursorToOffset(after);
290262
if ((!after && after !== 0) || after < 0) {
291-
throw new Parse.Error(
292-
Parse.Error.INVALID_QUERY,
293-
'After is not a valid cursor'
294-
);
263+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'After is not a valid cursor');
295264
}
296265

297266
// If skip and after are passed, a new skip is calculated by adding them
@@ -301,10 +270,7 @@ const calculateSkipAndLimit = (
301270
// Validates the first param
302271
if (first || first === 0) {
303272
if (first < 0) {
304-
throw new Parse.Error(
305-
Parse.Error.INVALID_QUERY,
306-
'First should be a positive number'
307-
);
273+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'First should be a positive number');
308274
}
309275

310276
// The first param is translated to the limit param of the Parse legacy API
@@ -316,10 +282,7 @@ const calculateSkipAndLimit = (
316282
// This method converts the cursor to the index of the object
317283
before = cursorToOffset(before);
318284
if ((!before && before !== 0) || before < 0) {
319-
throw new Parse.Error(
320-
Parse.Error.INVALID_QUERY,
321-
'Before is not a valid cursor'
322-
);
285+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Before is not a valid cursor');
323286
}
324287

325288
if ((skip || 0) >= before) {
@@ -334,10 +297,7 @@ const calculateSkipAndLimit = (
334297
// Validates the last param
335298
if (last || last === 0) {
336299
if (last < 0) {
337-
throw new Parse.Error(
338-
Parse.Error.INVALID_QUERY,
339-
'Last should be a positive number'
340-
);
300+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Last should be a positive number');
341301
}
342302

343303
if (last > maxLimit) {

0 commit comments

Comments
 (0)