2020-02-16 09:03:03 -05:00
|
|
|
|
/* eslint-disable
|
|
|
|
|
camelcase,
|
|
|
|
|
handle-callback-err,
|
|
|
|
|
no-unused-vars,
|
|
|
|
|
*/
|
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-16 09:03:02 -05:00
|
|
|
|
/*
|
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
|
*/
|
|
|
|
|
const sinon = require("sinon");
|
|
|
|
|
const chai = require("chai");
|
|
|
|
|
const should = chai.should();
|
|
|
|
|
const {db, ObjectId, ISODate} = require("../../../app/js/mongojs");
|
|
|
|
|
const async = require("async");
|
|
|
|
|
const Settings = require("settings-sharelatex");
|
|
|
|
|
const DocArchiveManager = require("../../../app/js/DocArchiveManager.js");
|
|
|
|
|
const request = require("request");
|
|
|
|
|
const DocstoreApp = require("./helpers/DocstoreApp");
|
|
|
|
|
const DocstoreClient = require("./helpers/DocstoreClient");
|
2015-06-01 17:24:40 -04:00
|
|
|
|
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
describe("Archiving", function() {
|
2018-05-23 06:27:31 -04:00
|
|
|
|
|
2020-02-16 09:03:03 -05:00
|
|
|
|
before(function(done) { return DocstoreApp.ensureRunning(done); });
|
2018-05-23 06:27:31 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
describe("multiple docs in a project", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
this.project_id = ObjectId();
|
|
|
|
|
this.docs = [{
|
|
|
|
|
_id: ObjectId(),
|
|
|
|
|
lines: ["one", "two", "three"],
|
|
|
|
|
ranges: {},
|
2017-03-30 12:13:43 -04:00
|
|
|
|
version: 2
|
|
|
|
|
}, {
|
2020-02-16 09:03:02 -05:00
|
|
|
|
_id: ObjectId(),
|
|
|
|
|
lines: ["aaa", "bbb", "ccc"],
|
|
|
|
|
ranges: {},
|
2017-03-30 12:13:43 -04:00
|
|
|
|
version: 4
|
2020-02-16 09:03:02 -05:00
|
|
|
|
}];
|
|
|
|
|
const jobs = Array.from(this.docs).map((doc) =>
|
|
|
|
|
(doc => {
|
|
|
|
|
return callback => {
|
|
|
|
|
return DocstoreClient.createDoc(this.project_id, doc._id, doc.lines, doc.version, doc.ranges, callback);
|
|
|
|
|
};
|
|
|
|
|
})(doc));
|
2018-05-23 06:27:31 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return async.series(jobs, error => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
|
|
this.res = res;
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-13 08:00:09 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should archive all the docs", function(done) {
|
|
|
|
|
this.res.statusCode.should.equal(204);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
2015-06-02 19:08:50 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set inS3 and unset lines and ranges in each doc", function(done) {
|
|
|
|
|
const jobs = Array.from(this.docs).map((doc) =>
|
|
|
|
|
(doc => {
|
|
|
|
|
return callback => {
|
|
|
|
|
return db.docs.findOne({_id: doc._id}, (error, doc) => {
|
|
|
|
|
should.not.exist(doc.lines);
|
|
|
|
|
should.not.exist(doc.ranges);
|
|
|
|
|
doc.inS3.should.equal(true);
|
|
|
|
|
return callback();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
})(doc));
|
|
|
|
|
return async.series(jobs, done);
|
|
|
|
|
});
|
2015-08-13 08:00:09 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set the docs in s3 correctly", function(done) {
|
|
|
|
|
const jobs = Array.from(this.docs).map((doc) =>
|
|
|
|
|
(doc => {
|
|
|
|
|
return callback => {
|
|
|
|
|
return DocstoreClient.getS3Doc(this.project_id, doc._id, (error, res, s3_doc) => {
|
|
|
|
|
s3_doc.lines.should.deep.equal(doc.lines);
|
|
|
|
|
s3_doc.ranges.should.deep.equal(doc.ranges);
|
|
|
|
|
return callback();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
})(doc));
|
|
|
|
|
return async.series(jobs, done);
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return describe("after unarchiving from a request for the project", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
return DocstoreClient.getAllDocs(this.project_id, (error, res, fetched_docs) => {
|
|
|
|
|
this.fetched_docs = fetched_docs;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should return the docs", function(done) {
|
|
|
|
|
for (let i = 0; i < this.fetched_docs.length; i++) {
|
|
|
|
|
const doc = this.fetched_docs[i];
|
|
|
|
|
doc.lines.should.deep.equal(this.docs[i].lines);
|
|
|
|
|
}
|
|
|
|
|
return done();
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return it("should restore the docs to mongo", function(done) {
|
|
|
|
|
const jobs = Array.from(this.docs).map((doc, i) =>
|
|
|
|
|
((doc, i) => {
|
|
|
|
|
return callback => {
|
|
|
|
|
return db.docs.findOne({_id: doc._id}, (error, doc) => {
|
|
|
|
|
doc.lines.should.deep.equal(this.docs[i].lines);
|
|
|
|
|
doc.ranges.should.deep.equal(this.docs[i].ranges);
|
|
|
|
|
should.not.exist(doc.inS3);
|
|
|
|
|
return callback();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
})(doc, i));
|
|
|
|
|
return async.series(jobs, done);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
describe("a deleted doc", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
this.project_id = ObjectId();
|
|
|
|
|
this.doc = {
|
|
|
|
|
_id: ObjectId(),
|
|
|
|
|
lines: ["one", "two", "three"],
|
|
|
|
|
ranges: {},
|
2017-03-30 12:13:43 -04:00
|
|
|
|
version: 2
|
2020-02-16 09:03:02 -05:00
|
|
|
|
};
|
|
|
|
|
return DocstoreClient.createDoc(this.project_id, this.doc._id, this.doc.lines, this.doc.version, this.doc.ranges, error => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return DocstoreClient.deleteDoc(this.project_id, this.doc._id, error => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
|
|
this.res = res;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should successully archive the docs", function(done) {
|
|
|
|
|
this.res.statusCode.should.equal(204);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set inS3 and unset lines and ranges in each doc", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
should.not.exist(doc.lines);
|
|
|
|
|
should.not.exist(doc.ranges);
|
|
|
|
|
doc.inS3.should.equal(true);
|
|
|
|
|
doc.deleted.should.equal(true);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set the doc in s3 correctly", function(done) {
|
|
|
|
|
return DocstoreClient.getS3Doc(this.project_id, this.doc._id, (error, res, s3_doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
s3_doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
s3_doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return describe("after unarchiving from a request for the project", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
return DocstoreClient.getAllDocs(this.project_id, (error, res, fetched_docs) => {
|
|
|
|
|
this.fetched_docs = fetched_docs;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should not included the deleted", function(done) {
|
|
|
|
|
this.fetched_docs.length.should.equal(0);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return it("should restore the doc to mongo", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
should.not.exist(doc.inS3);
|
|
|
|
|
doc.deleted.should.equal(true);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
describe("a doc with large lines", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
this.project_id = ObjectId();
|
|
|
|
|
this.timeout(1000 * 30);
|
|
|
|
|
const quarterMegInBytes = 250000;
|
|
|
|
|
const big_line = require("crypto").randomBytes(quarterMegInBytes).toString("hex");
|
|
|
|
|
this.doc = {
|
|
|
|
|
_id: ObjectId(),
|
|
|
|
|
lines: [big_line, big_line, big_line, big_line],
|
|
|
|
|
ranges: {},
|
2017-03-30 12:13:43 -04:00
|
|
|
|
version: 2
|
2020-02-16 09:03:02 -05:00
|
|
|
|
};
|
|
|
|
|
return DocstoreClient.createDoc(this.project_id, this.doc._id, this.doc.lines, this.doc.version, this.doc.ranges, error => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
|
|
this.res = res;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should successully archive the docs", function(done) {
|
|
|
|
|
this.res.statusCode.should.equal(204);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set inS3 and unset lines and ranges in each doc", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
should.not.exist(doc.lines);
|
|
|
|
|
should.not.exist(doc.ranges);
|
|
|
|
|
doc.inS3.should.equal(true);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set the doc in s3 correctly", function(done) {
|
|
|
|
|
return DocstoreClient.getS3Doc(this.project_id, this.doc._id, (error, res, s3_doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
s3_doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
s3_doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return describe("after unarchiving from a request for the project", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
return DocstoreClient.getAllDocs(this.project_id, (error, res, fetched_docs) => {
|
|
|
|
|
this.fetched_docs = fetched_docs;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return it("should restore the doc to mongo", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
should.not.exist(doc.inS3);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
describe("a doc with naughty strings", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
this.project_id = ObjectId();
|
|
|
|
|
this.doc = {
|
|
|
|
|
_id: ObjectId(),
|
|
|
|
|
lines: [ "", "undefined", "undef", "null", "NULL", "(null)", "nil", "NIL", "true", "false", "True", "False", "None", "\\", "\\\\", "0", "1", "1.00", "$1.00", "1/2", "1E2", "1E02", "1E+02", "-1", "-1.00", "-$1.00", "-1/2", "-1E2", "-1E02", "-1E+02", "1/0", "0/0", "-2147483648/-1", "-9223372036854775808/-1", "0.00", "0..0", ".", "0.0.0", "0,00", "0,,0", ",", "0,0,0", "0.0/0", "1.0/0.0", "0.0/0.0", "1,0/0,0", "0,0/0,0", "--1", "-", "-.", "-,", "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "NaN", "Infinity", "-Infinity", "0x0", "0xffffffff", "0xffffffffffffffff", "0xabad1dea", "123456789012345678901234567890123456789", "1,000.00", "1 000.00", "1'000.00", "1,000,000.00", "1 000 000.00", "1'000'000.00", "1.000,00", "1 000,00", "1'000,00", "1.000.000,00", "1 000i̳̞v̢͇ḙ͎͟-҉̭̩̼͔m̤̭̫i͕͇̝̦n̗͙ḍ̟ ̯̲͕͞ǫ̟̯̰̲͙̻̝f ̪̰̰̗̖̭̘͘c̦͍̲̞͍̩̙ḥ͚a̮͎̟̙͜ơ̩̹͎s̤.̝̝ ҉Z̡̖̜͖̰̣͉̜a͖̰͙̬͡l̲̫̳͍̩g̡̟̼̱͚̞̬ͅo̗͜.̟", "̦H̬̤̗̤͝e͜ ̜̥̝̻͍̟́w̕h̖̯͓o̝͙̖͎̱̮ ҉̺̙̞̟͈W̷̼̭a̺̪͍į͈͕̭͙̯̜t̶̼̮s̘͙͖̕ ̠̫̠B̻͍͙͉̳ͅe̵h̵̬͇̫͙i̹͓̳̳̮͎̫̕n͟d̴̪̜̖ ̰͉̩͇͙̲͞ͅT͖̼͓̪͢h͏͓̮̻e̬̝̟ͅ ̤̹̝W͙̞̝͔͇͝ͅa͏͓͔̹̼̣l̴͔̰̤̟͔ḽ̫.͕", "Z̮̞̠͙͔ͅḀ̗̞͈̻̗Ḷ͙͎̯̹̞͓G̻O̭̗̮", "˙ɐnbᴉlɐ ɐuƃɐɯ ǝɹolop ʇǝ ǝɹoqɐl ʇn ʇunpᴉpᴉɔuᴉ ɹodɯǝʇ poɯsnᴉǝ op pǝs 'ʇᴉlǝ ƃuᴉɔsᴉdᴉpɐ ɹnʇǝʇɔǝsuoɔ 'ʇǝɯɐ ʇᴉs ɹolop ɯnsdᴉ ɯǝɹo˥", "00˙Ɩ$-", "The quick brown fox jumps over the lazy dog", "𝐓𝐡𝐞 𝐪𝐮𝐢𝐜𝐤 𝐛𝐫𝐨𝐰𝐧 𝐟𝐨𝐱 𝐣𝐮𝐦𝐩𝐬 𝐨𝐯𝐞𝐫 𝐭𝐡𝐞 𝐥𝐚𝐳𝐲 𝐝𝐨𝐠", "𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐 𝖇𝖗𝖔𝖜𝖓 𝖋𝖔𝖝 𝖏𝖚𝖒𝖕𝖘 𝖔𝖛𝖊𝖗 𝖙𝖍𝖊 𝖑𝖆𝖟𝖞 𝖉𝖔𝖌", "𝑻𝒉𝒆 𝒒𝒖𝒊𝒄𝒌 𝒃𝒓𝒐𝒘𝒏 𝒇𝒐𝒙 𝒋𝒖𝒎𝒑𝒔 𝒐𝒗𝒆𝒓 𝒕𝒉𝒆 𝒍𝒂𝒛𝒚 𝒅𝒐𝒈", "𝓣𝓱𝓮 𝓺𝓾𝓲𝓬𝓴 𝓫𝓻𝓸𝔀𝓷 𝓯𝓸𝔁 𝓳𝓾𝓶𝓹𝓼 𝓸𝓿𝓮𝓻 𝓽𝓱𝓮 𝓵𝓪𝔃𝔂 𝓭𝓸𝓰", "𝕋𝕙𝕖 𝕢𝕦𝕚𝕔𝕜 𝕓𝕣𝕠𝕨𝕟 𝕗𝕠𝕩 𝕛𝕦𝕞𝕡𝕤 𝕠𝕧𝕖𝕣 𝕥𝕙𝕖 𝕝𝕒𝕫𝕪 𝕕𝕠𝕘", "𝚃𝚑𝚎 𝚚𝚞𝚒𝚌𝚔 𝚋𝚛𝚘𝚠𝚗 𝚏𝚘𝚡 𝚓𝚞𝚖𝚙𝚜 𝚘𝚟𝚎𝚛 𝚝𝚑𝚎 𝚕𝚊𝚣𝚢 𝚍𝚘𝚐", "⒯⒣⒠ ⒬⒰⒤⒞⒦ ⒝⒭⒪⒲⒩ ⒡⒪⒳ ⒥⒰⒨⒫⒮ ⒪⒱⒠⒭ ⒯⒣⒠ ⒧⒜⒵⒴ ⒟⒪⒢", "<script>alert(123)</script>", "<script>alert('123');</script>", "<img src=x onerror=alert(123) />", "<svg><script>123<1>alert(123)</script> ", "\"><script>alert(123)</script>", "'><script>alert(123)</script>", "><script>alert(123)</script>", "</script><script>alert(123)</script>", "< / script >< script >alert(123)< / script >", " onfocus=JaVaSCript:alert(123) autofocus ", "\" onfocus=JaVaSCript:alert(123) autofocus ", "' onfocus=JaVaSCript:alert(123) autofocus ", "<script>alert(123)</script>", "<sc<script>ript>alert(123)</sc</script>ript>", "--><script>alert(123)</script>", "\";alert(123);t=\"", "';alert(123);t='", "JavaSCript:alert(123)", ";alert(123);", "src=JaVaSCript:prompt(132)", "\"><script>alert(123);</script x=\"", "'><script>alert(123);</script x='", "><script>alert(123);</script x=", "\" autofocus onkeyup=\"javascript:alert(123)", "' autofocus onkeyup='javascript:alert(123)", "<script\\x20type=\"text/javascript\">javascript:alert(1);</script>", "<script\\x3Etype=\"text/javascript\">javascript:alert(1);</script>", "<script\\x0Dtype=\"text/javascript\">javascript:alert(1);</script>", "<script\\x09type=\"text/javascript\">javascript:alert(1);</script>", "<script\\x0Ctype=\"text/javascript\">javascript:alert(1);</script>", "<script\\x2Ftype=\"text/javascript\">javascript:alert(1);</script>", "<script\\x0Atype=\"t
|
|
|
|
|
ranges: {},
|
2017-03-30 12:13:43 -04:00
|
|
|
|
version: 2
|
2020-02-16 09:03:02 -05:00
|
|
|
|
};
|
|
|
|
|
return DocstoreClient.createDoc(this.project_id, this.doc._id, this.doc.lines, this.doc.version, this.doc.ranges, error => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
|
|
this.res = res;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should successully archive the docs", function(done) {
|
|
|
|
|
this.res.statusCode.should.equal(204);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set inS3 and unset lines and ranges in each doc", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
should.not.exist(doc.lines);
|
|
|
|
|
should.not.exist(doc.ranges);
|
|
|
|
|
doc.inS3.should.equal(true);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set the doc in s3 correctly", function(done) {
|
|
|
|
|
return DocstoreClient.getS3Doc(this.project_id, this.doc._id, (error, res, s3_doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
s3_doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
s3_doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return describe("after unarchiving from a request for the project", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
return DocstoreClient.getAllDocs(this.project_id, (error, res, fetched_docs) => {
|
|
|
|
|
this.fetched_docs = fetched_docs;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return it("should restore the doc to mongo", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
should.not.exist(doc.inS3);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
describe("a doc with ranges", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
this.project_id = ObjectId();
|
|
|
|
|
this.doc = {
|
|
|
|
|
_id: ObjectId(),
|
|
|
|
|
lines: ["one", "two", "three"],
|
2017-03-30 12:13:43 -04:00
|
|
|
|
ranges: {
|
|
|
|
|
changes:
|
|
|
|
|
[{
|
|
|
|
|
id : ObjectId(),
|
2020-02-16 09:03:02 -05:00
|
|
|
|
op : { "i" : "foo", "p" : 24 },
|
2017-03-30 12:13:43 -04:00
|
|
|
|
metadata : { "user_id" : ObjectId(), "ts" : new Date("2017-01-27T16:10:44.194Z") }
|
|
|
|
|
}, {
|
|
|
|
|
id : ObjectId(),
|
2020-02-16 09:03:02 -05:00
|
|
|
|
op : { "d" : "bar", "p" : 50 },
|
2017-03-30 12:13:43 -04:00
|
|
|
|
metadata : { "user_id" : ObjectId(), "ts" : new Date("2017-01-27T18:10:44.194Z") }
|
2020-02-16 09:03:02 -05:00
|
|
|
|
}],
|
2017-03-30 12:13:43 -04:00
|
|
|
|
comments: [{
|
|
|
|
|
id: ObjectId(),
|
|
|
|
|
op: { "c" : "comment", "p" : 284, "t" : ObjectId() },
|
|
|
|
|
metadata: { "user_id" : ObjectId(), "ts" : new Date("2017-01-26T14:22:04.869Z") }
|
|
|
|
|
}]
|
2020-02-16 09:03:02 -05:00
|
|
|
|
},
|
2017-03-30 12:13:43 -04:00
|
|
|
|
version: 2
|
2020-02-16 09:03:02 -05:00
|
|
|
|
};
|
|
|
|
|
return DocstoreClient.createDoc(this.project_id, this.doc._id, this.doc.lines, this.doc.version, this.doc.ranges, error => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
|
|
this.res = res;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should successully archive the docs", function(done) {
|
|
|
|
|
this.res.statusCode.should.equal(204);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set inS3 and unset lines and ranges in each doc", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
should.not.exist(doc.lines);
|
|
|
|
|
should.not.exist(doc.ranges);
|
|
|
|
|
doc.inS3.should.equal(true);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set the doc in s3 correctly", function(done) {
|
|
|
|
|
return DocstoreClient.getS3Doc(this.project_id, this.doc._id, (error, res, s3_doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
s3_doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
const ranges = JSON.parse(JSON.stringify(this.doc.ranges)); // ObjectId -> String
|
|
|
|
|
s3_doc.ranges.should.deep.equal(ranges);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return describe("after unarchiving from a request for the project", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
return DocstoreClient.getAllDocs(this.project_id, (error, res, fetched_docs) => {
|
|
|
|
|
this.fetched_docs = fetched_docs;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return it("should restore the doc to mongo", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
should.not.exist(doc.inS3);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
describe("a doc that is archived twice", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
this.project_id = ObjectId();
|
|
|
|
|
this.doc = {
|
|
|
|
|
_id: ObjectId(),
|
|
|
|
|
lines: ["abc", "def", "ghi"],
|
|
|
|
|
ranges: {},
|
2017-03-30 12:13:43 -04:00
|
|
|
|
version: 2
|
2020-02-16 09:03:02 -05:00
|
|
|
|
};
|
|
|
|
|
return DocstoreClient.createDoc(this.project_id, this.doc._id, this.doc.lines, this.doc.version, this.doc.ranges, error => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
|
|
this.res = res;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
this.res.statusCode.should.equal(204);
|
|
|
|
|
return DocstoreClient.archiveAllDoc(this.project_id, (error, res1) => {
|
|
|
|
|
this.res = res1;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
this.res.statusCode.should.equal(204);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-13 17:48:17 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set inS3 and unset lines and ranges in each doc", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
should.not.exist(doc.lines);
|
|
|
|
|
should.not.exist(doc.ranges);
|
|
|
|
|
doc.inS3.should.equal(true);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should set the doc in s3 correctly", function(done) {
|
|
|
|
|
return DocstoreClient.getS3Doc(this.project_id, this.doc._id, (error, res, s3_doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
s3_doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
s3_doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return describe("after unarchiving from a request for the project", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
return DocstoreClient.getAllDocs(this.project_id, (error, res, fetched_docs) => {
|
|
|
|
|
this.fetched_docs = fetched_docs;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return it("should restore the doc to mongo", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
doc.ranges.should.deep.equal(this.doc.ranges);
|
|
|
|
|
should.not.exist(doc.inS3);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return describe("a doc with the old schema (just an array of lines)", function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
this.project_id = ObjectId();
|
|
|
|
|
this.doc = {
|
|
|
|
|
_id: ObjectId(),
|
|
|
|
|
lines: ["abc", "def", "ghi"],
|
|
|
|
|
ranges: {},
|
2017-03-30 12:13:43 -04:00
|
|
|
|
version: 2
|
2020-02-16 09:03:02 -05:00
|
|
|
|
};
|
|
|
|
|
const options = DocArchiveManager.buildS3Options(`${this.project_id}/${this.doc._id}`);
|
|
|
|
|
options.json = this.doc.lines;
|
|
|
|
|
return request.put(options, (error, res, body) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
res.statusCode.should.equal(200);
|
|
|
|
|
return db.docs.insert({
|
|
|
|
|
project_id: this.project_id,
|
|
|
|
|
_id: this.doc._id,
|
|
|
|
|
rev: this.doc.version,
|
2017-03-30 12:13:43 -04:00
|
|
|
|
inS3: true
|
2020-02-16 09:03:02 -05:00
|
|
|
|
}, error => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return DocstoreClient.getAllDocs(this.project_id, (error, res, fetched_docs) => {
|
|
|
|
|
this.fetched_docs = fetched_docs;
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
it("should restore the doc to mongo", function(done) {
|
|
|
|
|
return db.docs.findOne({_id: this.doc._id}, (error, doc) => {
|
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
|
doc.lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
should.not.exist(doc.inS3);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-30 12:13:43 -04:00
|
|
|
|
|
2020-02-16 09:03:02 -05:00
|
|
|
|
return it("should return the doc", function(done) {
|
|
|
|
|
this.fetched_docs[0].lines.should.deep.equal(this.doc.lines);
|
|
|
|
|
return done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-09 13:18:50 -05:00
|
|
|
|
|