ArchiveDocsTests.js 45 KB

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