Finding areas that are untested and need love (#4131)

* Makes InstallationRouter like others

* Adds testing for Range file requests

- Fixes issue with small requests (0-2)

* Revert "Makes InstallationRouter like others"

This reverts commit e2d2a16ebf2757db6138c7b5b33c97c56c69ead6.

* Better handling of errors in FilesRouter

* Fix incorrectness in range requests

* Better/simpler logic

* Only on mongo at it requires Gridstore

* Open file streaming to all adapters supporting it

* Improves coverage of parsers

* Ensures depreciation warning is effective

* Removes unused function

* de-duplicate logic

* Removes necessity of overriding req.params.className on subclasses routers

* Use babel-preset-env to ensure min-version compatible code

* removes dead code

* Leverage indexes in order to infer which field is duplicated upon signup

- A note mentioned that it would be possible to leverage using the indexes on username/email to infer which is duplicated

* Small nit

* Better template to match column name

* Restores original implementation for safety

* nits
This commit is contained in:
Florent Vilmart
2017-09-05 17:51:11 -04:00
committed by GitHub
parent 3079270b3e
commit 139b9e1cb3
18 changed files with 473 additions and 272 deletions

View File

@@ -595,4 +595,290 @@ describe('Parse.File testing', () => {
done();
});
});
it('fails to upload an empty file', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: '',
}, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(400);
expect(body).toEqual('{"code":130,"error":"Invalid file upload."}');
done();
});
});
it('fails to upload without a file name', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/',
body: 'yolo',
}, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(400);
expect(body).toEqual('{"code":122,"error":"Filename not provided."}');
done();
});
});
it('fails to upload without a file name', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/',
body: 'yolo',
}, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(400);
expect(body).toEqual('{"code":122,"error":"Filename not provided."}');
done();
});
});
it('fails to delete an unkown file', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'X-Parse-Master-Key': 'test'
};
request.delete({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
}, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(400);
expect(body).toEqual('{"code":153,"error":"Could not delete file."}');
done();
});
});
describe_only_db('mongo')('Gridstore Range tests', () => {
it('supports range requests', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'argle bargle',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=0-5'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('argle ');
done();
});
});
});
it('supports small range requests', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'argle bargle',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=0-2'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('arg');
done();
});
});
});
// See specs https://www.greenbytes.de/tech/webdav/draft-ietf-httpbis-p5-range-latest.html#byte.ranges
it('supports getting one byte', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'argle bargle',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=2-2'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('g');
done();
});
});
});
it('supports getting last n bytes', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'something different',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=-4'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body.length).toBe(4);
expect(body).toEqual('rent');
done();
});
});
});
it('supports getting first n bytes', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'something different',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=10-'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('different');
done();
});
});
});
function repeat(string, count) {
var s = string;
while (count > 0) {
s += string;
count--;
}
return s;
}
it('supports large range requests', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: repeat('argle bargle', 100)
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=13-240'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body.length).toEqual(228);
expect(body.indexOf('rgle barglea')).toBe(0);
done();
});
});
});
it('fails to stream unknown file', done => {
request.get({ url: 'http://localhost:8378/1/files/test/file.txt', headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=13-240'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(response.statusCode).toBe(404);
expect(body).toEqual('File not found.');
done();
});
});
});
// Because GridStore is not loaded on PG, those are perfect
// for fallback tests
describe_only_db('postgres')('Default Range tests', () => {
it('fallback to regular request', done => {
var headers = {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
};
request.post({
headers: headers,
url: 'http://localhost:8378/1/files/file.txt',
body: 'argle bargle',
}, (error, response, body) => {
expect(error).toBe(null);
var b = JSON.parse(body);
request.get({ url: b.url, headers: {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Range': 'bytes=0-5'
} }, (error, response, body) => {
expect(error).toBe(null);
expect(body).toEqual('argle bargle');
done();
});
});
});
});
});