From 785a6cb5444d9795c85a9882aaad9961c0e829ea Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Sun, 16 Feb 2020 14:03:09 +0000 Subject: [PATCH] prettier: convert test/acceptance decaffeinated files to Prettier format --- .../test/acceptance/js/ArchiveDocsTests.js | 1561 +++++++++++------ .../test/acceptance/js/DeletingDocsTests.js | 234 +-- .../test/acceptance/js/GettingAllDocsTests.js | 169 +- .../test/acceptance/js/GettingDocsTests.js | 187 +- .../test/acceptance/js/UpdatingDocsTests.js | 733 +++++--- .../test/acceptance/js/helpers/DocstoreApp.js | 62 +- .../acceptance/js/helpers/DocstoreClient.js | 183 +- 7 files changed, 2012 insertions(+), 1117 deletions(-) diff --git a/services/docstore/test/acceptance/js/ArchiveDocsTests.js b/services/docstore/test/acceptance/js/ArchiveDocsTests.js index 69a3ec2308..67d5d0e828 100644 --- a/services/docstore/test/acceptance/js/ArchiveDocsTests.js +++ b/services/docstore/test/acceptance/js/ArchiveDocsTests.js @@ -12,514 +12,1097 @@ * 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"); +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') +describe('Archiving', function() { + before(function(done) { + return DocstoreApp.ensureRunning(done) + }) -describe("Archiving", function() { + describe('multiple docs in a project', function() { + before(function(done) { + this.project_id = ObjectId() + this.docs = [ + { + _id: ObjectId(), + lines: ['one', 'two', 'three'], + ranges: {}, + version: 2 + }, + { + _id: ObjectId(), + lines: ['aaa', 'bbb', 'ccc'], + ranges: {}, + version: 4 + } + ] + 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) + ) - before(function(done) { return DocstoreApp.ensureRunning(done); }); + return async.series(jobs, error => { + if (error != null) { + throw error + } + return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => { + this.res = res + return done() + }) + }) + }) - describe("multiple docs in a project", function() { - before(function(done) { - this.project_id = ObjectId(); - this.docs = [{ - _id: ObjectId(), - lines: ["one", "two", "three"], - ranges: {}, - version: 2 - }, { - _id: ObjectId(), - lines: ["aaa", "bbb", "ccc"], - ranges: {}, - version: 4 - }]; - 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)); + it('should archive all the docs', function(done) { + this.res.statusCode.should.equal(204) + return done() + }) - return async.series(jobs, error => { - if (error != null) { throw error; } - return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => { - this.res = res; - return done(); - }); - }); - }); + 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) + }) - it("should archive all the docs", function(done) { - this.res.statusCode.should.equal(204); - return done(); - }); + 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) + }) - 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); - }); + 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() + } + ) + }) - 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); - }); - - 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(); - }); - }); - - 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(); - }); - - 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); - }); - }); - }); - - describe("a deleted doc", function() { - before(function(done) { - this.project_id = ObjectId(); - this.doc = { - _id: ObjectId(), - lines: ["one", "two", "three"], - ranges: {}, - version: 2 - }; - 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(); - }); - }); - }); - }); - - it("should successully archive the docs", function(done) { - this.res.statusCode.should.equal(204); - return done(); - }); + 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() + }) - 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(); - }); - }); - - 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(); - }); - }); - - 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(); - }); - }); - - it("should not included the deleted", function(done) { - this.fetched_docs.length.should.equal(0); - return done(); - }); - - 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(); - }); - }); - }); - }); - - 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: {}, - version: 2 - }; - 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(); - }); - }); - }); - - it("should successully archive the docs", function(done) { - this.res.statusCode.should.equal(204); - return done(); - }); + 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) + }) + }) + }) - 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(); - }); - }); + describe('a deleted doc', function() { + before(function(done) { + this.project_id = ObjectId() + this.doc = { + _id: ObjectId(), + lines: ['one', 'two', 'three'], + ranges: {}, + version: 2 + } + 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() + } + ) + } + ) + } + ) + }) - 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(); - }); - }); - - 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(); - }); - }); - - 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(); - }); - }); - }); - }); - - 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 >< script >alert(123)< / script >", " onfocus=JaVaSCript:alert(123) autofocus ", "\" onfocus=JaVaSCript:alert(123) autofocus ", "' onfocus=JaVaSCript:alert(123) autofocus ", "<script>alert(123)</script>", "ript>alert(123)ript>", "-->", "\";alert(123);t=\"", "';alert(123);t='", "JavaSCript:alert(123)", ";alert(123);", "src=JaVaSCript:prompt(132)", "\"><\\x3Cscript>javascript:alert(1) ", "'`\"><\\x00script>javascript:alert(1)", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "ABC
DEF", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "`\"'>", "`\"'>", "`\"'>", "`\"'>", "`\"'>", "`\"'>", "`\"'>", "`\"'>", "`\"'>", "`\"'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "\"`'>", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "XXX", "javascript:alert(1)\"` `>", "", "", "<a href=http://foo.bar/#x=`y></a><img alt=\"`><img src=x:x onerror=javascript:alert(1)></a>\">", "<!--[if]><script>javascript:alert(1)</script -->", "<!--[if<img src=x onerror=javascript:alert(1)//]> -->", "<script src=\"/\\%(jscript)s\"></script>", "<script src=\"\\\\%(jscript)s\"></script>", "<IMG \"\"\"><SCRIPT>alert(\"XSS\")</SCRIPT>\">", "<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>", "<IMG SRC=# onmouseover=\"alert('xxs')\">", "<IMG SRC= onmouseover=\"alert('xxs')\">", "<IMG onmouseover=\"alert('xxs')\">", "<IMG SRC=javascript:alert('XSS')>", "<IMG SRC=javascript:alert('XSS')>", "<IMG SRC=javascript:alert('XSS')>", "<IMG SRC=\"jav ascript:alert('XSS');\">", "<IMG SRC=\"jav ascript:alert('XSS');\">", "<IMG SRC=\"jav ascript:alert('XSS');\">", "<IMG SRC=\"jav ascript:alert('XSS');\">", "perl -e 'print \"<IMG SRC=java\\0script:alert(\\\"XSS\\\")>\";' > out", "<IMG SRC=\"  javascript:alert('XSS');\">", "<SCRIPT/XSS SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<BODY onload!#$%&()*~+-_.,:;?@[/|\\]^`=alert(\"XSS\")>", "<SCRIPT/SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<<SCRIPT>alert(\"XSS\");//<</SCRIPT>", "<SCRIPT SRC=http://ha.ckers.org/xss.js?< B >", "<SCRIPT SRC=//ha.ckers.org/.j>", "<IMG SRC=\"javascript:alert('XSS')\"", "<iframe src=http://ha.ckers.org/scriptlet.html <", "\\\";alert('XSS');//", "<plaintext>", "1;DROP TABLE users", "1'; DROP TABLE users-- 1", "' OR 1=1 -- 1", "' OR '1'='1", "-", "--", "--version", "--help", "$USER", "/dev/null; touch /tmp/blns.fail ; echo", "`touch /tmp/blns.fail`", "$(touch /tmp/blns.fail)", "@{[system \"touch /tmp/blns.fail\"]}", "eval(\"puts 'hello world'\")", "System(\"ls -al /\")", "`ls -al /`", "Kernel.exec(\"ls -al /\")", "Kernel.exit(1)", "%x('ls -al /')", "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><!DOCTYPE foo [ <!ELEMENT foo ANY ><!ENTITY xxe SYSTEM \"file:///etc/passwd\" >]><foo>&xxe;</foo>", "$HOME", "$ENV{'HOME'}", "%d", "%s", "%*.*s", "../../../../../../../../../../../etc/passwd%00", "../../../../../../../../../../../etc/hosts", "() { 0; }; touch /tmp/blns.shellshock1.fail;", "() { _; } >_[$($())] { touch /tmp/blns.shellshock2.fail; }", "CON", "PRN", "AUX", "CLOCK$", "NUL", "A:", "ZZ:", "COM1", "LPT1", "LPT2", "LPT3", "COM2", "COM3", "COM4", "Scunthorpe General Hospital", "Penistone Community Church", "Lightwater Country Park", "Jimmy Clitheroe", "Horniman Museum", "shitake mushrooms", "RomansInSussex.co.uk", "http://www.cum.qc.ca/", "Craig Cockburn, Software Specialist", "Linda Callahan", "Dr. Herman I. Libshitz", "magna cum laude", "Super Bowl XXX", "medieval erection of parapets", "evaluate", "mocha", "expression", "Arsenal canal", "classic", "Tyson Gay", "If you're reading this, you've been in a coma for almost 20 years now. We're trying a new technique. We don't know where this message will end up in your dream, but we hope it works. Please wake up, we miss you.", "Roses are \u001b[0;31mred\u001b[0m, violets are \u001b[0;34mblue. Hope you enjoy terminal hue", "But now...\u001b[20Cfor my greatest trick...\u001b[8m", "The quic\b\b\b\b\b\bk brown fo\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007x... [Beeeep]", "Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗" ], - ranges: {}, - version: 2 - }; - 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(); - }); - }); - }); - - it("should successully archive the docs", function(done) { - this.res.statusCode.should.equal(204); - return done(); - }); + it('should successully archive the docs', function(done) { + this.res.statusCode.should.equal(204) + return done() + }) - 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(); - }); - }); + 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() + }) + }) - 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(); - }); - }); - - 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(); - }); - }); - - 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(); - }); - }); - }); - }); + 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() + } + ) + }) - describe("a doc with ranges", function() { - before(function(done) { - this.project_id = ObjectId(); - this.doc = { - _id: ObjectId(), - lines: ["one", "two", "three"], - ranges: { - changes: - [{ - id : ObjectId(), - op : { "i" : "foo", "p" : 24 }, - metadata : { "user_id" : ObjectId(), "ts" : new Date("2017-01-27T16:10:44.194Z") } - }, { - id : ObjectId(), - op : { "d" : "bar", "p" : 50 }, - metadata : { "user_id" : ObjectId(), "ts" : new Date("2017-01-27T18:10:44.194Z") } - }], - comments: [{ - id: ObjectId(), - op: { "c" : "comment", "p" : 284, "t" : ObjectId() }, - metadata: { "user_id" : ObjectId(), "ts" : new Date("2017-01-26T14:22:04.869Z") } - }] - }, - version: 2 - }; - 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(); - }); - }); - }); - - it("should successully archive the docs", function(done) { - this.res.statusCode.should.equal(204); - return done(); - }); + 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() + } + ) + }) - 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(); - }); - }); + it('should not included the deleted', function(done) { + this.fetched_docs.length.should.equal(0) + return done() + }) - 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(); - }); - }); - - 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(); - }); - }); - - 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(); - }); - }); - }); - }); + 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() + }) + }) + }) + }) - describe("a doc that is archived twice", function() { - before(function(done) { - this.project_id = ObjectId(); - this.doc = { - _id: ObjectId(), - lines: ["abc", "def", "ghi"], - ranges: {}, - version: 2 - }; - 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(); - }); - }); - }); - }); + 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: {}, + version: 2 + } + 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() + }) + } + ) + }) - 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(); - }); - }); + it('should successully archive the docs', function(done) { + this.res.statusCode.should.equal(204) + return done() + }) - 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(); - }); - }); - - 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(); - }); - }); - - 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(); - }); - }); - }); - }); + 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() + }) + }) - 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: {}, - version: 2 - }; - 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, - inS3: true - }, 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(); - }); - }); - }); - }); + 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() + } + ) + }) - 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(); - }); - }); - - return it("should return the doc", function(done) { - this.fetched_docs[0].lines.should.deep.equal(this.doc.lines); - return done(); - }); - }); -}); + 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() + } + ) + }) + 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() + }) + }) + }) + }) + + 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="text/javascript">javascript:alert(1);</script>', + '\'`"><\\x3Cscript>javascript:alert(1)</script> ', + '\'`"><\\x00script>javascript:alert(1)</script>', + 'ABC<div style="x\\x3Aexpression(javascript:alert(1)">DEF', + 'ABC<div style="x:expression\\x5C(javascript:alert(1)">DEF', + 'ABC<div style="x:expression\\x00(javascript:alert(1)">DEF', + 'ABC<div style="x:exp\\x00ression(javascript:alert(1)">DEF', + 'ABC<div style="x:exp\\x5Cression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\x0Aexpression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\x09expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE3\\x80\\x80expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x84expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xC2\\xA0expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x80expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x8Aexpression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\x0Dexpression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\x0Cexpression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x87expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xEF\\xBB\\xBFexpression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\x20expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x88expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\x00expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x8Bexpression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x86expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x85expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x82expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\x0Bexpression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x81expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x83expression(javascript:alert(1)">DEF', + 'ABC<div style="x:\\xE2\\x80\\x89expression(javascript:alert(1)">DEF', + '<a href="\\x0Bjavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x0Fjavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xC2\\xA0javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x05javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE1\\xA0\\x8Ejavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x18javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x11javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x88javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x89javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x80javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x17javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x03javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x0Ejavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x1Ajavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x00javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x10javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x82javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x20javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x13javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x09javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x8Ajavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x14javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x19javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\xAFjavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x1Fjavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x81javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x1Djavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x87javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x07javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE1\\x9A\\x80javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x83javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x04javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x01javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x08javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x84javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x86javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE3\\x80\\x80javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x12javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x0Djavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x0Ajavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x0Cjavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x15javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\xA8javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x16javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x02javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x1Bjavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x06javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\xA9javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x80\\x85javascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x1Ejavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\xE2\\x81\\x9Fjavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="\\x1Cjavascript:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="javascript\\x00:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="javascript\\x3A:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="javascript\\x09:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="javascript\\x0D:javascript:alert(1)" id="fuzzelement1">test</a>', + '<a href="javascript\\x0A:javascript:alert(1)" id="fuzzelement1">test</a>', + '`"\'><img src=xxx:x \\x0Aonerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x22onerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x0Bonerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x0Donerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x2Fonerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x09onerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x0Conerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x00onerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x27onerror=javascript:alert(1)>', + '`"\'><img src=xxx:x \\x20onerror=javascript:alert(1)>', + '"`\'><script>\\x3Bjavascript:alert(1)</script>', + '"`\'><script>\\x0Djavascript:alert(1)</script>', + '"`\'><script>\\xEF\\xBB\\xBFjavascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x81javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x84javascript:alert(1)</script>', + '"`\'><script>\\xE3\\x80\\x80javascript:alert(1)</script>', + '"`\'><script>\\x09javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x89javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x85javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x88javascript:alert(1)</script>', + '"`\'><script>\\x00javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\xA8javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x8Ajavascript:alert(1)</script>', + '"`\'><script>\\xE1\\x9A\\x80javascript:alert(1)</script>', + '"`\'><script>\\x0Cjavascript:alert(1)</script>', + '"`\'><script>\\x2Bjavascript:alert(1)</script>', + '"`\'><script>\\xF0\\x90\\x96\\x9Ajavascript:alert(1)</script>', + '"`\'><script>-javascript:alert(1)</script>', + '"`\'><script>\\x0Ajavascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\xAFjavascript:alert(1)</script>', + '"`\'><script>\\x7Ejavascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x87javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x81\\x9Fjavascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\xA9javascript:alert(1)</script>', + '"`\'><script>\\xC2\\x85javascript:alert(1)</script>', + '"`\'><script>\\xEF\\xBF\\xAEjavascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x83javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x8Bjavascript:alert(1)</script>', + '"`\'><script>\\xEF\\xBF\\xBEjavascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x80javascript:alert(1)</script>', + '"`\'><script>\\x21javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x82javascript:alert(1)</script>', + '"`\'><script>\\xE2\\x80\\x86javascript:alert(1)</script>', + '"`\'><script>\\xE1\\xA0\\x8Ejavascript:alert(1)</script>', + '"`\'><script>\\x0Bjavascript:alert(1)</script>', + '"`\'><script>\\x20javascript:alert(1)</script>', + '"`\'><script>\\xC2\\xA0javascript:alert(1)</script>', + '<img \\x00src=x onerror="alert(1)">', + '<img \\x47src=x onerror="javascript:alert(1)">', + '<img \\x11src=x onerror="javascript:alert(1)">', + '<img \\x12src=x onerror="javascript:alert(1)">', + '<img\\x47src=x onerror="javascript:alert(1)">', + '<img\\x10src=x onerror="javascript:alert(1)">', + '<img\\x13src=x onerror="javascript:alert(1)">', + '<img\\x32src=x onerror="javascript:alert(1)">', + '<img\\x47src=x onerror="javascript:alert(1)">', + '<img\\x11src=x onerror="javascript:alert(1)">', + '<img \\x47src=x onerror="javascript:alert(1)">', + '<img \\x34src=x onerror="javascript:alert(1)">', + '<img \\x39src=x onerror="javascript:alert(1)">', + '<img \\x00src=x onerror="javascript:alert(1)">', + '<img src\\x09=x onerror="javascript:alert(1)">', + '<img src\\x10=x onerror="javascript:alert(1)">', + '<img src\\x13=x onerror="javascript:alert(1)">', + '<img src\\x32=x onerror="javascript:alert(1)">', + '<img src\\x12=x onerror="javascript:alert(1)">', + '<img src\\x11=x onerror="javascript:alert(1)">', + '<img src\\x00=x onerror="javascript:alert(1)">', + '<img src\\x47=x onerror="javascript:alert(1)">', + '<img src=x\\x09onerror="javascript:alert(1)">', + '<img src=x\\x10onerror="javascript:alert(1)">', + '<img src=x\\x11onerror="javascript:alert(1)">', + '<img src=x\\x12onerror="javascript:alert(1)">', + '<img src=x\\x13onerror="javascript:alert(1)">', + '<img[a][b][c]src[d]=x[e]onerror=[f]"alert(1)">', + '<img src=x onerror=\\x09"javascript:alert(1)">', + '<img src=x onerror=\\x10"javascript:alert(1)">', + '<img src=x onerror=\\x11"javascript:alert(1)">', + '<img src=x onerror=\\x12"javascript:alert(1)">', + '<img src=x onerror=\\x32"javascript:alert(1)">', + '<img src=x onerror=\\x00"javascript:alert(1)">', + '<a href=java script:javascript:alert(1)>XXX</a>', + '<img src="x` `<script>javascript:alert(1)</script>"` `>', + '<img src onerror /" \'"= alt=javascript:alert(1)//">', + '<title onpropertychange=javascript:alert(1)>', + '<a href=http://foo.bar/#x=`y></a><img alt="`><img src=x:x onerror=javascript:alert(1)></a>">', + '<!--[if]><script>javascript:alert(1)</script -->', + '<!--[if<img src=x onerror=javascript:alert(1)//]> -->', + '<script src="/\\%(jscript)s"></script>', + '<script src="\\\\%(jscript)s"></script>', + '<IMG """><SCRIPT>alert("XSS")</SCRIPT>">', + '<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>', + '<IMG SRC=# onmouseover="alert(\'xxs\')">', + '<IMG SRC= onmouseover="alert(\'xxs\')">', + '<IMG onmouseover="alert(\'xxs\')">', + '<IMG SRC=javascript:alert('XSS')>', + '<IMG SRC=javascript:alert('XSS')>', + '<IMG SRC=javascript:alert('XSS')>', + '<IMG SRC="jav ascript:alert(\'XSS\');">', + '<IMG SRC="jav ascript:alert(\'XSS\');">', + '<IMG SRC="jav ascript:alert(\'XSS\');">', + '<IMG SRC="jav ascript:alert(\'XSS\');">', + 'perl -e \'print "<IMG SRC=java\\0script:alert(\\"XSS\\")>";\' > out', + '<IMG SRC="  javascript:alert(\'XSS\');">', + '<SCRIPT/XSS SRC="http://ha.ckers.org/xss.js"></SCRIPT>', + '<BODY onload!#$%&()*~+-_.,:;?@[/|\\]^`=alert("XSS")>', + '<SCRIPT/SRC="http://ha.ckers.org/xss.js"></SCRIPT>', + '<<SCRIPT>alert("XSS");//<</SCRIPT>', + '<SCRIPT SRC=http://ha.ckers.org/xss.js?< B >', + '<SCRIPT SRC=//ha.ckers.org/.j>', + '<IMG SRC="javascript:alert(\'XSS\')"', + '<iframe src=http://ha.ckers.org/scriptlet.html <', + "\\\";alert('XSS');//", + '<plaintext>', + '1;DROP TABLE users', + "1'; DROP TABLE users-- 1", + "' OR 1=1 -- 1", + "' OR '1'='1", + '-', + '--', + '--version', + '--help', + '$USER', + '/dev/null; touch /tmp/blns.fail ; echo', + '`touch /tmp/blns.fail`', + '$(touch /tmp/blns.fail)', + '@{[system "touch /tmp/blns.fail"]}', + 'eval("puts \'hello world\'")', + 'System("ls -al /")', + '`ls -al /`', + 'Kernel.exec("ls -al /")', + 'Kernel.exit(1)', + "%x('ls -al /')", + '<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE foo [ <!ELEMENT foo ANY ><!ENTITY xxe SYSTEM "file:///etc/passwd" >]><foo>&xxe;</foo>', + '$HOME', + "$ENV{'HOME'}", + '%d', + '%s', + '%*.*s', + '../../../../../../../../../../../etc/passwd%00', + '../../../../../../../../../../../etc/hosts', + '() { 0; }; touch /tmp/blns.shellshock1.fail;', + '() { _; } >_[$($())] { touch /tmp/blns.shellshock2.fail; }', + 'CON', + 'PRN', + 'AUX', + 'CLOCK$', + 'NUL', + 'A:', + 'ZZ:', + 'COM1', + 'LPT1', + 'LPT2', + 'LPT3', + 'COM2', + 'COM3', + 'COM4', + 'Scunthorpe General Hospital', + 'Penistone Community Church', + 'Lightwater Country Park', + 'Jimmy Clitheroe', + 'Horniman Museum', + 'shitake mushrooms', + 'RomansInSussex.co.uk', + 'http://www.cum.qc.ca/', + 'Craig Cockburn, Software Specialist', + 'Linda Callahan', + 'Dr. Herman I. Libshitz', + 'magna cum laude', + 'Super Bowl XXX', + 'medieval erection of parapets', + 'evaluate', + 'mocha', + 'expression', + 'Arsenal canal', + 'classic', + 'Tyson Gay', + "If you're reading this, you've been in a coma for almost 20 years now. We're trying a new technique. We don't know where this message will end up in your dream, but we hope it works. Please wake up, we miss you.", + 'Roses are \u001b[0;31mred\u001b[0m, violets are \u001b[0;34mblue. Hope you enjoy terminal hue', + 'But now...\u001b[20Cfor my greatest trick...\u001b[8m', + 'The quic\b\b\b\b\b\bk brown fo\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007x... [Beeeep]', + 'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗' + ], + ranges: {}, + version: 2 + } + 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() + }) + } + ) + }) + + it('should successully archive the docs', function(done) { + this.res.statusCode.should.equal(204) + return done() + }) + + 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() + }) + }) + + 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() + } + ) + }) + + 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() + } + ) + }) + + 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() + }) + }) + }) + }) + + describe('a doc with ranges', function() { + before(function(done) { + this.project_id = ObjectId() + this.doc = { + _id: ObjectId(), + lines: ['one', 'two', 'three'], + ranges: { + changes: [ + { + id: ObjectId(), + op: { i: 'foo', p: 24 }, + metadata: { + user_id: ObjectId(), + ts: new Date('2017-01-27T16:10:44.194Z') + } + }, + { + id: ObjectId(), + op: { d: 'bar', p: 50 }, + metadata: { + user_id: ObjectId(), + ts: new Date('2017-01-27T18:10:44.194Z') + } + } + ], + comments: [ + { + id: ObjectId(), + op: { c: 'comment', p: 284, t: ObjectId() }, + metadata: { + user_id: ObjectId(), + ts: new Date('2017-01-26T14:22:04.869Z') + } + } + ] + }, + version: 2 + } + 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() + }) + } + ) + }) + + it('should successully archive the docs', function(done) { + this.res.statusCode.should.equal(204) + return done() + }) + + 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() + }) + }) + + 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() + } + ) + }) + + 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() + } + ) + }) + + 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() + }) + }) + }) + }) + + describe('a doc that is archived twice', function() { + before(function(done) { + this.project_id = ObjectId() + this.doc = { + _id: ObjectId(), + lines: ['abc', 'def', 'ghi'], + ranges: {}, + version: 2 + } + 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() + } + ) + }) + } + ) + }) + + 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() + }) + }) + + 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() + } + ) + }) + + 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() + } + ) + }) + + 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() + }) + }) + }) + }) + + 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: {}, + version: 2 + } + 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, + inS3: true + }, + 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() + } + ) + } + ) + }) + }) + + 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() + }) + }) + + return it('should return the doc', function(done) { + this.fetched_docs[0].lines.should.deep.equal(this.doc.lines) + return done() + }) + }) +}) diff --git a/services/docstore/test/acceptance/js/DeletingDocsTests.js b/services/docstore/test/acceptance/js/DeletingDocsTests.js index 026730205d..8941567359 100644 --- a/services/docstore/test/acceptance/js/DeletingDocsTests.js +++ b/services/docstore/test/acceptance/js/DeletingDocsTests.js @@ -11,119 +11,149 @@ * 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"); -chai.should(); -const {db, ObjectId} = require("../../../app/js/mongojs"); -const { - expect -} = chai; -const DocstoreApp = require("./helpers/DocstoreApp"); +const sinon = require('sinon') +const chai = require('chai') +chai.should() +const { db, ObjectId } = require('../../../app/js/mongojs') +const { expect } = chai +const DocstoreApp = require('./helpers/DocstoreApp') -const DocstoreClient = require("./helpers/DocstoreClient"); +const DocstoreClient = require('./helpers/DocstoreClient') -describe("Deleting a doc", function() { - beforeEach(function(done) { - this.project_id = ObjectId(); - this.doc_id = ObjectId(); - this.lines = ["original", "lines"]; - this.version = 42; - this.ranges = []; - return DocstoreApp.ensureRunning(() => { - return DocstoreClient.createDoc(this.project_id, this.doc_id, this.lines, this.version, this.ranges, error => { - if (error != null) { throw error; } - return done(); - }); - }); - }); +describe('Deleting a doc', function() { + beforeEach(function(done) { + this.project_id = ObjectId() + this.doc_id = ObjectId() + this.lines = ['original', 'lines'] + this.version = 42 + this.ranges = [] + return DocstoreApp.ensureRunning(() => { + return DocstoreClient.createDoc( + this.project_id, + this.doc_id, + this.lines, + this.version, + this.ranges, + error => { + if (error != null) { + throw error + } + return done() + } + ) + }) + }) - describe("when the doc exists", function() { - beforeEach(function(done) { - return DocstoreClient.deleteDoc(this.project_id, this.doc_id, (error, res, doc) => { - this.res = res; - return done(); - }); - }); + describe('when the doc exists', function() { + beforeEach(function(done) { + return DocstoreClient.deleteDoc( + this.project_id, + this.doc_id, + (error, res, doc) => { + this.res = res + return done() + } + ) + }) - afterEach(function(done) { - return db.docs.remove({_id: this.doc_id}, done); - }); + afterEach(function(done) { + return db.docs.remove({ _id: this.doc_id }, done) + }) - return it("should insert a deleted doc into the docs collection", function(done) { - return db.docs.find({_id: this.doc_id}, (error, docs) => { - docs[0]._id.should.deep.equal(this.doc_id); - docs[0].lines.should.deep.equal(this.lines); - docs[0].deleted.should.equal(true); - return done(); - }); - }); - }); + return it('should insert a deleted doc into the docs collection', function(done) { + return db.docs.find({ _id: this.doc_id }, (error, docs) => { + docs[0]._id.should.deep.equal(this.doc_id) + docs[0].lines.should.deep.equal(this.lines) + docs[0].deleted.should.equal(true) + return done() + }) + }) + }) - return describe("when the doc does not exist", function() { return it("should return a 404", function(done) { - const missing_doc_id = ObjectId(); - return DocstoreClient.deleteDoc(this.project_id, missing_doc_id, (error, res, doc) => { - res.statusCode.should.equal(404); - return done(); - }); - }); }); -}); + return describe('when the doc does not exist', function() { + return it('should return a 404', function(done) { + const missing_doc_id = ObjectId() + return DocstoreClient.deleteDoc( + this.project_id, + missing_doc_id, + (error, res, doc) => { + res.statusCode.should.equal(404) + return done() + } + ) + }) + }) +}) describe("Destroying a project's documents", function() { - describe("when the doc exists", function() { - beforeEach(function(done) { - return db.docOps.insert({doc_id: ObjectId(this.doc_id), version: 1}, function(err) { - if (err != null) { return done(err); } - return DocstoreClient.destroyAllDoc(this.project_id, done); - }); - }); + describe('when the doc exists', function() { + beforeEach(function(done) { + return db.docOps.insert( + { doc_id: ObjectId(this.doc_id), version: 1 }, + function(err) { + if (err != null) { + return done(err) + } + return DocstoreClient.destroyAllDoc(this.project_id, done) + } + ) + }) - it("should remove the doc from the docs collection", function(done) { - return db.docs.find({_id: this.doc_id}, (err, docs) => { - expect(err).not.to.exist; - expect(docs).to.deep.equal([]); - return done(); - }); - }); + it('should remove the doc from the docs collection', function(done) { + return db.docs.find({ _id: this.doc_id }, (err, docs) => { + expect(err).not.to.exist + expect(docs).to.deep.equal([]) + return done() + }) + }) - return it("should remove the docOps from the docOps collection", function(done) { - return db.docOps.find({doc_id: this.doc_id}, (err, docOps) => { - expect(err).not.to.exist; - expect(docOps).to.deep.equal([]); - return done(); - }); - }); - }); + return it('should remove the docOps from the docOps collection', function(done) { + return db.docOps.find({ doc_id: this.doc_id }, (err, docOps) => { + expect(err).not.to.exist + expect(docOps).to.deep.equal([]) + return done() + }) + }) + }) - return describe("when the doc is archived", function() { - beforeEach(function(done) { - return DocstoreClient.archiveAllDoc(this.project_id, function(err) { - if (err != null) { return done(err); } - return DocstoreClient.destroyAllDoc(this.project_id, done); - }); - }); + return describe('when the doc is archived', function() { + beforeEach(function(done) { + return DocstoreClient.archiveAllDoc(this.project_id, function(err) { + if (err != null) { + return done(err) + } + return DocstoreClient.destroyAllDoc(this.project_id, done) + }) + }) - it("should remove the doc from the docs collection", function(done) { - return db.docs.find({_id: this.doc_id}, (err, docs) => { - expect(err).not.to.exist; - expect(docs).to.deep.equal([]); - return done(); - }); - }); + it('should remove the doc from the docs collection', function(done) { + return db.docs.find({ _id: this.doc_id }, (err, docs) => { + expect(err).not.to.exist + expect(docs).to.deep.equal([]) + return done() + }) + }) - it("should remove the docOps from the docOps collection", function(done) { - return db.docOps.find({doc_id: this.doc_id}, (err, docOps) => { - expect(err).not.to.exist; - expect(docOps).to.deep.equal([]); - return done(); - }); - }); + it('should remove the docOps from the docOps collection', function(done) { + return db.docOps.find({ doc_id: this.doc_id }, (err, docOps) => { + expect(err).not.to.exist + expect(docOps).to.deep.equal([]) + return done() + }) + }) - return it("should remove the doc contents from s3", function(done) { - return DocstoreClient.getS3Doc(this.project_id, this.doc_id, (error, res, s3_doc) => { - if (error != null) { throw error; } - expect(res.statusCode).to.equal(404); - return done(); - }); - }); - }); -}); + return it('should remove the doc contents from s3', function(done) { + return DocstoreClient.getS3Doc( + this.project_id, + this.doc_id, + (error, res, s3_doc) => { + if (error != null) { + throw error + } + expect(res.statusCode).to.equal(404) + return done() + } + ) + }) + }) +}) diff --git a/services/docstore/test/acceptance/js/GettingAllDocsTests.js b/services/docstore/test/acceptance/js/GettingAllDocsTests.js index 2970042480..4fc7f811d8 100644 --- a/services/docstore/test/acceptance/js/GettingAllDocsTests.js +++ b/services/docstore/test/acceptance/js/GettingAllDocsTests.js @@ -11,79 +11,104 @@ * 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"); -chai.should(); -const {ObjectId} = require("mongojs"); -const async = require("async"); -const DocstoreApp = require("./helpers/DocstoreApp"); +const sinon = require('sinon') +const chai = require('chai') +chai.should() +const { ObjectId } = require('mongojs') +const async = require('async') +const DocstoreApp = require('./helpers/DocstoreApp') -const DocstoreClient = require("./helpers/DocstoreClient"); +const DocstoreClient = require('./helpers/DocstoreClient') -describe("Getting all docs", function() { - beforeEach(function(done) { - this.project_id = ObjectId(); - this.docs = [{ - _id: ObjectId(), - lines: ["one", "two", "three"], - ranges: {"mock": "one"}, - rev: 2 - }, { - _id: ObjectId(), - lines: ["aaa", "bbb", "ccc"], - ranges: {"mock": "two"}, - rev: 4 - }, { - _id: ObjectId(), - lines: ["111", "222", "333"], - ranges: {"mock": "three"}, - rev: 6 - }]; - this.deleted_doc = { - _id: ObjectId(), - lines: ["deleted"], - ranges: {"mock": "four"}, - rev: 8 - }; - const version = 42; - const jobs = Array.from(this.docs).map((doc) => - (doc => { - return callback => { - return DocstoreClient.createDoc(this.project_id, doc._id, doc.lines, version, doc.ranges, callback); - }; - })(doc)); - jobs.push(cb => { - return DocstoreClient.createDoc(this.project_id, this.deleted_doc._id, this.deleted_doc.lines, version, this.deleted_doc.ranges, err=> { - return DocstoreClient.deleteDoc(this.project_id, this.deleted_doc._id, cb); - }); - }); - jobs.unshift(cb => DocstoreApp.ensureRunning(cb)); - return async.series(jobs, done); - }); - - it("getAllDocs should return all the (non-deleted) docs", function(done) { - return DocstoreClient.getAllDocs(this.project_id, (error, res, docs) => { - if (error != null) { throw error; } - docs.length.should.equal(this.docs.length); - for (let i = 0; i < docs.length; i++) { - const doc = docs[i]; - doc.lines.should.deep.equal(this.docs[i].lines); - } - return done(); - }); - }); - - return it("getAllRanges should return all the (non-deleted) doc ranges", function(done) { - return DocstoreClient.getAllRanges(this.project_id, (error, res, docs) => { - if (error != null) { throw error; } - docs.length.should.equal(this.docs.length); - for (let i = 0; i < docs.length; i++) { - const doc = docs[i]; - doc.ranges.should.deep.equal(this.docs[i].ranges); - } - return done(); - }); - }); -}); +describe('Getting all docs', function() { + beforeEach(function(done) { + this.project_id = ObjectId() + this.docs = [ + { + _id: ObjectId(), + lines: ['one', 'two', 'three'], + ranges: { mock: 'one' }, + rev: 2 + }, + { + _id: ObjectId(), + lines: ['aaa', 'bbb', 'ccc'], + ranges: { mock: 'two' }, + rev: 4 + }, + { + _id: ObjectId(), + lines: ['111', '222', '333'], + ranges: { mock: 'three' }, + rev: 6 + } + ] + this.deleted_doc = { + _id: ObjectId(), + lines: ['deleted'], + ranges: { mock: 'four' }, + rev: 8 + } + const version = 42 + const jobs = Array.from(this.docs).map(doc => + (doc => { + return callback => { + return DocstoreClient.createDoc( + this.project_id, + doc._id, + doc.lines, + version, + doc.ranges, + callback + ) + } + })(doc) + ) + jobs.push(cb => { + return DocstoreClient.createDoc( + this.project_id, + this.deleted_doc._id, + this.deleted_doc.lines, + version, + this.deleted_doc.ranges, + err => { + return DocstoreClient.deleteDoc( + this.project_id, + this.deleted_doc._id, + cb + ) + } + ) + }) + jobs.unshift(cb => DocstoreApp.ensureRunning(cb)) + return async.series(jobs, done) + }) + it('getAllDocs should return all the (non-deleted) docs', function(done) { + return DocstoreClient.getAllDocs(this.project_id, (error, res, docs) => { + if (error != null) { + throw error + } + docs.length.should.equal(this.docs.length) + for (let i = 0; i < docs.length; i++) { + const doc = docs[i] + doc.lines.should.deep.equal(this.docs[i].lines) + } + return done() + }) + }) + return it('getAllRanges should return all the (non-deleted) doc ranges', function(done) { + return DocstoreClient.getAllRanges(this.project_id, (error, res, docs) => { + if (error != null) { + throw error + } + docs.length.should.equal(this.docs.length) + for (let i = 0; i < docs.length; i++) { + const doc = docs[i] + doc.ranges.should.deep.equal(this.docs[i].ranges) + } + return done() + }) + }) +}) diff --git a/services/docstore/test/acceptance/js/GettingDocsTests.js b/services/docstore/test/acceptance/js/GettingDocsTests.js index e6a96d0958..fb3df8a657 100644 --- a/services/docstore/test/acceptance/js/GettingDocsTests.js +++ b/services/docstore/test/acceptance/js/GettingDocsTests.js @@ -11,80 +11,127 @@ * 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"); -chai.should(); -const {ObjectId} = require("mongojs"); -const DocstoreApp = require("./helpers/DocstoreApp"); +const sinon = require('sinon') +const chai = require('chai') +chai.should() +const { ObjectId } = require('mongojs') +const DocstoreApp = require('./helpers/DocstoreApp') -const DocstoreClient = require("./helpers/DocstoreClient"); +const DocstoreClient = require('./helpers/DocstoreClient') -describe("Getting a doc", function() { - beforeEach(function(done) { - this.project_id = ObjectId(); - this.doc_id = ObjectId(); - this.lines = ["original", "lines"]; - this.version = 42; - this.ranges = { - changes: [{ - id: ObjectId().toString(), - op: { i: "foo", p: 3 }, - meta: { - user_id: ObjectId().toString(), - ts: new Date().toString() - } - }] - }; - return DocstoreApp.ensureRunning(() => { - return DocstoreClient.createDoc(this.project_id, this.doc_id, this.lines, this.version, this.ranges, error => { - if (error != null) { throw error; } - return done(); - }); - }); - }); +describe('Getting a doc', function() { + beforeEach(function(done) { + this.project_id = ObjectId() + this.doc_id = ObjectId() + this.lines = ['original', 'lines'] + this.version = 42 + this.ranges = { + changes: [ + { + id: ObjectId().toString(), + op: { i: 'foo', p: 3 }, + meta: { + user_id: ObjectId().toString(), + ts: new Date().toString() + } + } + ] + } + return DocstoreApp.ensureRunning(() => { + return DocstoreClient.createDoc( + this.project_id, + this.doc_id, + this.lines, + this.version, + this.ranges, + error => { + if (error != null) { + throw error + } + return done() + } + ) + }) + }) - describe("when the doc exists", function() { return it("should get the doc lines and version", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.lines); - doc.version.should.equal(this.version); - doc.ranges.should.deep.equal(this.ranges); - return done(); - }); - }); }); + describe('when the doc exists', function() { + return it('should get the doc lines and version', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.lines) + doc.version.should.equal(this.version) + doc.ranges.should.deep.equal(this.ranges) + return done() + } + ) + }) + }) - describe("when the doc does not exist", function() { return it("should return a 404", function(done) { - const missing_doc_id = ObjectId(); - return DocstoreClient.getDoc(this.project_id, missing_doc_id, {}, (error, res, doc) => { - res.statusCode.should.equal(404); - return done(); - }); - }); }); + describe('when the doc does not exist', function() { + return it('should return a 404', function(done) { + const missing_doc_id = ObjectId() + return DocstoreClient.getDoc( + this.project_id, + missing_doc_id, + {}, + (error, res, doc) => { + res.statusCode.should.equal(404) + return done() + } + ) + }) + }) - return describe("when the doc is a deleted doc", function() { - beforeEach(function(done) { - this.deleted_doc_id = ObjectId(); - return DocstoreClient.createDoc(this.project_id, this.deleted_doc_id, this.lines, this.version, this.ranges, error => { - if (error != null) { throw error; } - return DocstoreClient.deleteDoc(this.project_id, this.deleted_doc_id, done); - }); - }); + return describe('when the doc is a deleted doc', function() { + beforeEach(function(done) { + this.deleted_doc_id = ObjectId() + return DocstoreClient.createDoc( + this.project_id, + this.deleted_doc_id, + this.lines, + this.version, + this.ranges, + error => { + if (error != null) { + throw error + } + return DocstoreClient.deleteDoc( + this.project_id, + this.deleted_doc_id, + done + ) + } + ) + }) - it("should return the doc", function(done) { - return DocstoreClient.getDoc(this.project_id, this.deleted_doc_id, {include_deleted:true},(error, res, doc) => { - doc.lines.should.deep.equal(this.lines); - doc.version.should.equal(this.version); - doc.ranges.should.deep.equal(this.ranges); - doc.deleted.should.equal(true); - return done(); - }); - }); + it('should return the doc', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.deleted_doc_id, + { include_deleted: true }, + (error, res, doc) => { + doc.lines.should.deep.equal(this.lines) + doc.version.should.equal(this.version) + doc.ranges.should.deep.equal(this.ranges) + doc.deleted.should.equal(true) + return done() + } + ) + }) - return it("should return a 404 when the query string is not set", function(done){ - return DocstoreClient.getDoc(this.project_id, this.deleted_doc_id, {},(error, res, doc) => { - res.statusCode.should.equal(404); - return done(); - }); - }); - }); -}); - \ No newline at end of file + return it('should return a 404 when the query string is not set', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.deleted_doc_id, + {}, + (error, res, doc) => { + res.statusCode.should.equal(404) + return done() + } + ) + }) + }) +}) diff --git a/services/docstore/test/acceptance/js/UpdatingDocsTests.js b/services/docstore/test/acceptance/js/UpdatingDocsTests.js index b3908ba2c4..96f5dfac47 100644 --- a/services/docstore/test/acceptance/js/UpdatingDocsTests.js +++ b/services/docstore/test/acceptance/js/UpdatingDocsTests.js @@ -10,329 +10,490 @@ * 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"); -chai.should(); -const {ObjectId} = require("mongojs"); -const DocstoreApp = require("./helpers/DocstoreApp"); +const sinon = require('sinon') +const chai = require('chai') +chai.should() +const { ObjectId } = require('mongojs') +const DocstoreApp = require('./helpers/DocstoreApp') -const DocstoreClient = require("./helpers/DocstoreClient"); +const DocstoreClient = require('./helpers/DocstoreClient') -describe("Applying updates to a doc", function() { - beforeEach(function(done) { - this.project_id = ObjectId(); - this.doc_id = ObjectId(); - this.originalLines = ["original", "lines"]; - this.newLines = ["new", "lines"]; - this.originalRanges = { - changes: [{ - id: ObjectId().toString(), - op: { i: "foo", p: 3 }, - meta: { - user_id: ObjectId().toString(), - ts: new Date().toString() - } - }] - }; - this.newRanges = { - changes: [{ - id: ObjectId().toString(), - op: { i: "bar", p: 6 }, - meta: { - user_id: ObjectId().toString(), - ts: new Date().toString() - } - }] - }; - this.version = 42; - return DocstoreApp.ensureRunning(() => { - return DocstoreClient.createDoc(this.project_id, this.doc_id, this.originalLines, this.version, this.originalRanges, error => { - if (error != null) { throw error; } - return done(); - }); - }); - }); +describe('Applying updates to a doc', function() { + beforeEach(function(done) { + this.project_id = ObjectId() + this.doc_id = ObjectId() + this.originalLines = ['original', 'lines'] + this.newLines = ['new', 'lines'] + this.originalRanges = { + changes: [ + { + id: ObjectId().toString(), + op: { i: 'foo', p: 3 }, + meta: { + user_id: ObjectId().toString(), + ts: new Date().toString() + } + } + ] + } + this.newRanges = { + changes: [ + { + id: ObjectId().toString(), + op: { i: 'bar', p: 6 }, + meta: { + user_id: ObjectId().toString(), + ts: new Date().toString() + } + } + ] + } + this.version = 42 + return DocstoreApp.ensureRunning(() => { + return DocstoreClient.createDoc( + this.project_id, + this.doc_id, + this.originalLines, + this.version, + this.originalRanges, + error => { + if (error != null) { + throw error + } + return done() + } + ) + }) + }) - describe("when nothing has been updated", function() { - beforeEach(function(done) { - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.originalLines, this.version, this.originalRanges, (error, res, body) => { - this.body = body; - return done(); - }); - }); + describe('when nothing has been updated', function() { + beforeEach(function(done) { + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.originalLines, + this.version, + this.originalRanges, + (error, res, body) => { + this.body = body + return done() + } + ) + }) - it("should return modified = false", function() { - return this.body.modified.should.equal(false); - }); + it('should return modified = false', function() { + return this.body.modified.should.equal(false) + }) - return it("should not update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - doc.version.should.equal(this.version); - doc.ranges.should.deep.equal(this.originalRanges); - return done(); - }); - }); - }); + return it('should not update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + doc.version.should.equal(this.version) + doc.ranges.should.deep.equal(this.originalRanges) + return done() + } + ) + }) + }) - describe("when the lines have changed", function() { - beforeEach(function(done) { - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.newLines, this.version, this.originalRanges, (error, res, body) => { - this.body = body; - return done(); - }); - }); + describe('when the lines have changed', function() { + beforeEach(function(done) { + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.newLines, + this.version, + this.originalRanges, + (error, res, body) => { + this.body = body + return done() + } + ) + }) - it("should return modified = true", function() { - return this.body.modified.should.equal(true); - }); + it('should return modified = true', function() { + return this.body.modified.should.equal(true) + }) - it("should return the rev", function() { - return this.body.rev.should.equal(2); - }); + it('should return the rev', function() { + return this.body.rev.should.equal(2) + }) - return it("should update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.newLines); - doc.version.should.equal(this.version); - doc.ranges.should.deep.equal(this.originalRanges); - return done(); - }); - }); - }); + return it('should update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.newLines) + doc.version.should.equal(this.version) + doc.ranges.should.deep.equal(this.originalRanges) + return done() + } + ) + }) + }) - describe("when the version has changed", function() { - beforeEach(function(done) { - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.originalLines, this.version + 1, this.originalRanges, (error, res, body) => { - this.body = body; - return done(); - }); - }); + describe('when the version has changed', function() { + beforeEach(function(done) { + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.originalLines, + this.version + 1, + this.originalRanges, + (error, res, body) => { + this.body = body + return done() + } + ) + }) - it("should return modified = true", function() { - return this.body.modified.should.equal(true); - }); + it('should return modified = true', function() { + return this.body.modified.should.equal(true) + }) - it("should return the rev", function() { - return this.body.rev.should.equal(1); - }); + it('should return the rev', function() { + return this.body.rev.should.equal(1) + }) - return it("should update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - doc.version.should.equal(this.version + 1); - doc.ranges.should.deep.equal(this.originalRanges); - return done(); - }); - }); - }); + return it('should update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + doc.version.should.equal(this.version + 1) + doc.ranges.should.deep.equal(this.originalRanges) + return done() + } + ) + }) + }) - describe("when the ranges have changed", function() { - beforeEach(function(done) { - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.originalLines, this.version, this.newRanges, (error, res, body) => { - this.body = body; - return done(); - }); - }); + describe('when the ranges have changed', function() { + beforeEach(function(done) { + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.originalLines, + this.version, + this.newRanges, + (error, res, body) => { + this.body = body + return done() + } + ) + }) - it("should return modified = true", function() { - return this.body.modified.should.equal(true); - }); + it('should return modified = true', function() { + return this.body.modified.should.equal(true) + }) - it("should return the rev", function() { - return this.body.rev.should.equal(2); - }); + it('should return the rev', function() { + return this.body.rev.should.equal(2) + }) - return it("should update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - doc.version.should.equal(this.version); - doc.ranges.should.deep.equal(this.newRanges); - return done(); - }); - }); - }); + return it('should update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + doc.version.should.equal(this.version) + doc.ranges.should.deep.equal(this.newRanges) + return done() + } + ) + }) + }) - describe("when the doc does not exist", function() { - beforeEach(function(done) { - this.missing_doc_id = ObjectId(); - return DocstoreClient.updateDoc(this.project_id, this.missing_doc_id, this.originalLines, 0, this.originalRanges, (error, res, body) => { - this.res = res; - this.body = body; - return done(); - }); - }); + describe('when the doc does not exist', function() { + beforeEach(function(done) { + this.missing_doc_id = ObjectId() + return DocstoreClient.updateDoc( + this.project_id, + this.missing_doc_id, + this.originalLines, + 0, + this.originalRanges, + (error, res, body) => { + this.res = res + this.body = body + return done() + } + ) + }) - it("should create the doc", function() { - return this.body.rev.should.equal(1); - }); + it('should create the doc', function() { + return this.body.rev.should.equal(1) + }) - return it("should be retreivable", function(done){ - return DocstoreClient.getDoc(this.project_id, this.missing_doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - doc.version.should.equal(0); - doc.ranges.should.deep.equal(this.originalRanges); - return done(); - }); - }); - }); + return it('should be retreivable', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.missing_doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + doc.version.should.equal(0) + doc.ranges.should.deep.equal(this.originalRanges) + return done() + } + ) + }) + }) - describe("when malformed doc lines are provided", function() { - describe("when the lines are not an array", function() { - beforeEach(function(done) { - return DocstoreClient.updateDoc(this.project_id, this.doc_id, { foo: "bar" }, this.version, this.originalRanges, (error, res, body) => { - this.res = res; - this.body = body; - return done(); - }); - }); + describe('when malformed doc lines are provided', function() { + describe('when the lines are not an array', function() { + beforeEach(function(done) { + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + { foo: 'bar' }, + this.version, + this.originalRanges, + (error, res, body) => { + this.res = res + this.body = body + return done() + } + ) + }) - it("should return 400", function() { - return this.res.statusCode.should.equal(400); - }); + it('should return 400', function() { + return this.res.statusCode.should.equal(400) + }) - return it("should not update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - return done(); - }); - }); - }); + return it('should not update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + return done() + } + ) + }) + }) - return describe("when the lines are not present", function() { - beforeEach(function(done) { - return DocstoreClient.updateDoc(this.project_id, this.doc_id, null, this.version, this.originalRanges, (error, res, body) => { - this.res = res; - this.body = body; - return done(); - }); - }); + return describe('when the lines are not present', function() { + beforeEach(function(done) { + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + null, + this.version, + this.originalRanges, + (error, res, body) => { + this.res = res + this.body = body + return done() + } + ) + }) - it("should return 400", function() { - return this.res.statusCode.should.equal(400); - }); + it('should return 400', function() { + return this.res.statusCode.should.equal(400) + }) - return it("should not update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - return done(); - }); - }); - }); - }); - - describe("when no version is provided", function() { - beforeEach(function(done) { - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.originalLines, null, this.originalRanges, (error, res, body) => { - this.res = res; - this.body = body; - return done(); - }); - }); + return it('should not update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + return done() + } + ) + }) + }) + }) - it("should return 400", function() { - return this.res.statusCode.should.equal(400); - }); + describe('when no version is provided', function() { + beforeEach(function(done) { + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.originalLines, + null, + this.originalRanges, + (error, res, body) => { + this.res = res + this.body = body + return done() + } + ) + }) - return it("should not update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - doc.version.should.equal(this.version); - return done(); - }); - }); - }); + it('should return 400', function() { + return this.res.statusCode.should.equal(400) + }) - describe("when the content is large", function() { - beforeEach(function(done) { - const line = new Array(1025).join("x"); // 1kb - this.largeLines = Array.apply(null, Array(1024)).map(() => line); // 1mb - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.largeLines, this.version, this.originalRanges, (error, res, body) => { - this.body = body; - return done(); - }); - }); + return it('should not update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + doc.version.should.equal(this.version) + return done() + } + ) + }) + }) - it("should return modified = true", function() { - return this.body.modified.should.equal(true); - }); + describe('when the content is large', function() { + beforeEach(function(done) { + const line = new Array(1025).join('x') // 1kb + this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1mb + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.largeLines, + this.version, + this.originalRanges, + (error, res, body) => { + this.body = body + return done() + } + ) + }) - return it("should update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.largeLines); - return done(); - }); - }); - }); + it('should return modified = true', function() { + return this.body.modified.should.equal(true) + }) - describe("when there is a large json payload", function() { - beforeEach(function(done) { - const line = new Array(1025).join("x"); // 1kb - this.largeLines = Array.apply(null, Array(1024)).map(() => line); // 1kb - this.originalRanges.padding = Array.apply(null, Array(2049)).map(() => line); // 2mb + 1kb - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.largeLines, this.version, this.originalRanges, (error, res, body) => { - this.res = res; - this.body = body; - return done(); - }); - }); + return it('should update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.largeLines) + return done() + } + ) + }) + }) - it("should return modified = true", function() { - return this.body.modified.should.equal(true); - }); + describe('when there is a large json payload', function() { + beforeEach(function(done) { + const line = new Array(1025).join('x') // 1kb + this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1kb + this.originalRanges.padding = Array.apply(null, Array(2049)).map( + () => line + ) // 2mb + 1kb + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.largeLines, + this.version, + this.originalRanges, + (error, res, body) => { + this.res = res + this.body = body + return done() + } + ) + }) - return it("should update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.largeLines); - return done(); - }); - }); - }); + it('should return modified = true', function() { + return this.body.modified.should.equal(true) + }) - describe("when the document body is too large", function() { - beforeEach(function(done) { - const line = new Array(1025).join("x"); // 1kb - this.largeLines = Array.apply(null, Array(2049)).map(() => line); // 2mb + 1kb - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.largeLines, this.version, this.originalRanges, (error, res, body) => { - this.res = res; - this.body = body; - return done(); - }); - }); + return it('should update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.largeLines) + return done() + } + ) + }) + }) - it("should return 413", function() { - return this.res.statusCode.should.equal(413); - }); + describe('when the document body is too large', function() { + beforeEach(function(done) { + const line = new Array(1025).join('x') // 1kb + this.largeLines = Array.apply(null, Array(2049)).map(() => line) // 2mb + 1kb + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.largeLines, + this.version, + this.originalRanges, + (error, res, body) => { + this.res = res + this.body = body + return done() + } + ) + }) - it("should report body too large", function() { - return this.res.body.should.equal('document body too large'); - }); + it('should return 413', function() { + return this.res.statusCode.should.equal(413) + }) - return it("should not update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - return done(); - }); - }); - }); + it('should report body too large', function() { + return this.res.body.should.equal('document body too large') + }) - return describe("when the json payload is too large", function() { - beforeEach(function(done) { - const line = new Array(1025).join("x"); // 1kb - this.largeLines = Array.apply(null, Array(1024)).map(() => line); // 1kb - this.originalRanges.padding = Array.apply(null, Array(4096)).map(() => line); // 4mb - return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.largeLines, this.version, this.originalRanges, (error, res, body) => { - this.res = res; - this.body = body; - return done(); - }); - }); + return it('should not update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + return done() + } + ) + }) + }) - return it("should not update the doc in the API", function(done) { - return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => { - doc.lines.should.deep.equal(this.originalLines); - return done(); - }); - }); - }); -}); + return describe('when the json payload is too large', function() { + beforeEach(function(done) { + const line = new Array(1025).join('x') // 1kb + this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1kb + this.originalRanges.padding = Array.apply(null, Array(4096)).map( + () => line + ) // 4mb + return DocstoreClient.updateDoc( + this.project_id, + this.doc_id, + this.largeLines, + this.version, + this.originalRanges, + (error, res, body) => { + this.res = res + this.body = body + return done() + } + ) + }) + + return it('should not update the doc in the API', function(done) { + return DocstoreClient.getDoc( + this.project_id, + this.doc_id, + {}, + (error, res, doc) => { + doc.lines.should.deep.equal(this.originalLines) + return done() + } + ) + }) + }) +}) diff --git a/services/docstore/test/acceptance/js/helpers/DocstoreApp.js b/services/docstore/test/acceptance/js/helpers/DocstoreApp.js index 9fd8389576..e29117bd78 100644 --- a/services/docstore/test/acceptance/js/helpers/DocstoreApp.js +++ b/services/docstore/test/acceptance/js/helpers/DocstoreApp.js @@ -11,34 +11,38 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -const app = require('../../../../app'); -require("logger-sharelatex").logger.level("error"); -const settings = require("settings-sharelatex"); +const app = require('../../../../app') +require('logger-sharelatex').logger.level('error') +const settings = require('settings-sharelatex') module.exports = { - running: false, - initing: false, - callbacks: [], - ensureRunning(callback) { - if (callback == null) { callback = function(error) {}; } - if (this.running) { - return callback(); - } else if (this.initing) { - return this.callbacks.push(callback); - } else { - this.initing = true; - this.callbacks.push(callback); - return app.listen(settings.internal.docstore.port, "localhost", error => { - if (error != null) { throw error; } - this.running = true; - return (() => { - const result = []; - for (callback of Array.from(this.callbacks)) { - result.push(callback()); - } - return result; - })(); - }); - } - } -}; \ No newline at end of file + running: false, + initing: false, + callbacks: [], + ensureRunning(callback) { + if (callback == null) { + callback = function(error) {} + } + if (this.running) { + return callback() + } else if (this.initing) { + return this.callbacks.push(callback) + } else { + this.initing = true + this.callbacks.push(callback) + return app.listen(settings.internal.docstore.port, 'localhost', error => { + if (error != null) { + throw error + } + this.running = true + return (() => { + const result = [] + for (callback of Array.from(this.callbacks)) { + result.push(callback()) + } + return result + })() + }) + } + } +} diff --git a/services/docstore/test/acceptance/js/helpers/DocstoreClient.js b/services/docstore/test/acceptance/js/helpers/DocstoreClient.js index 129723a9ea..da91433880 100644 --- a/services/docstore/test/acceptance/js/helpers/DocstoreClient.js +++ b/services/docstore/test/acceptance/js/helpers/DocstoreClient.js @@ -11,81 +11,126 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -let DocstoreClient; -const request = require("request").defaults({jar: false}); -const {db, ObjectId} = require("../../../../app/js/mongojs"); -const settings = require("settings-sharelatex"); -const DocArchiveManager = require("../../../../app/js/DocArchiveManager.js"); +let DocstoreClient +const request = require('request').defaults({ jar: false }) +const { db, ObjectId } = require('../../../../app/js/mongojs') +const settings = require('settings-sharelatex') +const DocArchiveManager = require('../../../../app/js/DocArchiveManager.js') -module.exports = (DocstoreClient = { +module.exports = DocstoreClient = { + createDoc(project_id, doc_id, lines, version, ranges, callback) { + if (callback == null) { + callback = function(error) {} + } + return DocstoreClient.updateDoc( + project_id, + doc_id, + lines, + version, + ranges, + callback + ) + }, - createDoc(project_id, doc_id, lines, version, ranges, callback) { - if (callback == null) { callback = function(error) {}; } - return DocstoreClient.updateDoc(project_id, doc_id, lines, version, ranges, callback); - }, + getDoc(project_id, doc_id, qs, callback) { + if (callback == null) { + callback = function(error, res, body) {} + } + return request.get( + { + url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`, + json: true, + qs + }, + callback + ) + }, - getDoc(project_id, doc_id, qs, callback) { - if (callback == null) { callback = function(error, res, body) {}; } - return request.get({ - url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`, - json: true, - qs - }, callback); - }, + getAllDocs(project_id, callback) { + if (callback == null) { + callback = function(error, res, body) {} + } + return request.get( + { + url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`, + json: true + }, + callback + ) + }, - getAllDocs(project_id, callback) { - if (callback == null) { callback = function(error, res, body) {}; } - return request.get({ - url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`, - json: true - }, callback); - }, + getAllRanges(project_id, callback) { + if (callback == null) { + callback = function(error, res, body) {} + } + return request.get( + { + url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`, + json: true + }, + callback + ) + }, - getAllRanges(project_id, callback) { - if (callback == null) { callback = function(error, res, body) {}; } - return request.get({ - url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`, - json: true - }, callback); - }, + updateDoc(project_id, doc_id, lines, version, ranges, callback) { + if (callback == null) { + callback = function(error, res, body) {} + } + return request.post( + { + url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`, + json: { + lines, + version, + ranges + } + }, + callback + ) + }, - updateDoc(project_id, doc_id, lines, version, ranges, callback) { - if (callback == null) { callback = function(error, res, body) {}; } - return request.post({ - url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`, - json: { - lines, - version, - ranges - } - }, callback); - }, + deleteDoc(project_id, doc_id, callback) { + if (callback == null) { + callback = function(error, res, body) {} + } + return request.del( + { + url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}` + }, + callback + ) + }, - deleteDoc(project_id, doc_id, callback) { - if (callback == null) { callback = function(error, res, body) {}; } - return request.del({ - url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}` - }, callback); - }, - - archiveAllDoc(project_id, callback) { - if (callback == null) { callback = function(error, res, body) {}; } - return request.post({ - url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive` - }, callback); - }, + archiveAllDoc(project_id, callback) { + if (callback == null) { + callback = function(error, res, body) {} + } + return request.post( + { + url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive` + }, + callback + ) + }, - destroyAllDoc(project_id, callback) { - if (callback == null) { callback = function(error, res, body) {}; } - return request.post({ - url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy` - }, callback); - }, + destroyAllDoc(project_id, callback) { + if (callback == null) { + callback = function(error, res, body) {} + } + return request.post( + { + url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy` + }, + callback + ) + }, - getS3Doc(project_id, doc_id, callback) { - if (callback == null) { callback = function(error, res, body) {}; } - const options = DocArchiveManager.buildS3Options(project_id+"/"+doc_id); - options.json = true; - return request.get(options, callback); - } -}); + getS3Doc(project_id, doc_id, callback) { + if (callback == null) { + callback = function(error, res, body) {} + } + const options = DocArchiveManager.buildS3Options(project_id + '/' + doc_id) + options.json = true + return request.get(options, callback) + } +}