Remove request and request-promise from dev dependencies (#5077)

* removes from emailverificationtoken spec

* updates winston

* Updates ValidationAndPasswordsReset

* Use local request in schemas

* Removes request in rest.spec

* Removes request from PushRouter0

* removes request from public API

* removes request from index.spec

* Removes request form parse.push spec

* removes request from ParseInstallation spec

* Removes from ParseHooks

* removes request from ParseGlobalConfig.spec

* Removes request from ParseAPI.spec.js

* removes request from LogsRouter

* removes in features

* Filters undefined headers instead of crashing

* Removes request from ParseUser spec

* Removes usage of request in ParseFile.spec.js

* Removes request from AuthAdapters.js

* removes request-promise from ParseGeoPoint.spec

* Removes request-promise from ParseQuery spec

* remove request-promise from UserPII

* removes request-promise from EnableExpressErrorHandler

* Updates RevocableSessionUpgrade spec

* Update RestQuery

* Removes read preferenceOptionM

* ensure we forward auth from URL

* use request in CloudCode.spec.js

* Removes request-promise from JobSchedule.spec

* Removes rp from VerifyUserPassword.spec.js

* Removes rp from PasswordPolicy spec

* Removes rp from ParsePolygon spec

* Removes rp from fullTextSearch spec

* Removes rp from PArseQuery.Aggregate

* Ensure we properly forward errors

* Removes request and request-promise
This commit is contained in:
Florent Vilmart
2018-09-24 17:07:51 -04:00
committed by GitHub
parent 93a0017b25
commit 045d941aef
35 changed files with 5825 additions and 8257 deletions

View File

@@ -1,7 +1,7 @@
'use strict';
const MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
const request = require('request');
const request = require('../lib/request');
const Config = require('../lib/Config');
describe('Custom Pages, Email Verification, Password Reset', () => {
@@ -273,46 +273,43 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
})
.then(() => {
expect(sendEmailOptions).not.toBeUndefined();
request.get(
sendEmailOptions.link,
{
followRedirect: false,
},
(error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=user'
);
user
.fetch()
.then(
() => {
expect(user.get('emailVerified')).toEqual(true);
request({
url: sendEmailOptions.link,
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
expect(response.text).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=user'
);
user
.fetch()
.then(
() => {
expect(user.get('emailVerified')).toEqual(true);
Parse.User.logIn('user', 'other-password').then(
user => {
expect(typeof user).toBe('object');
expect(user.get('emailVerified')).toBe(true);
done();
},
() => {
fail('login should have succeeded');
done();
}
);
},
err => {
jfail(err);
fail('this should not fail');
done();
}
)
.catch(err => {
Parse.User.logIn('user', 'other-password').then(
user => {
expect(typeof user).toBe('object');
expect(user.get('emailVerified')).toBe(true);
done();
},
() => {
fail('login should have succeeded');
done();
}
);
},
err => {
jfail(err);
fail('this should not fail');
done();
});
}
);
}
)
.catch(err => {
jfail(err);
done();
});
});
});
});
@@ -375,8 +372,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
Parse.User.requestPasswordReset('testInvalidConfig@parse.com')
)
.then(
result => {
console.log(result);
() => {
fail('sending password reset email should not have succeeded');
done();
},
@@ -414,8 +410,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
Parse.User.requestPasswordReset('testInvalidConfig@parse.com')
)
.then(
result => {
console.log(result);
() => {
fail('sending password reset email should not have succeeded');
done();
},
@@ -450,8 +445,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
Parse.User.requestPasswordReset('testInvalidConfig@parse.com')
)
.then(
result => {
console.log(result);
() => {
fail('sending password reset email should not have succeeded');
done();
},
@@ -624,35 +618,32 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
})
.then(() => {
expect(sendEmailOptions).not.toBeUndefined();
request.get(
sendEmailOptions.link,
{
followRedirect: false,
},
(error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=user'
);
user
.fetch()
.then(
() => {
expect(user.get('emailVerified')).toEqual(true);
done();
},
err => {
jfail(err);
fail('this should not fail');
done();
}
)
.catch(err => {
jfail(err);
request({
url: sendEmailOptions.link,
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
expect(response.text).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=user'
);
user
.fetch()
.then(
() => {
expect(user.get('emailVerified')).toEqual(true);
done();
});
}
);
},
err => {
jfail(err);
fail('this should not fail');
done();
}
)
.catch(err => {
jfail(err);
done();
});
});
});
});
@@ -667,19 +658,16 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
},
publicServerURL: 'http://localhost:8378/1',
}).then(() => {
request.get(
'http://localhost:8378/1/apps/test/verify_email',
{
followRedirect: false,
},
(error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
);
done();
}
);
request({
url: 'http://localhost:8378/1/apps/test/verify_email',
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
expect(response.text).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
);
done();
});
});
});
@@ -694,19 +682,17 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
},
publicServerURL: 'http://localhost:8378/1',
}).then(() => {
request.get(
'http://localhost:8378/1/apps/test/verify_email?token=asdfasdf&username=sadfasga',
{
followRedirect: false,
},
(error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=sadfasga&appId=test'
);
done();
}
);
request({
url:
'http://localhost:8378/1/apps/test/verify_email?token=asdfasdf&username=sadfasga',
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
expect(response.text).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=sadfasga&appId=test'
);
done();
});
});
});
@@ -721,22 +707,20 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
},
publicServerURL: 'http://localhost:8378/1',
}).then(() => {
request.post(
'http://localhost:8378/1/apps/test/resend_verification_email',
{
followRedirect: false,
form: {
username: 'sadfasga',
},
request({
url: 'http://localhost:8378/1/apps/test/resend_verification_email',
method: 'POST',
followRedirects: false,
body: {
username: 'sadfasga',
},
(error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/link_send_fail.html'
);
done();
}
);
}).then(response => {
expect(response.status).toEqual(302);
expect(response.text).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/link_send_fail.html'
);
done();
});
});
});
@@ -744,22 +728,20 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
const user = new Parse.User();
const emailAdapter = {
sendVerificationEmail: () => {
request.get(
'http://localhost:8378/1/apps/test/verify_email?token=invalid&username=zxcv',
{
followRedirect: false,
},
(error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=zxcv&appId=test'
);
user.fetch().then(() => {
expect(user.get('emailVerified')).toEqual(false);
done();
});
}
);
request({
url:
'http://localhost:8378/1/apps/test/verify_email?token=invalid&username=zxcv',
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
expect(response.text).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=zxcv&appId=test'
);
user.fetch().then(() => {
expect(user.get('emailVerified')).toEqual(false);
done();
});
});
},
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => {},
@@ -788,23 +770,15 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
const emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: options => {
request.get(
options.link,
{
followRedirect: false,
},
(error, response) => {
if (error) {
jfail(error);
fail('Failed to get the reset link');
return;
}
expect(response.statusCode).toEqual(302);
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=[a-zA-Z0-9]+\&id=test\&username=zxcv%2Bzxcv/;
expect(response.body.match(re)).not.toBe(null);
done();
}
);
request({
url: options.link,
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=[a-zA-Z0-9]+\&id=test\&username=zxcv%2Bzxcv/;
expect(response.text.match(re)).not.toBe(null);
done();
});
},
sendMail: () => {},
};
@@ -840,19 +814,17 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
},
publicServerURL: 'http://localhost:8378/1',
}).then(() => {
request.get(
'http://localhost:8378/1/apps/test/request_password_reset?token=asdfasdf&username=sadfasga',
{
followRedirect: false,
},
(error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
);
done();
}
);
request({
url:
'http://localhost:8378/1/apps/test/request_password_reset?token=asdfasdf&username=sadfasga',
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
expect(response.text).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
);
done();
});
});
});
@@ -861,76 +833,59 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
const emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: options => {
request.get(
options.link,
{
followRedirect: false,
},
(error, response) => {
if (error) {
jfail(error);
fail('Failed to get the reset link');
return;
}
expect(response.statusCode).toEqual(302);
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=zxcv/;
const match = response.body.match(re);
if (!match) {
fail('should have a token');
done();
return;
}
const token = match[1];
request({
url: options.link,
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=zxcv/;
const match = response.text.match(re);
if (!match) {
fail('should have a token');
done();
return;
}
const token = match[1];
request.post(
{
url: 'http://localhost:8378/1/apps/test/request_password_reset',
body: `new_password=hello&token=${token}&username=zxcv`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
followRedirect: false,
},
(error, response) => {
if (error) {
jfail(error);
fail('Failed to POST request password reset');
return;
}
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html?username=zxcv'
);
request({
url: 'http://localhost:8378/1/apps/test/request_password_reset',
method: 'POST',
body: { new_password: 'hello', token, username: 'zxcv' },
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
followRedirects: false,
}).then(response => {
expect(response.status).toEqual(302);
expect(response.text).toEqual(
'Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html?username=zxcv'
);
Parse.User.logIn('zxcv', 'hello').then(
function() {
const config = Config.get('test');
config.database.adapter
.find(
'_User',
{ fields: {} },
{ username: 'zxcv' },
{ limit: 1 }
)
.then(results => {
// _perishable_token should be unset after reset password
expect(results.length).toEqual(1);
expect(results[0]['_perishable_token']).toEqual(
undefined
);
done();
});
},
err => {
jfail(err);
fail('should login with new password');
Parse.User.logIn('zxcv', 'hello').then(
function() {
const config = Config.get('test');
config.database.adapter
.find(
'_User',
{ fields: {} },
{ username: 'zxcv' },
{ limit: 1 }
)
.then(results => {
// _perishable_token should be unset after reset password
expect(results.length).toEqual(1);
expect(results[0]['_perishable_token']).toEqual(undefined);
done();
}
);
});
},
err => {
jfail(err);
fail('should login with new password');
done();
}
);
}
);
});
});
},
sendMail: () => {},
};