GraphQL: Optimize queries, fixes some null returns (on object), fix stitched GraphQLUpload (#6709)

* Optimize query, fixes some null returns, fix stitched GraphQLUpload

* Fix authData key selection

* Prefer Iso string since other GraphQL solutions use this format

* fix tests

Co-authored-by: Antonio Davi Macedo Coelho de Castro <adavimacedo@gmail.com>
This commit is contained in:
Antoine Cormouls
2020-10-02 00:19:26 +02:00
committed by GitHub
parent 929c4e1b0d
commit 62048260c9
32 changed files with 1533 additions and 1161 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,8 @@ describe_only_db('mongo')('Idempotency', () => {
config,
auth.master(config),
'_Idempotency',
res.results[0].objectId);
res.results[0].objectId
);
}
async function setup(options) {
await reconfigureServer({
@@ -37,14 +38,16 @@ describe_only_db('mongo')('Idempotency', () => {
}
// Setups
beforeEach(async () => {
if (SIMULATE_TTL) { jasmine.DEFAULT_TIMEOUT_INTERVAL = 200000; }
if (SIMULATE_TTL) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 200000;
}
await setup({
paths: [
"functions/.*",
"jobs/.*",
"classes/.*",
"users",
"installations"
'functions/.*',
'jobs/.*',
'classes/.*',
'users',
'installations',
],
ttl: 30,
});
@@ -61,14 +64,14 @@ describe_only_db('mongo')('Idempotency', () => {
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
'X-Parse-Request-Id': 'abc-123'
}
'X-Parse-Request-Id': 'abc-123',
},
};
expect(Config.get(Parse.applicationId).idempotencyOptions.ttl).toBe(30);
await request(params);
await request(params).then(fail, e => {
expect(e.status).toEqual(400);
expect(e.data.error).toEqual("Duplicate request");
expect(e.data.error).toEqual('Duplicate request');
});
expect(counter).toBe(1);
});
@@ -84,8 +87,8 @@ describe_only_db('mongo')('Idempotency', () => {
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
'X-Parse-Request-Id': 'abc-123'
}
'X-Parse-Request-Id': 'abc-123',
},
};
await expectAsync(request(params)).toBeResolved();
if (SIMULATE_TTL) {
@@ -108,13 +111,13 @@ describe_only_db('mongo')('Idempotency', () => {
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
'X-Parse-Request-Id': 'abc-123'
}
'X-Parse-Request-Id': 'abc-123',
},
};
await expectAsync(request(params)).toBeResolved();
await request(params).then(fail, e => {
expect(e.status).toEqual(400);
expect(e.data.error).toEqual("Duplicate request");
expect(e.data.error).toEqual('Duplicate request');
});
expect(counter).toBe(1);
});
@@ -130,13 +133,13 @@ describe_only_db('mongo')('Idempotency', () => {
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
'X-Parse-Request-Id': 'abc-123'
}
'X-Parse-Request-Id': 'abc-123',
},
};
await expectAsync(request(params)).toBeResolved();
await request(params).then(fail, e => {
expect(e.status).toEqual(400);
expect(e.data.error).toEqual("Duplicate request");
expect(e.data.error).toEqual('Duplicate request');
});
expect(counter).toBe(1);
});
@@ -150,19 +153,19 @@ describe_only_db('mongo')('Idempotency', () => {
method: 'POST',
url: 'http://localhost:8378/1/users',
body: {
username: "user",
password: "pass"
username: 'user',
password: 'pass',
},
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
'X-Parse-Request-Id': 'abc-123'
}
'X-Parse-Request-Id': 'abc-123',
},
};
await expectAsync(request(params)).toBeResolved();
await request(params).then(fail, e => {
expect(e.status).toEqual(400);
expect(e.data.error).toEqual("Duplicate request");
expect(e.data.error).toEqual('Duplicate request');
});
expect(counter).toBe(1);
});
@@ -176,19 +179,19 @@ describe_only_db('mongo')('Idempotency', () => {
method: 'POST',
url: 'http://localhost:8378/1/installations',
body: {
installationId: "1",
deviceType: "ios"
installationId: '1',
deviceType: 'ios',
},
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
'X-Parse-Request-Id': 'abc-123'
}
'X-Parse-Request-Id': 'abc-123',
},
};
await expectAsync(request(params)).toBeResolved();
await request(params).then(fail, e => {
expect(e.status).toEqual(400);
expect(e.data.error).toEqual("Duplicate request");
expect(e.data.error).toEqual('Duplicate request');
});
expect(counter).toBe(1);
});
@@ -205,8 +208,8 @@ describe_only_db('mongo')('Idempotency', () => {
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
'X-Parse-Request-Id': uuid.v4()
}
'X-Parse-Request-Id': uuid.v4(),
},
};
return request(params);
});
@@ -215,7 +218,9 @@ describe_only_db('mongo')('Idempotency', () => {
});
it('should re-throw any other error unchanged when writing request entry fails for any other reason', async () => {
spyOn(rest, 'create').and.rejectWith(new Parse.Error(0, "some other error"));
spyOn(rest, 'create').and.rejectWith(
new Parse.Error(0, 'some other error')
);
Parse.Cloud.define('myFunction', () => {});
const params = {
method: 'POST',
@@ -223,19 +228,23 @@ describe_only_db('mongo')('Idempotency', () => {
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
'X-Parse-Request-Id': 'abc-123'
}
'X-Parse-Request-Id': 'abc-123',
},
};
await request(params).then(fail, e => {
expect(e.status).toEqual(400);
expect(e.data.error).toEqual("some other error");
expect(e.data.error).toEqual('some other error');
});
});
it('should use default configuration when none is set', async () => {
await setup({});
expect(Config.get(Parse.applicationId).idempotencyOptions.ttl).toBe(Definitions.IdempotencyOptions.ttl.default);
expect(Config.get(Parse.applicationId).idempotencyOptions.paths).toBe(Definitions.IdempotencyOptions.paths.default);
expect(Config.get(Parse.applicationId).idempotencyOptions.ttl).toBe(
Definitions.IdempotencyOptions.ttl.default
);
expect(Config.get(Parse.applicationId).idempotencyOptions.paths).toBe(
Definitions.IdempotencyOptions.paths.default
);
});
it('should throw on invalid configuration', async () => {

View File

@@ -12,7 +12,7 @@ describe('middlewares', () => {
_ApplicationId: 'FakeAppId',
},
headers: {},
get: (key) => {
get: key => {
return fakeReq.headers[key.toLowerCase()];
},
};
@@ -24,7 +24,7 @@ describe('middlewares', () => {
AppCache.del(fakeReq.body._ApplicationId);
});
it('should use _ContentType if provided', (done) => {
it('should use _ContentType if provided', done => {
expect(fakeReq.headers['content-type']).toEqual(undefined);
const contentType = 'image/jpeg';
fakeReq.body._ContentType = contentType;
@@ -64,7 +64,7 @@ describe('middlewares', () => {
expect(fakeRes.status).toHaveBeenCalledWith(403);
});
it('should succeed when any one of the configured keys supplied', (done) => {
it('should succeed when any one of the configured keys supplied', done => {
AppCache.put(fakeReq.body._ApplicationId, {
clientKey: 'clientKey',
masterKey: 'masterKey',
@@ -77,7 +77,7 @@ describe('middlewares', () => {
});
});
it('should succeed when client key supplied but empty', (done) => {
it('should succeed when client key supplied but empty', done => {
AppCache.put(fakeReq.body._ApplicationId, {
clientKey: '',
masterKey: 'masterKey',
@@ -90,7 +90,7 @@ describe('middlewares', () => {
});
});
it('should succeed when no keys are configured and none supplied', (done) => {
it('should succeed when no keys are configured and none supplied', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
});
@@ -110,22 +110,22 @@ describe('middlewares', () => {
const BodyKeys = Object.keys(BodyParams);
BodyKeys.forEach((infoKey) => {
BodyKeys.forEach(infoKey => {
const bodyKey = BodyParams[infoKey];
const keyValue = 'Fake' + bodyKey;
// javascriptKey is the only one that gets defaulted,
const otherKeys = BodyKeys.filter(
(otherKey) => otherKey !== infoKey && otherKey !== 'javascriptKey'
otherKey => otherKey !== infoKey && otherKey !== 'javascriptKey'
);
it(`it should pull ${bodyKey} into req.info`, (done) => {
it(`it should pull ${bodyKey} into req.info`, done => {
fakeReq.body[bodyKey] = keyValue;
middlewares.handleParseHeaders(fakeReq, fakeRes, () => {
expect(fakeReq.body[bodyKey]).toEqual(undefined);
expect(fakeReq.info[infoKey]).toEqual(keyValue);
otherKeys.forEach((otherKey) => {
otherKeys.forEach(otherKey => {
expect(fakeReq.info[otherKey]).toEqual(undefined);
});
@@ -145,7 +145,7 @@ describe('middlewares', () => {
expect(fakeRes.status).toHaveBeenCalledWith(403);
});
it('should succeed if the ip does belong to masterKeyIps list', (done) => {
it('should succeed if the ip does belong to masterKeyIps list', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
masterKeyIps: ['ip1', 'ip2'],
@@ -169,7 +169,7 @@ describe('middlewares', () => {
expect(fakeRes.status).toHaveBeenCalledWith(403);
});
it('should succeed if the connection.remoteAddress does belong to masterKeyIps list', (done) => {
it('should succeed if the connection.remoteAddress does belong to masterKeyIps list', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
masterKeyIps: ['ip1', 'ip2'],
@@ -193,7 +193,7 @@ describe('middlewares', () => {
expect(fakeRes.status).toHaveBeenCalledWith(403);
});
it('should succeed if the socket.remoteAddress does belong to masterKeyIps list', (done) => {
it('should succeed if the socket.remoteAddress does belong to masterKeyIps list', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
masterKeyIps: ['ip1', 'ip2'],
@@ -217,7 +217,7 @@ describe('middlewares', () => {
expect(fakeRes.status).toHaveBeenCalledWith(403);
});
it('should succeed if the connection.socket.remoteAddress does belong to masterKeyIps list', (done) => {
it('should succeed if the connection.socket.remoteAddress does belong to masterKeyIps list', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
masterKeyIps: ['ip1', 'ip2'],
@@ -230,7 +230,7 @@ describe('middlewares', () => {
});
});
it('should allow any ip to use masterKey if masterKeyIps is empty', (done) => {
it('should allow any ip to use masterKey if masterKeyIps is empty', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
masterKeyIps: [],
@@ -243,7 +243,7 @@ describe('middlewares', () => {
});
});
it('should succeed if xff header does belong to masterKeyIps', (done) => {
it('should succeed if xff header does belong to masterKeyIps', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
masterKeyIps: ['ip1'],
@@ -256,7 +256,7 @@ describe('middlewares', () => {
});
});
it('should succeed if xff header with one ip does belong to masterKeyIps', (done) => {
it('should succeed if xff header with one ip does belong to masterKeyIps', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
masterKeyIps: ['ip1'],
@@ -393,7 +393,7 @@ describe('middlewares', () => {
);
});
it('should use user provided on field userFromJWT', (done) => {
it('should use user provided on field userFromJWT', done => {
AppCache.put(fakeReq.body._ApplicationId, {
masterKey: 'masterKey',
});

View File

@@ -354,14 +354,12 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
it('should delete field without index', async () => {
const database = Config.get(Parse.applicationId).database;
const obj = new Parse.Object('MyObject');
obj.set("test", 1);
obj.set('test', 1);
await obj.save();
const schemaBeforeDeletion = await new Parse.Schema('MyObject').get();
await database.adapter.deleteFields(
"MyObject",
schemaBeforeDeletion,
["test"]
);
await database.adapter.deleteFields('MyObject', schemaBeforeDeletion, [
'test',
]);
const schemaAfterDeletion = await new Parse.Schema('MyObject').get();
expect(schemaBeforeDeletion.fields.test).toBeDefined();
expect(schemaAfterDeletion.fields.test).toBeUndefined();
@@ -370,19 +368,15 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
it('should delete field with index', async () => {
const database = Config.get(Parse.applicationId).database;
const obj = new Parse.Object('MyObject');
obj.set("test", 1);
obj.set('test', 1);
await obj.save();
const schemaBeforeDeletion = await new Parse.Schema('MyObject').get();
await database.adapter.ensureIndex(
'MyObject',
schemaBeforeDeletion,
['test']
);
await database.adapter.deleteFields(
"MyObject",
schemaBeforeDeletion,
["test"]
);
await database.adapter.ensureIndex('MyObject', schemaBeforeDeletion, [
'test',
]);
await database.adapter.deleteFields('MyObject', schemaBeforeDeletion, [
'test',
]);
const schemaAfterDeletion = await new Parse.Schema('MyObject').get();
expect(schemaBeforeDeletion.fields.test).toBeDefined();
expect(schemaAfterDeletion.fields.test).toBeUndefined();

View File

@@ -55,7 +55,7 @@ const loadTestData = () => {
return Parse.Object.saveAll([obj1, obj2, obj3, obj4]);
};
const get = function(url, options) {
const get = function (url, options) {
options.qs = options.body;
delete options.body;
Object.keys(options.qs).forEach(key => {
@@ -1345,10 +1345,10 @@ describe('Parse.Query Aggregate testing', () => {
user.set('score', score);
user
.signUp()
.then(function() {
.then(function () {
return get(Parse.serverURL + '/aggregate/_User', options);
})
.then(function(resp) {
.then(function (resp) {
expect(resp.results.length).toBe(1);
const result = resp.results[0];
@@ -1369,7 +1369,7 @@ describe('Parse.Query Aggregate testing', () => {
done();
})
.catch(function(err) {
.catch(function (err) {
fail(err);
});
});
@@ -1440,13 +1440,25 @@ describe('Parse.Query Aggregate testing', () => {
['location'],
undefined,
false,
{ indexType: '2dsphere' },
{ indexType: '2dsphere' }
);
// Create objects
const GeoObject = Parse.Object.extend('GeoObject');
const obj1 = new GeoObject({ value: 1, location: new Parse.GeoPoint(1, 1), date: new Date(1) });
const obj2 = new GeoObject({ value: 2, location: new Parse.GeoPoint(2, 1), date: new Date(2) });
const obj3 = new GeoObject({ value: 3, location: new Parse.GeoPoint(3, 1), date: new Date(3) });
const obj1 = new GeoObject({
value: 1,
location: new Parse.GeoPoint(1, 1),
date: new Date(1),
});
const obj2 = new GeoObject({
value: 2,
location: new Parse.GeoPoint(2, 1),
date: new Date(2),
});
const obj3 = new GeoObject({
value: 3,
location: new Parse.GeoPoint(3, 1),
date: new Date(3),
});
await Parse.Object.saveAll([obj1, obj2, obj3]);
// Create query
const pipeline = [
@@ -1454,18 +1466,18 @@ describe('Parse.Query Aggregate testing', () => {
geoNear: {
near: {
type: 'Point',
coordinates: [1, 1]
coordinates: [1, 1],
},
key: 'location',
spherical: true,
distanceField: 'dist',
query: {
date: {
$gte: new Date(2)
}
}
}
}
$gte: new Date(2),
},
},
},
},
];
const query = new Parse.Query(GeoObject);
const results = await query.aggregate(pipeline);
@@ -1489,9 +1501,21 @@ describe('Parse.Query Aggregate testing', () => {
);
// Create objects
const GeoObject = Parse.Object.extend('GeoObject');
const obj1 = new GeoObject({ value: 1, location: new Parse.GeoPoint(1, 1), date: new Date(1) });
const obj2 = new GeoObject({ value: 2, location: new Parse.GeoPoint(2, 1), date: new Date(2) });
const obj3 = new GeoObject({ value: 3, location: new Parse.GeoPoint(3, 1), date: new Date(3) });
const obj1 = new GeoObject({
value: 1,
location: new Parse.GeoPoint(1, 1),
date: new Date(1),
});
const obj2 = new GeoObject({
value: 2,
location: new Parse.GeoPoint(2, 1),
date: new Date(2),
});
const obj3 = new GeoObject({
value: 3,
location: new Parse.GeoPoint(3, 1),
date: new Date(3),
});
await Parse.Object.saveAll([obj1, obj2, obj3]);
// Create query
const pipeline = [
@@ -1499,13 +1523,13 @@ describe('Parse.Query Aggregate testing', () => {
geoNear: {
near: {
type: 'Point',
coordinates: [1, 1]
coordinates: [1, 1],
},
key: 'location',
spherical: true,
distanceField: 'dist'
}
}
distanceField: 'dist',
},
},
];
const query = new Parse.Query(GeoObject);
const results = await query.aggregate(pipeline);
@@ -1513,38 +1537,53 @@ describe('Parse.Query Aggregate testing', () => {
expect(results.length).toEqual(3);
});
it_only_db('mongo')('aggregate geoNear with near legacy coordinate pair', async () => {
// Create geo index which is required for `geoNear` query
const database = Config.get(Parse.applicationId).database;
const schema = await new Parse.Schema('GeoObject').save();
await database.adapter.ensureIndex(
'GeoObject',
schema,
['location'],
undefined,
false,
'2dsphere'
);
// Create objects
const GeoObject = Parse.Object.extend('GeoObject');
const obj1 = new GeoObject({ value: 1, location: new Parse.GeoPoint(1, 1), date: new Date(1) });
const obj2 = new GeoObject({ value: 2, location: new Parse.GeoPoint(2, 1), date: new Date(2) });
const obj3 = new GeoObject({ value: 3, location: new Parse.GeoPoint(3, 1), date: new Date(3) });
await Parse.Object.saveAll([obj1, obj2, obj3]);
// Create query
const pipeline = [
{
geoNear: {
near: [1, 1],
key: 'location',
spherical: true,
distanceField: 'dist'
}
}
];
const query = new Parse.Query(GeoObject);
const results = await query.aggregate(pipeline);
// Check results
expect(results.length).toEqual(3);
});
it_only_db('mongo')(
'aggregate geoNear with near legacy coordinate pair',
async () => {
// Create geo index which is required for `geoNear` query
const database = Config.get(Parse.applicationId).database;
const schema = await new Parse.Schema('GeoObject').save();
await database.adapter.ensureIndex(
'GeoObject',
schema,
['location'],
undefined,
false,
'2dsphere'
);
// Create objects
const GeoObject = Parse.Object.extend('GeoObject');
const obj1 = new GeoObject({
value: 1,
location: new Parse.GeoPoint(1, 1),
date: new Date(1),
});
const obj2 = new GeoObject({
value: 2,
location: new Parse.GeoPoint(2, 1),
date: new Date(2),
});
const obj3 = new GeoObject({
value: 3,
location: new Parse.GeoPoint(3, 1),
date: new Date(3),
});
await Parse.Object.saveAll([obj1, obj2, obj3]);
// Create query
const pipeline = [
{
geoNear: {
near: [1, 1],
key: 'location',
spherical: true,
distanceField: 'dist',
},
},
];
const query = new Parse.Query(GeoObject);
const results = await query.aggregate(pipeline);
// Check results
expect(results.length).toEqual(3);
}
);
});

View File

@@ -384,10 +384,10 @@ describe('Parse.User testing', () => {
let sessionToken = null;
Promise.resolve()
.then(function() {
.then(function () {
return Parse.User.signUp('Jason', 'Parse', { code: 'red' });
})
.then(function(newUser) {
.then(function (newUser) {
equal(Parse.User.current(), newUser);
user = newUser;
@@ -401,7 +401,7 @@ describe('Parse.User testing', () => {
return Parse.User.become(sessionToken);
})
.then(function(newUser) {
.then(function (newUser) {
equal(Parse.User.current(), newUser);
ok(newUser);
@@ -417,24 +417,24 @@ describe('Parse.User testing', () => {
return Parse.User.become('somegarbage');
})
.then(
function() {
function () {
// This should have failed actually.
ok(
false,
"Shouldn't have been able to log in with garbage session token."
);
},
function(error) {
function (error) {
ok(error);
// Handle the error.
return Promise.resolve();
}
)
.then(
function() {
function () {
done();
},
function(error) {
function (error) {
ok(false, error);
done();
}
@@ -733,11 +733,11 @@ describe('Parse.User testing', () => {
function signUpAll(list, optionsOrCallback) {
let promise = Promise.resolve();
list.forEach(user => {
promise = promise.then(function() {
promise = promise.then(function () {
return user.signUp();
});
});
promise = promise.then(function() {
promise = promise.then(function () {
return list;
});
return promise.then(optionsOrCallback);
@@ -748,7 +748,7 @@ describe('Parse.User testing', () => {
const MESSAGES = 5;
// Make a list of users.
const userList = range(USERS).map(function(i) {
const userList = range(USERS).map(function (i) {
const user = new Parse.User();
user.set('password', 'user_num_' + i);
user.set('email', 'user_num_' + i + '@example.com');
@@ -756,14 +756,14 @@ describe('Parse.User testing', () => {
return user;
});
signUpAll(userList, async function(users) {
signUpAll(userList, async function (users) {
// Make a list of messages.
if (!users || users.length != USERS) {
fail('signupAll failed');
done();
return;
}
const messageList = range(MESSAGES).map(function(i) {
const messageList = range(MESSAGES).map(function (i) {
const message = new TestObject();
message.set('to', users[(i + 1) % USERS]);
message.set('from', users[i % USERS]);
@@ -844,7 +844,7 @@ describe('Parse.User testing', () => {
const user = new Parse.User();
user.set('username', 'alice');
user.set('password', 'password');
user.signUp().then(function(userAgain) {
user.signUp().then(function (userAgain) {
equal(userAgain.get('username'), 'bob');
ok(userAgain.dirty('username'));
const query = new Parse.Query(Parse.User);
@@ -938,14 +938,14 @@ describe('Parse.User testing', () => {
let id;
Parse.User.signUp('alice', 'password', null)
.then(function(alice) {
.then(function (alice) {
id = alice.id;
return Parse.User.logOut();
})
.then(() => {
return Parse.User.logIn('alice', 'password');
})
.then(function() {
.then(function () {
// Simulate browser refresh by force-reloading user from localStorage
Parse.User._clearCache();
@@ -953,7 +953,7 @@ describe('Parse.User testing', () => {
return Parse.User.current().save({ some_field: 1 });
})
.then(
function() {
function () {
// Check the user in memory just after save operation
const userInMemory = Parse.User.current();
@@ -1046,7 +1046,7 @@ describe('Parse.User testing', () => {
done();
},
function(error) {
function (error) {
ok(false, error);
done();
}
@@ -1089,7 +1089,7 @@ describe('Parse.User testing', () => {
it('user signup class method uses subclassing', async done => {
const SuperUser = Parse.User.extend({
secret: function() {
secret: function () {
return 1337;
},
});
@@ -1102,7 +1102,7 @@ describe('Parse.User testing', () => {
it('user on disk gets updated after save', async done => {
Parse.User.extend({
isSuper: function() {
isSuper: function () {
return true;
},
});
@@ -1130,7 +1130,7 @@ describe('Parse.User testing', () => {
done();
});
const getMockFacebookProviderWithIdToken = function(id, token) {
const getMockFacebookProviderWithIdToken = function (id, token) {
return {
authData: {
id: id,
@@ -1143,7 +1143,7 @@ describe('Parse.User testing', () => {
synchronizedAuthToken: null,
synchronizedExpiration: null,
authenticate: function(options) {
authenticate: function (options) {
if (this.shouldError) {
options.error(this, 'An error occurred');
} else if (this.shouldCancel) {
@@ -1152,7 +1152,7 @@ describe('Parse.User testing', () => {
options.success(this, this.authData);
}
},
restoreAuthentication: function(authData) {
restoreAuthentication: function (authData) {
if (!authData) {
this.synchronizedUserId = null;
this.synchronizedAuthToken = null;
@@ -1164,10 +1164,10 @@ describe('Parse.User testing', () => {
this.synchronizedExpiration = authData.expiration_date;
return true;
},
getAuthType: function() {
getAuthType: function () {
return 'facebook';
},
deauthenticate: function() {
deauthenticate: function () {
this.loggedOut = true;
this.restoreAuthentication(null);
},
@@ -1176,11 +1176,11 @@ describe('Parse.User testing', () => {
// Note that this mocks out client-side Facebook action rather than
// server-side.
const getMockFacebookProvider = function() {
const getMockFacebookProvider = function () {
return getMockFacebookProviderWithIdToken('8675309', 'jenny');
};
const getMockMyOauthProvider = function() {
const getMockMyOauthProvider = function () {
return {
authData: {
id: '12345',
@@ -1193,7 +1193,7 @@ describe('Parse.User testing', () => {
synchronizedAuthToken: null,
synchronizedExpiration: null,
authenticate: function(options) {
authenticate: function (options) {
if (this.shouldError) {
options.error(this, 'An error occurred');
} else if (this.shouldCancel) {
@@ -1202,7 +1202,7 @@ describe('Parse.User testing', () => {
options.success(this, this.authData);
}
},
restoreAuthentication: function(authData) {
restoreAuthentication: function (authData) {
if (!authData) {
this.synchronizedUserId = null;
this.synchronizedAuthToken = null;
@@ -1214,10 +1214,10 @@ describe('Parse.User testing', () => {
this.synchronizedExpiration = authData.expiration_date;
return true;
},
getAuthType: function() {
getAuthType: function () {
return 'myoauth';
},
deauthenticate: function() {
deauthenticate: function () {
this.loggedOut = true;
this.restoreAuthentication(null);
},
@@ -1225,7 +1225,7 @@ describe('Parse.User testing', () => {
};
Parse.User.extend({
extended: function() {
extended: function () {
return true;
},
});
@@ -1438,7 +1438,7 @@ describe('Parse.User testing', () => {
Parse.User._registerAuthenticationProvider(provider);
await Parse.User._logInWith('facebook');
Parse.User.logOut().then(async () => {
Parse.Cloud.beforeSave(Parse.User, function(req, res) {
Parse.Cloud.beforeSave(Parse.User, function (req, res) {
res.error("Before save shouldn't be called on login");
});
await Parse.User._logInWith('facebook');
@@ -1871,16 +1871,16 @@ describe('Parse.User testing', () => {
id: '12345',
access_token: 'token',
},
restoreAuthentication: function() {
restoreAuthentication: function () {
return true;
},
deauthenticate: function() {
deauthenticate: function () {
provider.authData = {};
},
authenticate: function(options) {
authenticate: function (options) {
options.success(this, provider.authData);
},
getAuthType: function() {
getAuthType: function () {
return 'shortLivedAuth';
},
};
@@ -1912,16 +1912,16 @@ describe('Parse.User testing', () => {
id: '12345',
access_token: 'token',
},
restoreAuthentication: function() {
restoreAuthentication: function () {
return true;
},
deauthenticate: function() {
deauthenticate: function () {
provider.authData = {};
},
authenticate: function(options) {
authenticate: function (options) {
options.success(this, provider.authData);
},
getAuthType: function() {
getAuthType: function () {
return 'shortLivedAuth';
},
};
@@ -2068,10 +2068,10 @@ describe('Parse.User testing', () => {
access_token: 'jenny',
expiration_date: new Date().toJSON(),
}).then(
function() {
function () {
done();
},
function(error) {
function (error) {
ok(false, error);
done();
}
@@ -2097,10 +2097,10 @@ describe('Parse.User testing', () => {
access_token: 'jenny',
expiration_date: new Date().toJSON(),
}).then(
function() {
function () {
done();
},
function(error) {
function (error) {
ok(false, error);
done();
}
@@ -2111,27 +2111,27 @@ describe('Parse.User testing', () => {
const data = { foo: 'bar' };
Parse.User.signUp('finn', 'human', data)
.then(function(user) {
.then(function (user) {
equal(Parse.User.current(), user);
equal(user.get('foo'), 'bar');
return Parse.User.logOut();
})
.then(function() {
.then(function () {
return Parse.User.logIn('finn', 'human');
})
.then(function(user) {
.then(function (user) {
equal(user, Parse.User.current());
equal(user.get('foo'), 'bar');
return Parse.User.logOut();
})
.then(function() {
.then(function () {
const user = new Parse.User();
user.set('username', 'jake');
user.set('password', 'dog');
user.set('foo', 'baz');
return user.signUp();
})
.then(function(user) {
.then(function (user) {
equal(user, Parse.User.current());
equal(user.get('foo'), 'baz');
user = new Parse.User();
@@ -2139,14 +2139,14 @@ describe('Parse.User testing', () => {
user.set('password', 'dog');
return user.logIn();
})
.then(function(user) {
.then(function (user) {
equal(user, Parse.User.current());
equal(user.get('foo'), 'baz');
const userAgain = new Parse.User();
userAgain.id = user.id;
return userAgain.fetch();
})
.then(function(userAgain) {
.then(function (userAgain) {
equal(userAgain.get('foo'), 'baz');
done();
});
@@ -2154,7 +2154,7 @@ describe('Parse.User testing', () => {
it("querying for users doesn't get session tokens", done => {
Parse.User.signUp('finn', 'human', { foo: 'bar' })
.then(function() {
.then(function () {
return Parse.User.logOut();
})
.then(() => {
@@ -2164,7 +2164,7 @@ describe('Parse.User testing', () => {
user.set('foo', 'baz');
return user.signUp();
})
.then(function() {
.then(function () {
return Parse.User.logOut();
})
.then(() => {
@@ -2172,7 +2172,7 @@ describe('Parse.User testing', () => {
return query.find({ sessionToken: null });
})
.then(
function(users) {
function (users) {
equal(users.length, 2);
users.forEach(user => {
expect(user.getSessionToken()).toBeUndefined();
@@ -2183,7 +2183,7 @@ describe('Parse.User testing', () => {
});
done();
},
function(error) {
function (error) {
ok(false, error);
done();
}
@@ -2214,19 +2214,19 @@ describe('Parse.User testing', () => {
user.setUsername('zxcv');
let currentSessionToken = '';
Promise.resolve()
.then(function() {
.then(function () {
return user.signUp();
})
.then(function() {
.then(function () {
currentSessionToken = user.getSessionToken();
return user.fetch();
})
.then(
function(u) {
function (u) {
expect(currentSessionToken).toEqual(u.getSessionToken());
done();
},
function(error) {
function (error) {
ok(false, error);
done();
}
@@ -2739,25 +2739,25 @@ describe('Parse.User testing', () => {
let sessionToken = null;
Promise.resolve()
.then(function() {
.then(function () {
return Parse.User.signUp('fosco', 'parse');
})
.then(function(newUser) {
.then(function (newUser) {
equal(Parse.User.current(), newUser);
sessionToken = newUser.getSessionToken();
ok(sessionToken);
newUser.set('password', 'facebook');
return newUser.save();
})
.then(function() {
.then(function () {
return Parse.User.become(sessionToken);
})
.then(
function() {
function () {
fail('Session should have been invalidated');
done();
},
function(err) {
function (err) {
expect(err.code).toBe(Parse.Error.INVALID_SESSION_TOKEN);
expect(err.message).toBe('Invalid session token');
done();
@@ -2768,25 +2768,25 @@ describe('Parse.User testing', () => {
it('test parse user become', done => {
let sessionToken = null;
Promise.resolve()
.then(function() {
.then(function () {
return Parse.User.signUp('flessard', 'folo', { foo: 1 });
})
.then(function(newUser) {
.then(function (newUser) {
equal(Parse.User.current(), newUser);
sessionToken = newUser.getSessionToken();
ok(sessionToken);
newUser.set('foo', 2);
return newUser.save();
})
.then(function() {
.then(function () {
return Parse.User.become(sessionToken);
})
.then(
function(newUser) {
function (newUser) {
equal(newUser.get('foo'), 2);
done();
},
function() {
function () {
fail('The session should still be valid');
done();
}
@@ -2798,7 +2798,7 @@ describe('Parse.User testing', () => {
let sessionToken = null;
Promise.resolve()
.then(function() {
.then(function () {
return Parse.User.signUp('log', 'out');
})
.then(newUser => {
@@ -3362,10 +3362,7 @@ describe('Parse.User testing', () => {
user
.signUp()
.then(() => {
return Parse.User.current()
.relation('relation')
.query()
.find();
return Parse.User.current().relation('relation').query().find();
})
.then(res => {
expect(res.length).toBe(0);
@@ -3401,9 +3398,7 @@ describe('Parse.User testing', () => {
return user.signUp();
})
.then(() => {
return Parse.User.current()
.set('emailVerified', true)
.save();
return Parse.User.current().set('emailVerified', true).save();
})
.then(() => {
fail('Should not be able to update emailVerified');
@@ -3574,9 +3569,7 @@ describe('Parse.User testing', () => {
return user.signUp();
})
.then(() => {
return Parse.User.current()
.set('_email_verify_token', 'bad')
.save();
return Parse.User.current().set('_email_verify_token', 'bad').save();
})
.then(() => {
fail('Should not be able to update email verification token');
@@ -4081,7 +4074,7 @@ describe('Parse.User testing', () => {
});
});
describe('Security Advisory GHSA-8w3j-g983-8jh5', function() {
describe('Security Advisory GHSA-8w3j-g983-8jh5', function () {
it_only_db('mongo')(
'should validate credentials first and check if account already linked afterwards ()',
async done => {

View File

@@ -219,9 +219,9 @@ describe('batch', () => {
expect(databaseAdapter.createObject.calls.argsFor(0)[3]).toBe(
databaseAdapter.createObject.calls.argsFor(1)[3]
);
expect(results.map(result => result.get('key')).sort()).toEqual(
['value1', 'value2']
);
expect(
results.map(result => result.get('key')).sort()
).toEqual(['value1', 'value2']);
done();
});
});

View File

@@ -473,7 +473,7 @@ describe('defaultGraphQLTypes', () => {
it('should serialize date', () => {
const date = new Date();
expect(serialize(date)).toBe(date.toUTCString());
expect(serialize(date)).toBe(date.toISOString());
});
it('should return iso value if object', () => {

View File

@@ -200,7 +200,7 @@ beforeEach(done => {
.catch(done.fail);
});
afterEach(function(done) {
afterEach(function (done) {
const afterLogOut = () => {
if (Object.keys(openConnections).length > 0) {
fail(
@@ -230,7 +230,7 @@ afterEach(function(done) {
'_Session',
'_Product',
'_Audience',
'_Idempotency'
'_Idempotency',
].indexOf(className) >= 0
);
}
@@ -327,13 +327,13 @@ function range(n) {
function mockCustomAuthenticator(id, password) {
const custom = {};
custom.validateAuthData = function(authData) {
custom.validateAuthData = function (authData) {
if (authData.id === id && authData.password.startsWith(password)) {
return Promise.resolve();
}
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'not validated');
};
custom.validateAppId = function() {
custom.validateAppId = function () {
return Promise.resolve();
};
return custom;
@@ -345,14 +345,14 @@ function mockCustom() {
function mockFacebookAuthenticator(id, token) {
const facebook = {};
facebook.validateAuthData = function(authData) {
facebook.validateAuthData = function (authData) {
if (authData.id === id && authData.access_token.startsWith(token)) {
return Promise.resolve();
} else {
throw undefined;
}
};
facebook.validateAppId = function(appId, authData) {
facebook.validateAppId = function (appId, authData) {
if (authData.access_token.startsWith(token)) {
return Promise.resolve();
} else {
@@ -369,17 +369,17 @@ function mockFacebook() {
function mockShortLivedAuth() {
const auth = {};
let accessToken;
auth.setValidAccessToken = function(validAccessToken) {
auth.setValidAccessToken = function (validAccessToken) {
accessToken = validAccessToken;
};
auth.validateAuthData = function(authData) {
auth.validateAuthData = function (authData) {
if (authData.access_token == accessToken) {
return Promise.resolve();
} else {
return Promise.reject('Invalid access token');
}
};
auth.validateAppId = function() {
auth.validateAppId = function () {
return Promise.resolve();
};
return auth;
@@ -404,7 +404,7 @@ global.defaultConfiguration = defaultConfiguration;
global.mockCustomAuthenticator = mockCustomAuthenticator;
global.mockFacebookAuthenticator = mockFacebookAuthenticator;
global.databaseAdapter = databaseAdapter;
global.jfail = function(err) {
global.jfail = function (err) {
fail(JSON.stringify(err));
};
@@ -454,7 +454,7 @@ global.describe_only = validator => {
};
const libraryCache = {};
jasmine.mockLibrary = function(library, name, mock) {
jasmine.mockLibrary = function (library, name, mock) {
const original = require(library)[name];
if (!libraryCache[library]) {
libraryCache[library] = {};
@@ -463,7 +463,7 @@ jasmine.mockLibrary = function(library, name, mock) {
libraryCache[library][name] = original;
};
jasmine.restoreLibrary = function(library, name) {
jasmine.restoreLibrary = function (library, name) {
if (!libraryCache[library] || !libraryCache[library][name]) {
throw 'Can not find library ' + library + ' ' + name;
}