ArchiveDocsTests.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. /* eslint-disable
  2. camelcase,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS101: Remove unnecessary use of Array.from
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const Settings = require('@overleaf/settings')
  15. const { expect } = require('chai')
  16. const { db, ObjectId } = require('../../../app/js/mongodb')
  17. const async = require('async')
  18. const DocstoreApp = require('./helpers/DocstoreApp')
  19. const DocstoreClient = require('./helpers/DocstoreClient')
  20. const { Storage } = require('@google-cloud/storage')
  21. const Persistor = require('../../../app/js/PersistorManager')
  22. const Streamifier = require('streamifier')
  23. function uploadContent(path, json, callback) {
  24. const stream = Streamifier.createReadStream(JSON.stringify(json))
  25. Persistor.sendStream(Settings.docstore.bucket, path, stream)
  26. .then(() => callback())
  27. .catch(callback)
  28. }
  29. describe('Archiving', function () {
  30. before(function (done) {
  31. return DocstoreApp.ensureRunning(done)
  32. })
  33. before(async function () {
  34. const storage = new Storage(Settings.docstore.gcs.endpoint)
  35. await storage.createBucket(Settings.docstore.bucket)
  36. await storage.createBucket(`${Settings.docstore.bucket}-deleted`)
  37. })
  38. describe('multiple docs in a project', function () {
  39. before(function (done) {
  40. this.project_id = ObjectId()
  41. this.docs = [
  42. {
  43. _id: ObjectId(),
  44. lines: ['one', 'two', 'three'],
  45. ranges: {},
  46. version: 2,
  47. },
  48. {
  49. _id: ObjectId(),
  50. lines: ['aaa', 'bbb', 'ccc'],
  51. ranges: {},
  52. version: 4,
  53. },
  54. ]
  55. const jobs = Array.from(this.docs).map(doc =>
  56. (doc => {
  57. return callback => {
  58. return DocstoreClient.createDoc(
  59. this.project_id,
  60. doc._id,
  61. doc.lines,
  62. doc.version,
  63. doc.ranges,
  64. callback
  65. )
  66. }
  67. })(doc)
  68. )
  69. return async.series(jobs, error => {
  70. if (error != null) {
  71. throw error
  72. }
  73. return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
  74. if (error) return done(error)
  75. this.res = res
  76. return done()
  77. })
  78. })
  79. })
  80. it('should archive all the docs', function (done) {
  81. this.res.statusCode.should.equal(204)
  82. return done()
  83. })
  84. it('should set inS3 and unset lines and ranges in each doc', function (done) {
  85. const jobs = Array.from(this.docs).map(doc =>
  86. (doc => {
  87. return callback => {
  88. return db.docs.findOne({ _id: doc._id }, (error, doc) => {
  89. if (error) return callback(error)
  90. expect(doc.lines).not.to.exist
  91. expect(doc.ranges).not.to.exist
  92. doc.inS3.should.equal(true)
  93. return callback()
  94. })
  95. }
  96. })(doc)
  97. )
  98. return async.series(jobs, done)
  99. })
  100. it('should set the docs in s3 correctly', function (done) {
  101. const jobs = Array.from(this.docs).map(doc =>
  102. (doc => {
  103. return callback => {
  104. return DocstoreClient.getS3Doc(
  105. this.project_id,
  106. doc._id,
  107. (error, s3_doc) => {
  108. if (error) return callback(error)
  109. s3_doc.lines.should.deep.equal(doc.lines)
  110. s3_doc.ranges.should.deep.equal(doc.ranges)
  111. callback()
  112. }
  113. )
  114. }
  115. })(doc)
  116. )
  117. return async.series(jobs, done)
  118. })
  119. return describe('after unarchiving from a request for the project', function () {
  120. before(function (done) {
  121. return DocstoreClient.getAllDocs(
  122. this.project_id,
  123. (error, res, fetched_docs) => {
  124. this.fetched_docs = fetched_docs
  125. if (error != null) {
  126. throw error
  127. }
  128. return done()
  129. }
  130. )
  131. })
  132. it('should return the docs', function (done) {
  133. for (let i = 0; i < this.fetched_docs.length; i++) {
  134. const doc = this.fetched_docs[i]
  135. doc.lines.should.deep.equal(this.docs[i].lines)
  136. }
  137. return done()
  138. })
  139. return it('should restore the docs to mongo', function (done) {
  140. const jobs = Array.from(this.docs).map((doc, i) =>
  141. ((doc, i) => {
  142. return callback => {
  143. return db.docs.findOne({ _id: doc._id }, (error, doc) => {
  144. if (error) return callback(error)
  145. doc.lines.should.deep.equal(this.docs[i].lines)
  146. doc.ranges.should.deep.equal(this.docs[i].ranges)
  147. expect(doc.inS3).not.to.exist
  148. return callback()
  149. })
  150. }
  151. })(doc, i)
  152. )
  153. return async.series(jobs, done)
  154. })
  155. })
  156. })
  157. describe('a deleted doc', function () {
  158. beforeEach(function (done) {
  159. this.project_id = ObjectId()
  160. this.doc = {
  161. _id: ObjectId(),
  162. lines: ['one', 'two', 'three'],
  163. ranges: {},
  164. version: 2,
  165. }
  166. return DocstoreClient.createDoc(
  167. this.project_id,
  168. this.doc._id,
  169. this.doc.lines,
  170. this.doc.version,
  171. this.doc.ranges,
  172. error => {
  173. if (error != null) {
  174. throw error
  175. }
  176. return DocstoreClient.deleteDoc(
  177. this.project_id,
  178. this.doc._id,
  179. error => {
  180. if (error != null) {
  181. throw error
  182. }
  183. return DocstoreClient.archiveAllDoc(
  184. this.project_id,
  185. (error, res) => {
  186. this.res = res
  187. if (error != null) {
  188. throw error
  189. }
  190. return done()
  191. }
  192. )
  193. }
  194. )
  195. }
  196. )
  197. })
  198. it('should successully archive the docs', function (done) {
  199. this.res.statusCode.should.equal(204)
  200. return done()
  201. })
  202. it('should set inS3 and unset lines and ranges in each doc', function (done) {
  203. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  204. if (error != null) {
  205. throw error
  206. }
  207. expect(doc.lines).not.to.exist
  208. expect(doc.ranges).not.to.exist
  209. doc.inS3.should.equal(true)
  210. doc.deleted.should.equal(true)
  211. return done()
  212. })
  213. })
  214. it('should set the doc in s3 correctly', function (done) {
  215. return DocstoreClient.getS3Doc(
  216. this.project_id,
  217. this.doc._id,
  218. (error, s3_doc) => {
  219. if (error != null) {
  220. throw error
  221. }
  222. s3_doc.lines.should.deep.equal(this.doc.lines)
  223. s3_doc.ranges.should.deep.equal(this.doc.ranges)
  224. return done()
  225. }
  226. )
  227. })
  228. describe('after unarchiving from a request for the project', function () {
  229. beforeEach(function (done) {
  230. return DocstoreClient.getAllDocs(
  231. this.project_id,
  232. (error, res, fetched_docs) => {
  233. this.fetched_docs = fetched_docs
  234. if (error != null) {
  235. throw error
  236. }
  237. return done()
  238. }
  239. )
  240. })
  241. it('should not included the deleted', function (done) {
  242. this.fetched_docs.length.should.equal(0)
  243. return done()
  244. })
  245. return it('should restore the doc to mongo', function (done) {
  246. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  247. if (error != null) {
  248. throw error
  249. }
  250. doc.lines.should.deep.equal(this.doc.lines)
  251. doc.ranges.should.deep.equal(this.doc.ranges)
  252. expect(doc.inS3).not.to.exist
  253. doc.deleted.should.equal(true)
  254. return done()
  255. })
  256. })
  257. })
  258. describe('when keepSoftDeletedDocsArchived is enabled', function () {
  259. let keepSoftDeletedDocsArchived
  260. beforeEach(function overwriteSetting() {
  261. keepSoftDeletedDocsArchived =
  262. Settings.docstore.keepSoftDeletedDocsArchived
  263. Settings.docstore.keepSoftDeletedDocsArchived = true
  264. })
  265. afterEach(function restoreSetting() {
  266. Settings.docstore.keepSoftDeletedDocsArchived =
  267. keepSoftDeletedDocsArchived
  268. })
  269. describe('after unarchiving from a request for the project', function () {
  270. beforeEach(function (done) {
  271. DocstoreClient.getAllDocs(
  272. this.project_id,
  273. (error, res, fetched_docs) => {
  274. this.fetched_docs = fetched_docs
  275. if (error) {
  276. return done(error)
  277. }
  278. done()
  279. }
  280. )
  281. })
  282. it('should not included the deleted', function (done) {
  283. this.fetched_docs.length.should.equal(0)
  284. done()
  285. })
  286. it('should not have restored the deleted doc to mongo', function (done) {
  287. db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  288. if (error) {
  289. return done(error)
  290. }
  291. expect(doc.lines).to.not.exist
  292. expect(doc.ranges).to.not.exist
  293. expect(doc.inS3).to.equal(true)
  294. expect(doc.deleted).to.equal(true)
  295. done()
  296. })
  297. })
  298. })
  299. })
  300. })
  301. describe('archiving a single doc', function () {
  302. before(function (done) {
  303. this.project_id = ObjectId()
  304. this.timeout(1000 * 30)
  305. this.doc = {
  306. _id: ObjectId(),
  307. lines: ['foo', 'bar'],
  308. ranges: {},
  309. version: 2,
  310. }
  311. DocstoreClient.createDoc(
  312. this.project_id,
  313. this.doc._id,
  314. this.doc.lines,
  315. this.doc.version,
  316. this.doc.ranges,
  317. error => {
  318. if (error) {
  319. return done(error)
  320. }
  321. DocstoreClient.archiveDocById(
  322. this.project_id,
  323. this.doc._id,
  324. (error, res) => {
  325. this.res = res
  326. if (error) {
  327. return done(error)
  328. }
  329. done()
  330. }
  331. )
  332. }
  333. )
  334. })
  335. it('should successully archive the doc', function (done) {
  336. this.res.statusCode.should.equal(204)
  337. done()
  338. })
  339. it('should set inS3 and unset lines and ranges in the doc', function (done) {
  340. db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  341. if (error) {
  342. return done(error)
  343. }
  344. expect(doc.lines).not.to.exist
  345. expect(doc.ranges).not.to.exist
  346. doc.inS3.should.equal(true)
  347. done()
  348. })
  349. })
  350. it('should set the doc in s3 correctly', function (done) {
  351. DocstoreClient.getS3Doc(
  352. this.project_id,
  353. this.doc._id,
  354. (error, s3_doc) => {
  355. if (error) {
  356. return done(error)
  357. }
  358. s3_doc.lines.should.deep.equal(this.doc.lines)
  359. s3_doc.ranges.should.deep.equal(this.doc.ranges)
  360. done()
  361. }
  362. )
  363. })
  364. })
  365. describe('a doc with large lines', function () {
  366. before(function (done) {
  367. this.project_id = ObjectId()
  368. this.timeout(1000 * 30)
  369. const quarterMegInBytes = 250000
  370. const big_line = require('crypto')
  371. .randomBytes(quarterMegInBytes)
  372. .toString('hex')
  373. this.doc = {
  374. _id: ObjectId(),
  375. lines: [big_line, big_line, big_line, big_line],
  376. ranges: {},
  377. version: 2,
  378. }
  379. return DocstoreClient.createDoc(
  380. this.project_id,
  381. this.doc._id,
  382. this.doc.lines,
  383. this.doc.version,
  384. this.doc.ranges,
  385. error => {
  386. if (error != null) {
  387. throw error
  388. }
  389. return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
  390. this.res = res
  391. if (error != null) {
  392. throw error
  393. }
  394. return done()
  395. })
  396. }
  397. )
  398. })
  399. it('should successully archive the docs', function (done) {
  400. this.res.statusCode.should.equal(204)
  401. return done()
  402. })
  403. it('should set inS3 and unset lines and ranges in each doc', function (done) {
  404. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  405. if (error != null) {
  406. throw error
  407. }
  408. expect(doc.lines).not.to.exist
  409. expect(doc.ranges).not.to.exist
  410. doc.inS3.should.equal(true)
  411. return done()
  412. })
  413. })
  414. it('should set the doc in s3 correctly', function (done) {
  415. return DocstoreClient.getS3Doc(
  416. this.project_id,
  417. this.doc._id,
  418. (error, s3_doc) => {
  419. if (error != null) {
  420. throw error
  421. }
  422. s3_doc.lines.should.deep.equal(this.doc.lines)
  423. s3_doc.ranges.should.deep.equal(this.doc.ranges)
  424. return done()
  425. }
  426. )
  427. })
  428. return describe('after unarchiving from a request for the project', function () {
  429. before(function (done) {
  430. return DocstoreClient.getAllDocs(
  431. this.project_id,
  432. (error, res, fetched_docs) => {
  433. this.fetched_docs = fetched_docs
  434. if (error != null) {
  435. throw error
  436. }
  437. return done()
  438. }
  439. )
  440. })
  441. return it('should restore the doc to mongo', function (done) {
  442. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  443. if (error != null) {
  444. throw error
  445. }
  446. doc.lines.should.deep.equal(this.doc.lines)
  447. doc.ranges.should.deep.equal(this.doc.ranges)
  448. expect(doc.inS3).not.to.exist
  449. return done()
  450. })
  451. })
  452. })
  453. })
  454. describe('a doc with naughty strings', function () {
  455. before(function (done) {
  456. this.project_id = ObjectId()
  457. this.doc = {
  458. _id: ObjectId(),
  459. lines: [
  460. '',
  461. 'undefined',
  462. 'undef',
  463. 'null',
  464. 'NULL',
  465. '(null)',
  466. 'nil',
  467. 'NIL',
  468. 'true',
  469. 'false',
  470. 'True',
  471. 'False',
  472. 'None',
  473. '\\',
  474. '\\\\',
  475. '0',
  476. '1',
  477. '1.00',
  478. '$1.00',
  479. '1/2',
  480. '1E2',
  481. '1E02',
  482. '1E+02',
  483. '-1',
  484. '-1.00',
  485. '-$1.00',
  486. '-1/2',
  487. '-1E2',
  488. '-1E02',
  489. '-1E+02',
  490. '1/0',
  491. '0/0',
  492. '-2147483648/-1',
  493. '-9223372036854775808/-1',
  494. '0.00',
  495. '0..0',
  496. '.',
  497. '0.0.0',
  498. '0,00',
  499. '0,,0',
  500. ',',
  501. '0,0,0',
  502. '0.0/0',
  503. '1.0/0.0',
  504. '0.0/0.0',
  505. '1,0/0,0',
  506. '0,0/0,0',
  507. '--1',
  508. '-',
  509. '-.',
  510. '-,',
  511. '999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999',
  512. 'NaN',
  513. 'Infinity',
  514. '-Infinity',
  515. '0x0',
  516. '0xffffffff',
  517. '0xffffffffffffffff',
  518. '0xabad1dea',
  519. '123456789012345678901234567890123456789',
  520. '1,000.00',
  521. '1 000.00',
  522. "1'000.00",
  523. '1,000,000.00',
  524. '1 000 000.00',
  525. "1'000'000.00",
  526. '1.000,00',
  527. '1 000,00',
  528. "1'000,00",
  529. '1.000.000,00',
  530. '1 000i̳̞v̢͇ḙ͎͟-҉̭̩̼͔m̤̭̫i͕͇̝̦n̗͙ḍ̟ ̯̲͕͞ǫ̟̯̰̲͙̻̝f ̪̰̰̗̖̭̘͘c̦͍̲̞͍̩̙ḥ͚a̮͎̟̙͜ơ̩̹͎s̤.̝̝ ҉Z̡̖̜͖̰̣͉̜a͖̰͙̬͡l̲̫̳͍̩g̡̟̼̱͚̞̬ͅo̗͜.̟',
  531. '̦H̬̤̗̤͝e͜ ̜̥̝̻͍̟́w̕h̖̯͓o̝͙̖͎̱̮ ҉̺̙̞̟͈W̷̼̭a̺̪͍į͈͕̭͙̯̜t̶̼̮s̘͙͖̕ ̠̫̠B̻͍͙͉̳ͅe̵h̵̬͇̫͙i̹͓̳̳̮͎̫̕n͟d̴̪̜̖ ̰͉̩͇͙̲͞ͅT͖̼͓̪͢h͏͓̮̻e̬̝̟ͅ ̤̹̝W͙̞̝͔͇͝ͅa͏͓͔̹̼̣l̴͔̰̤̟͔ḽ̫.͕',
  532. 'Z̮̞̠͙͔ͅḀ̗̞͈̻̗Ḷ͙͎̯̹̞͓G̻O̭̗̮',
  533. "˙ɐ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˥",
  534. '00˙Ɩ$-',
  535. 'The quick brown fox jumps over the lazy dog',
  536. '𝐓𝐡𝐞 𝐪𝐮𝐢𝐜𝐤 𝐛𝐫𝐨𝐰𝐧 𝐟𝐨𝐱 𝐣𝐮𝐦𝐩𝐬 𝐨𝐯𝐞𝐫 𝐭𝐡𝐞 𝐥𝐚𝐳𝐲 𝐝𝐨𝐠',
  537. '𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐 𝖇𝖗𝖔𝖜𝖓 𝖋𝖔𝖝 𝖏𝖚𝖒𝖕𝖘 𝖔𝖛𝖊𝖗 𝖙𝖍𝖊 𝖑𝖆𝖟𝖞 𝖉𝖔𝖌',
  538. '𝑻𝒉𝒆 𝒒𝒖𝒊𝒄𝒌 𝒃𝒓𝒐𝒘𝒏 𝒇𝒐𝒙 𝒋𝒖𝒎𝒑𝒔 𝒐𝒗𝒆𝒓 𝒕𝒉𝒆 𝒍𝒂𝒛𝒚 𝒅𝒐𝒈',
  539. '𝓣𝓱𝓮 𝓺𝓾𝓲𝓬𝓴 𝓫𝓻𝓸𝔀𝓷 𝓯𝓸𝔁 𝓳𝓾𝓶𝓹𝓼 𝓸𝓿𝓮𝓻 𝓽𝓱𝓮 𝓵𝓪𝔃𝔂 𝓭𝓸𝓰',
  540. '𝕋𝕙𝕖 𝕢𝕦𝕚𝕔𝕜 𝕓𝕣𝕠𝕨𝕟 𝕗𝕠𝕩 𝕛𝕦𝕞𝕡𝕤 𝕠𝕧𝕖𝕣 𝕥𝕙𝕖 𝕝𝕒𝕫𝕪 𝕕𝕠𝕘',
  541. '𝚃𝚑𝚎 𝚚𝚞𝚒𝚌𝚔 𝚋𝚛𝚘𝚠𝚗 𝚏𝚘𝚡 𝚓𝚞𝚖𝚙𝚜 𝚘𝚟𝚎𝚛 𝚝𝚑𝚎 𝚕𝚊𝚣𝚢 𝚍𝚘𝚐',
  542. '⒯⒣⒠ ⒬⒰⒤⒞⒦ ⒝⒭⒪⒲⒩ ⒡⒪⒳ ⒥⒰⒨⒫⒮ ⒪⒱⒠⒭ ⒯⒣⒠ ⒧⒜⒵⒴ ⒟⒪⒢',
  543. '<script>alert(123)</script>',
  544. '&lt;script&gt;alert(&#39;123&#39;);&lt;/script&gt;',
  545. '<img src=x onerror=alert(123) />',
  546. '<svg><script>123<1>alert(123)</script> ',
  547. '"><script>alert(123)</script>',
  548. "'><script>alert(123)</script>",
  549. '><script>alert(123)</script>',
  550. '</script><script>alert(123)</script>',
  551. '< / script >< script >alert(123)< / script >',
  552. ' onfocus=JaVaSCript:alert(123) autofocus ',
  553. '" onfocus=JaVaSCript:alert(123) autofocus ',
  554. "' onfocus=JaVaSCript:alert(123) autofocus ",
  555. '<script>alert(123)</script>',
  556. '<sc<script>ript>alert(123)</sc</script>ript>',
  557. '--><script>alert(123)</script>',
  558. '";alert(123);t="',
  559. "';alert(123);t='",
  560. 'JavaSCript:alert(123)',
  561. ';alert(123);',
  562. 'src=JaVaSCript:prompt(132)',
  563. '"><script>alert(123);</script x="',
  564. "'><script>alert(123);</script x='",
  565. '><script>alert(123);</script x=',
  566. '" autofocus onkeyup="javascript:alert(123)',
  567. "' autofocus onkeyup='javascript:alert(123)",
  568. '<script\\x20type="text/javascript">javascript:alert(1);</script>',
  569. '<script\\x3Etype="text/javascript">javascript:alert(1);</script>',
  570. '<script\\x0Dtype="text/javascript">javascript:alert(1);</script>',
  571. '<script\\x09type="text/javascript">javascript:alert(1);</script>',
  572. '<script\\x0Ctype="text/javascript">javascript:alert(1);</script>',
  573. '<script\\x2Ftype="text/javascript">javascript:alert(1);</script>',
  574. '<script\\x0Atype="text/javascript">javascript:alert(1);</script>',
  575. '\'`"><\\x3Cscript>javascript:alert(1)</script> ',
  576. '\'`"><\\x00script>javascript:alert(1)</script>',
  577. 'ABC<div style="x\\x3Aexpression(javascript:alert(1)">DEF',
  578. 'ABC<div style="x:expression\\x5C(javascript:alert(1)">DEF',
  579. 'ABC<div style="x:expression\\x00(javascript:alert(1)">DEF',
  580. 'ABC<div style="x:exp\\x00ression(javascript:alert(1)">DEF',
  581. 'ABC<div style="x:exp\\x5Cression(javascript:alert(1)">DEF',
  582. 'ABC<div style="x:\\x0Aexpression(javascript:alert(1)">DEF',
  583. 'ABC<div style="x:\\x09expression(javascript:alert(1)">DEF',
  584. 'ABC<div style="x:\\xE3\\x80\\x80expression(javascript:alert(1)">DEF',
  585. 'ABC<div style="x:\\xE2\\x80\\x84expression(javascript:alert(1)">DEF',
  586. 'ABC<div style="x:\\xC2\\xA0expression(javascript:alert(1)">DEF',
  587. 'ABC<div style="x:\\xE2\\x80\\x80expression(javascript:alert(1)">DEF',
  588. 'ABC<div style="x:\\xE2\\x80\\x8Aexpression(javascript:alert(1)">DEF',
  589. 'ABC<div style="x:\\x0Dexpression(javascript:alert(1)">DEF',
  590. 'ABC<div style="x:\\x0Cexpression(javascript:alert(1)">DEF',
  591. 'ABC<div style="x:\\xE2\\x80\\x87expression(javascript:alert(1)">DEF',
  592. 'ABC<div style="x:\\xEF\\xBB\\xBFexpression(javascript:alert(1)">DEF',
  593. 'ABC<div style="x:\\x20expression(javascript:alert(1)">DEF',
  594. 'ABC<div style="x:\\xE2\\x80\\x88expression(javascript:alert(1)">DEF',
  595. 'ABC<div style="x:\\x00expression(javascript:alert(1)">DEF',
  596. 'ABC<div style="x:\\xE2\\x80\\x8Bexpression(javascript:alert(1)">DEF',
  597. 'ABC<div style="x:\\xE2\\x80\\x86expression(javascript:alert(1)">DEF',
  598. 'ABC<div style="x:\\xE2\\x80\\x85expression(javascript:alert(1)">DEF',
  599. 'ABC<div style="x:\\xE2\\x80\\x82expression(javascript:alert(1)">DEF',
  600. 'ABC<div style="x:\\x0Bexpression(javascript:alert(1)">DEF',
  601. 'ABC<div style="x:\\xE2\\x80\\x81expression(javascript:alert(1)">DEF',
  602. 'ABC<div style="x:\\xE2\\x80\\x83expression(javascript:alert(1)">DEF',
  603. 'ABC<div style="x:\\xE2\\x80\\x89expression(javascript:alert(1)">DEF',
  604. '<a href="\\x0Bjavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  605. '<a href="\\x0Fjavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  606. '<a href="\\xC2\\xA0javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  607. '<a href="\\x05javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  608. '<a href="\\xE1\\xA0\\x8Ejavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  609. '<a href="\\x18javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  610. '<a href="\\x11javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  611. '<a href="\\xE2\\x80\\x88javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  612. '<a href="\\xE2\\x80\\x89javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  613. '<a href="\\xE2\\x80\\x80javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  614. '<a href="\\x17javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  615. '<a href="\\x03javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  616. '<a href="\\x0Ejavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  617. '<a href="\\x1Ajavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  618. '<a href="\\x00javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  619. '<a href="\\x10javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  620. '<a href="\\xE2\\x80\\x82javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  621. '<a href="\\x20javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  622. '<a href="\\x13javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  623. '<a href="\\x09javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  624. '<a href="\\xE2\\x80\\x8Ajavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  625. '<a href="\\x14javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  626. '<a href="\\x19javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  627. '<a href="\\xE2\\x80\\xAFjavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  628. '<a href="\\x1Fjavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  629. '<a href="\\xE2\\x80\\x81javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  630. '<a href="\\x1Djavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  631. '<a href="\\xE2\\x80\\x87javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  632. '<a href="\\x07javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  633. '<a href="\\xE1\\x9A\\x80javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  634. '<a href="\\xE2\\x80\\x83javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  635. '<a href="\\x04javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  636. '<a href="\\x01javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  637. '<a href="\\x08javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  638. '<a href="\\xE2\\x80\\x84javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  639. '<a href="\\xE2\\x80\\x86javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  640. '<a href="\\xE3\\x80\\x80javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  641. '<a href="\\x12javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  642. '<a href="\\x0Djavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  643. '<a href="\\x0Ajavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  644. '<a href="\\x0Cjavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  645. '<a href="\\x15javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  646. '<a href="\\xE2\\x80\\xA8javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  647. '<a href="\\x16javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  648. '<a href="\\x02javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  649. '<a href="\\x1Bjavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  650. '<a href="\\x06javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  651. '<a href="\\xE2\\x80\\xA9javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  652. '<a href="\\xE2\\x80\\x85javascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  653. '<a href="\\x1Ejavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  654. '<a href="\\xE2\\x81\\x9Fjavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  655. '<a href="\\x1Cjavascript:javascript:alert(1)" id="fuzzelement1">test</a>',
  656. '<a href="javascript\\x00:javascript:alert(1)" id="fuzzelement1">test</a>',
  657. '<a href="javascript\\x3A:javascript:alert(1)" id="fuzzelement1">test</a>',
  658. '<a href="javascript\\x09:javascript:alert(1)" id="fuzzelement1">test</a>',
  659. '<a href="javascript\\x0D:javascript:alert(1)" id="fuzzelement1">test</a>',
  660. '<a href="javascript\\x0A:javascript:alert(1)" id="fuzzelement1">test</a>',
  661. '`"\'><img src=xxx:x \\x0Aonerror=javascript:alert(1)>',
  662. '`"\'><img src=xxx:x \\x22onerror=javascript:alert(1)>',
  663. '`"\'><img src=xxx:x \\x0Bonerror=javascript:alert(1)>',
  664. '`"\'><img src=xxx:x \\x0Donerror=javascript:alert(1)>',
  665. '`"\'><img src=xxx:x \\x2Fonerror=javascript:alert(1)>',
  666. '`"\'><img src=xxx:x \\x09onerror=javascript:alert(1)>',
  667. '`"\'><img src=xxx:x \\x0Conerror=javascript:alert(1)>',
  668. '`"\'><img src=xxx:x \\x00onerror=javascript:alert(1)>',
  669. '`"\'><img src=xxx:x \\x27onerror=javascript:alert(1)>',
  670. '`"\'><img src=xxx:x \\x20onerror=javascript:alert(1)>',
  671. '"`\'><script>\\x3Bjavascript:alert(1)</script>',
  672. '"`\'><script>\\x0Djavascript:alert(1)</script>',
  673. '"`\'><script>\\xEF\\xBB\\xBFjavascript:alert(1)</script>',
  674. '"`\'><script>\\xE2\\x80\\x81javascript:alert(1)</script>',
  675. '"`\'><script>\\xE2\\x80\\x84javascript:alert(1)</script>',
  676. '"`\'><script>\\xE3\\x80\\x80javascript:alert(1)</script>',
  677. '"`\'><script>\\x09javascript:alert(1)</script>',
  678. '"`\'><script>\\xE2\\x80\\x89javascript:alert(1)</script>',
  679. '"`\'><script>\\xE2\\x80\\x85javascript:alert(1)</script>',
  680. '"`\'><script>\\xE2\\x80\\x88javascript:alert(1)</script>',
  681. '"`\'><script>\\x00javascript:alert(1)</script>',
  682. '"`\'><script>\\xE2\\x80\\xA8javascript:alert(1)</script>',
  683. '"`\'><script>\\xE2\\x80\\x8Ajavascript:alert(1)</script>',
  684. '"`\'><script>\\xE1\\x9A\\x80javascript:alert(1)</script>',
  685. '"`\'><script>\\x0Cjavascript:alert(1)</script>',
  686. '"`\'><script>\\x2Bjavascript:alert(1)</script>',
  687. '"`\'><script>\\xF0\\x90\\x96\\x9Ajavascript:alert(1)</script>',
  688. '"`\'><script>-javascript:alert(1)</script>',
  689. '"`\'><script>\\x0Ajavascript:alert(1)</script>',
  690. '"`\'><script>\\xE2\\x80\\xAFjavascript:alert(1)</script>',
  691. '"`\'><script>\\x7Ejavascript:alert(1)</script>',
  692. '"`\'><script>\\xE2\\x80\\x87javascript:alert(1)</script>',
  693. '"`\'><script>\\xE2\\x81\\x9Fjavascript:alert(1)</script>',
  694. '"`\'><script>\\xE2\\x80\\xA9javascript:alert(1)</script>',
  695. '"`\'><script>\\xC2\\x85javascript:alert(1)</script>',
  696. '"`\'><script>\\xEF\\xBF\\xAEjavascript:alert(1)</script>',
  697. '"`\'><script>\\xE2\\x80\\x83javascript:alert(1)</script>',
  698. '"`\'><script>\\xE2\\x80\\x8Bjavascript:alert(1)</script>',
  699. '"`\'><script>\\xEF\\xBF\\xBEjavascript:alert(1)</script>',
  700. '"`\'><script>\\xE2\\x80\\x80javascript:alert(1)</script>',
  701. '"`\'><script>\\x21javascript:alert(1)</script>',
  702. '"`\'><script>\\xE2\\x80\\x82javascript:alert(1)</script>',
  703. '"`\'><script>\\xE2\\x80\\x86javascript:alert(1)</script>',
  704. '"`\'><script>\\xE1\\xA0\\x8Ejavascript:alert(1)</script>',
  705. '"`\'><script>\\x0Bjavascript:alert(1)</script>',
  706. '"`\'><script>\\x20javascript:alert(1)</script>',
  707. '"`\'><script>\\xC2\\xA0javascript:alert(1)</script>',
  708. '<img \\x00src=x onerror="alert(1)">',
  709. '<img \\x47src=x onerror="javascript:alert(1)">',
  710. '<img \\x11src=x onerror="javascript:alert(1)">',
  711. '<img \\x12src=x onerror="javascript:alert(1)">',
  712. '<img\\x47src=x onerror="javascript:alert(1)">',
  713. '<img\\x10src=x onerror="javascript:alert(1)">',
  714. '<img\\x13src=x onerror="javascript:alert(1)">',
  715. '<img\\x32src=x onerror="javascript:alert(1)">',
  716. '<img\\x47src=x onerror="javascript:alert(1)">',
  717. '<img\\x11src=x onerror="javascript:alert(1)">',
  718. '<img \\x47src=x onerror="javascript:alert(1)">',
  719. '<img \\x34src=x onerror="javascript:alert(1)">',
  720. '<img \\x39src=x onerror="javascript:alert(1)">',
  721. '<img \\x00src=x onerror="javascript:alert(1)">',
  722. '<img src\\x09=x onerror="javascript:alert(1)">',
  723. '<img src\\x10=x onerror="javascript:alert(1)">',
  724. '<img src\\x13=x onerror="javascript:alert(1)">',
  725. '<img src\\x32=x onerror="javascript:alert(1)">',
  726. '<img src\\x12=x onerror="javascript:alert(1)">',
  727. '<img src\\x11=x onerror="javascript:alert(1)">',
  728. '<img src\\x00=x onerror="javascript:alert(1)">',
  729. '<img src\\x47=x onerror="javascript:alert(1)">',
  730. '<img src=x\\x09onerror="javascript:alert(1)">',
  731. '<img src=x\\x10onerror="javascript:alert(1)">',
  732. '<img src=x\\x11onerror="javascript:alert(1)">',
  733. '<img src=x\\x12onerror="javascript:alert(1)">',
  734. '<img src=x\\x13onerror="javascript:alert(1)">',
  735. '<img[a][b][c]src[d]=x[e]onerror=[f]"alert(1)">',
  736. '<img src=x onerror=\\x09"javascript:alert(1)">',
  737. '<img src=x onerror=\\x10"javascript:alert(1)">',
  738. '<img src=x onerror=\\x11"javascript:alert(1)">',
  739. '<img src=x onerror=\\x12"javascript:alert(1)">',
  740. '<img src=x onerror=\\x32"javascript:alert(1)">',
  741. '<img src=x onerror=\\x00"javascript:alert(1)">',
  742. '<a href=java&#1&#2&#3&#4&#5&#6&#7&#8&#11&#12script:javascript:alert(1)>XXX</a>',
  743. '<img src="x` `<script>javascript:alert(1)</script>"` `>',
  744. '<img src onerror /" \'"= alt=javascript:alert(1)//">',
  745. '<title onpropertychange=javascript:alert(1)></title><title title=>',
  746. '<a href=http://foo.bar/#x=`y></a><img alt="`><img src=x:x onerror=javascript:alert(1)></a>">',
  747. '<!--[if]><script>javascript:alert(1)</script -->',
  748. '<!--[if<img src=x onerror=javascript:alert(1)//]> -->',
  749. '<script src="/\\%(jscript)s"></script>',
  750. '<script src="\\\\%(jscript)s"></script>',
  751. '<IMG """><SCRIPT>alert("XSS")</SCRIPT>">',
  752. '<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>',
  753. '<IMG SRC=# onmouseover="alert(\'xxs\')">',
  754. '<IMG SRC= onmouseover="alert(\'xxs\')">',
  755. '<IMG onmouseover="alert(\'xxs\')">',
  756. '<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>',
  757. '<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>',
  758. '<IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>',
  759. '<IMG SRC="jav ascript:alert(\'XSS\');">',
  760. '<IMG SRC="jav&#x09;ascript:alert(\'XSS\');">',
  761. '<IMG SRC="jav&#x0A;ascript:alert(\'XSS\');">',
  762. '<IMG SRC="jav&#x0D;ascript:alert(\'XSS\');">',
  763. 'perl -e \'print "<IMG SRC=java\\0script:alert(\\"XSS\\")>";\' > out',
  764. '<IMG SRC=" &#14; javascript:alert(\'XSS\');">',
  765. '<SCRIPT/XSS SRC="http://ha.ckers.org/xss.js"></SCRIPT>',
  766. '<BODY onload!#$%&()*~+-_.,:;?@[/|\\]^`=alert("XSS")>',
  767. '<SCRIPT/SRC="http://ha.ckers.org/xss.js"></SCRIPT>',
  768. '<<SCRIPT>alert("XSS");//<</SCRIPT>',
  769. '<SCRIPT SRC=http://ha.ckers.org/xss.js?< B >',
  770. '<SCRIPT SRC=//ha.ckers.org/.j>',
  771. '<IMG SRC="javascript:alert(\'XSS\')"',
  772. '<iframe src=http://ha.ckers.org/scriptlet.html <',
  773. "\\\";alert('XSS');//",
  774. '<plaintext>',
  775. '1;DROP TABLE users',
  776. "1'; DROP TABLE users-- 1",
  777. "' OR 1=1 -- 1",
  778. "' OR '1'='1",
  779. '-',
  780. '--',
  781. '--version',
  782. '--help',
  783. '$USER',
  784. '/dev/null; touch /tmp/blns.fail ; echo',
  785. '`touch /tmp/blns.fail`',
  786. '$(touch /tmp/blns.fail)',
  787. '@{[system "touch /tmp/blns.fail"]}',
  788. 'eval("puts \'hello world\'")',
  789. 'System("ls -al /")',
  790. '`ls -al /`',
  791. 'Kernel.exec("ls -al /")',
  792. 'Kernel.exit(1)',
  793. "%x('ls -al /')",
  794. '<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE foo [ <!ELEMENT foo ANY ><!ENTITY xxe SYSTEM "file:///etc/passwd" >]><foo>&xxe;</foo>',
  795. '$HOME',
  796. "$ENV{'HOME'}",
  797. '%d',
  798. '%s',
  799. '%*.*s',
  800. '../../../../../../../../../../../etc/passwd%00',
  801. '../../../../../../../../../../../etc/hosts',
  802. '() { 0; }; touch /tmp/blns.shellshock1.fail;',
  803. '() { _; } >_[$($())] { touch /tmp/blns.shellshock2.fail; }',
  804. 'CON',
  805. 'PRN',
  806. 'AUX',
  807. 'CLOCK$',
  808. 'NUL',
  809. 'A:',
  810. 'ZZ:',
  811. 'COM1',
  812. 'LPT1',
  813. 'LPT2',
  814. 'LPT3',
  815. 'COM2',
  816. 'COM3',
  817. 'COM4',
  818. 'Scunthorpe General Hospital',
  819. 'Penistone Community Church',
  820. 'Lightwater Country Park',
  821. 'Jimmy Clitheroe',
  822. 'Horniman Museum',
  823. 'shitake mushrooms',
  824. 'RomansInSussex.co.uk',
  825. 'http://www.cum.qc.ca/',
  826. 'Craig Cockburn, Software Specialist',
  827. 'Linda Callahan',
  828. 'Dr. Herman I. Libshitz',
  829. 'magna cum laude',
  830. 'Super Bowl XXX',
  831. 'medieval erection of parapets',
  832. 'evaluate',
  833. 'mocha',
  834. 'expression',
  835. 'Arsenal canal',
  836. 'classic',
  837. 'Tyson Gay',
  838. "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.",
  839. 'Roses are \u001b[0;31mred\u001b[0m, violets are \u001b[0;34mblue. Hope you enjoy terminal hue',
  840. 'But now...\u001b[20Cfor my greatest trick...\u001b[8m',
  841. 'The quic\b\b\b\b\b\bk brown fo\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007x... [Beeeep]',
  842. 'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗',
  843. ],
  844. ranges: {},
  845. version: 2,
  846. }
  847. return DocstoreClient.createDoc(
  848. this.project_id,
  849. this.doc._id,
  850. this.doc.lines,
  851. this.doc.version,
  852. this.doc.ranges,
  853. error => {
  854. if (error != null) {
  855. throw error
  856. }
  857. return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
  858. this.res = res
  859. if (error != null) {
  860. throw error
  861. }
  862. return done()
  863. })
  864. }
  865. )
  866. })
  867. it('should successully archive the docs', function (done) {
  868. this.res.statusCode.should.equal(204)
  869. return done()
  870. })
  871. it('should set inS3 and unset lines and ranges in each doc', function (done) {
  872. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  873. if (error != null) {
  874. throw error
  875. }
  876. expect(doc.lines).not.to.exist
  877. expect(doc.ranges).not.to.exist
  878. doc.inS3.should.equal(true)
  879. return done()
  880. })
  881. })
  882. it('should set the doc in s3 correctly', function (done) {
  883. return DocstoreClient.getS3Doc(
  884. this.project_id,
  885. this.doc._id,
  886. (error, s3_doc) => {
  887. if (error != null) {
  888. throw error
  889. }
  890. s3_doc.lines.should.deep.equal(this.doc.lines)
  891. s3_doc.ranges.should.deep.equal(this.doc.ranges)
  892. return done()
  893. }
  894. )
  895. })
  896. return describe('after unarchiving from a request for the project', function () {
  897. before(function (done) {
  898. return DocstoreClient.getAllDocs(
  899. this.project_id,
  900. (error, res, fetched_docs) => {
  901. this.fetched_docs = fetched_docs
  902. if (error != null) {
  903. throw error
  904. }
  905. return done()
  906. }
  907. )
  908. })
  909. return it('should restore the doc to mongo', function (done) {
  910. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  911. if (error != null) {
  912. throw error
  913. }
  914. doc.lines.should.deep.equal(this.doc.lines)
  915. doc.ranges.should.deep.equal(this.doc.ranges)
  916. expect(doc.inS3).not.to.exist
  917. return done()
  918. })
  919. })
  920. })
  921. })
  922. describe('a doc with ranges', function () {
  923. before(function (done) {
  924. this.project_id = ObjectId()
  925. this.doc = {
  926. _id: ObjectId(),
  927. lines: ['one', 'two', 'three'],
  928. ranges: {
  929. changes: [
  930. {
  931. id: ObjectId(),
  932. op: { i: 'foo', p: 24 },
  933. metadata: {
  934. user_id: ObjectId(),
  935. ts: new Date('2017-01-27T16:10:44.194Z'),
  936. },
  937. },
  938. {
  939. id: ObjectId(),
  940. op: { d: 'bar', p: 50 },
  941. metadata: {
  942. user_id: ObjectId(),
  943. ts: new Date('2017-01-27T18:10:44.194Z'),
  944. },
  945. },
  946. ],
  947. comments: [
  948. {
  949. id: ObjectId(),
  950. op: { c: 'comment', p: 284, t: ObjectId() },
  951. metadata: {
  952. user_id: ObjectId(),
  953. ts: new Date('2017-01-26T14:22:04.869Z'),
  954. },
  955. },
  956. ],
  957. },
  958. version: 2,
  959. }
  960. return DocstoreClient.createDoc(
  961. this.project_id,
  962. this.doc._id,
  963. this.doc.lines,
  964. this.doc.version,
  965. this.doc.ranges,
  966. error => {
  967. if (error != null) {
  968. throw error
  969. }
  970. return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
  971. this.res = res
  972. if (error != null) {
  973. throw error
  974. }
  975. return done()
  976. })
  977. }
  978. )
  979. })
  980. it('should successully archive the docs', function (done) {
  981. this.res.statusCode.should.equal(204)
  982. return done()
  983. })
  984. it('should set inS3 and unset lines and ranges in each doc', function (done) {
  985. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  986. if (error != null) {
  987. throw error
  988. }
  989. expect(doc.lines).not.to.exist
  990. expect(doc.ranges).not.to.exist
  991. doc.inS3.should.equal(true)
  992. return done()
  993. })
  994. })
  995. it('should set the doc in s3 correctly', function (done) {
  996. return DocstoreClient.getS3Doc(
  997. this.project_id,
  998. this.doc._id,
  999. (error, s3_doc) => {
  1000. if (error != null) {
  1001. throw error
  1002. }
  1003. s3_doc.lines.should.deep.equal(this.doc.lines)
  1004. const ranges = JSON.parse(JSON.stringify(this.doc.ranges)) // ObjectId -> String
  1005. s3_doc.ranges.should.deep.equal(ranges)
  1006. return done()
  1007. }
  1008. )
  1009. })
  1010. return describe('after unarchiving from a request for the project', function () {
  1011. before(function (done) {
  1012. return DocstoreClient.getAllDocs(
  1013. this.project_id,
  1014. (error, res, fetched_docs) => {
  1015. this.fetched_docs = fetched_docs
  1016. if (error != null) {
  1017. throw error
  1018. }
  1019. return done()
  1020. }
  1021. )
  1022. })
  1023. return it('should restore the doc to mongo', function (done) {
  1024. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  1025. if (error != null) {
  1026. throw error
  1027. }
  1028. doc.lines.should.deep.equal(this.doc.lines)
  1029. doc.ranges.should.deep.equal(this.doc.ranges)
  1030. expect(doc.inS3).not.to.exist
  1031. return done()
  1032. })
  1033. })
  1034. })
  1035. })
  1036. describe('a doc that is archived twice', function () {
  1037. before(function (done) {
  1038. this.project_id = ObjectId()
  1039. this.doc = {
  1040. _id: ObjectId(),
  1041. lines: ['abc', 'def', 'ghi'],
  1042. ranges: {},
  1043. version: 2,
  1044. }
  1045. return DocstoreClient.createDoc(
  1046. this.project_id,
  1047. this.doc._id,
  1048. this.doc.lines,
  1049. this.doc.version,
  1050. this.doc.ranges,
  1051. error => {
  1052. if (error != null) {
  1053. throw error
  1054. }
  1055. return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
  1056. this.res = res
  1057. if (error != null) {
  1058. throw error
  1059. }
  1060. this.res.statusCode.should.equal(204)
  1061. return DocstoreClient.archiveAllDoc(
  1062. this.project_id,
  1063. (error, res1) => {
  1064. this.res = res1
  1065. if (error != null) {
  1066. throw error
  1067. }
  1068. this.res.statusCode.should.equal(204)
  1069. return done()
  1070. }
  1071. )
  1072. })
  1073. }
  1074. )
  1075. })
  1076. it('should set inS3 and unset lines and ranges in each doc', function (done) {
  1077. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  1078. if (error != null) {
  1079. throw error
  1080. }
  1081. expect(doc.lines).not.to.exist
  1082. expect(doc.ranges).not.to.exist
  1083. doc.inS3.should.equal(true)
  1084. return done()
  1085. })
  1086. })
  1087. it('should set the doc in s3 correctly', function (done) {
  1088. return DocstoreClient.getS3Doc(
  1089. this.project_id,
  1090. this.doc._id,
  1091. (error, s3_doc) => {
  1092. if (error != null) {
  1093. throw error
  1094. }
  1095. s3_doc.lines.should.deep.equal(this.doc.lines)
  1096. s3_doc.ranges.should.deep.equal(this.doc.ranges)
  1097. return done()
  1098. }
  1099. )
  1100. })
  1101. return describe('after unarchiving from a request for the project', function () {
  1102. before(function (done) {
  1103. return DocstoreClient.getAllDocs(
  1104. this.project_id,
  1105. (error, res, fetched_docs) => {
  1106. this.fetched_docs = fetched_docs
  1107. if (error != null) {
  1108. throw error
  1109. }
  1110. return done()
  1111. }
  1112. )
  1113. })
  1114. return it('should restore the doc to mongo', function (done) {
  1115. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  1116. if (error != null) {
  1117. throw error
  1118. }
  1119. doc.lines.should.deep.equal(this.doc.lines)
  1120. doc.ranges.should.deep.equal(this.doc.ranges)
  1121. expect(doc.inS3).not.to.exist
  1122. return done()
  1123. })
  1124. })
  1125. })
  1126. })
  1127. return describe('a doc with the old schema (just an array of lines)', function () {
  1128. before(function (done) {
  1129. this.project_id = ObjectId()
  1130. this.doc = {
  1131. _id: ObjectId(),
  1132. lines: ['abc', 'def', 'ghi'],
  1133. ranges: {},
  1134. version: 2,
  1135. }
  1136. uploadContent(
  1137. `${this.project_id}/${this.doc._id}`,
  1138. this.doc.lines,
  1139. error => {
  1140. expect(error).not.to.exist
  1141. db.docs.insert(
  1142. {
  1143. project_id: this.project_id,
  1144. _id: this.doc._id,
  1145. rev: this.doc.version,
  1146. inS3: true,
  1147. },
  1148. error => {
  1149. if (error != null) {
  1150. throw error
  1151. }
  1152. DocstoreClient.getAllDocs(
  1153. this.project_id,
  1154. (error, res, fetched_docs) => {
  1155. this.fetched_docs = fetched_docs
  1156. if (error != null) {
  1157. throw error
  1158. }
  1159. return done()
  1160. }
  1161. )
  1162. }
  1163. )
  1164. }
  1165. )
  1166. })
  1167. it('should restore the doc to mongo', function (done) {
  1168. return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
  1169. if (error != null) {
  1170. throw error
  1171. }
  1172. doc.lines.should.deep.equal(this.doc.lines)
  1173. expect(doc.inS3).not.to.exist
  1174. return done()
  1175. })
  1176. })
  1177. return it('should return the doc', function (done) {
  1178. this.fetched_docs[0].lines.should.deep.equal(this.doc.lines)
  1179. return done()
  1180. })
  1181. })
  1182. })