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:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user