ArchiveDocsTests.js 45 KB

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