AllowedImageNamesTests.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. const Client = require('./helpers/Client')
  2. const ClsiApp = require('./helpers/ClsiApp')
  3. const { expect } = require('chai')
  4. describe('AllowedImageNames', function () {
  5. beforeEach(function (done) {
  6. this.project_id = Client.randomId()
  7. this.request = {
  8. options: {
  9. imageName: undefined,
  10. },
  11. resources: [
  12. {
  13. path: 'main.tex',
  14. content: `\
  15. \\documentclass{article}
  16. \\begin{document}
  17. Hello world
  18. \\end{document}\
  19. `,
  20. },
  21. ],
  22. }
  23. ClsiApp.ensureRunning(done)
  24. })
  25. describe('with a valid name', function () {
  26. beforeEach(function (done) {
  27. this.request.options.imageName = process.env.TEXLIVE_IMAGE
  28. Client.compile(this.project_id, this.request, (error, res, body) => {
  29. this.error = error
  30. this.res = res
  31. this.body = body
  32. done(error)
  33. })
  34. })
  35. it('should return success', function () {
  36. expect(this.res.statusCode).to.equal(200)
  37. })
  38. it('should return a PDF', function () {
  39. let pdf
  40. try {
  41. pdf = Client.getOutputFile(this.body, 'pdf')
  42. } catch (e) {}
  43. expect(pdf).to.exist
  44. })
  45. })
  46. describe('with an invalid name', function () {
  47. beforeEach(function (done) {
  48. this.request.options.imageName = 'something/evil:1337'
  49. Client.compile(this.project_id, this.request, (error, res, body) => {
  50. this.error = error
  51. this.res = res
  52. this.body = body
  53. done(error)
  54. })
  55. })
  56. it('should return non success', function () {
  57. expect(this.res.statusCode).to.not.equal(200)
  58. })
  59. it('should not return a PDF', function () {
  60. let pdf
  61. try {
  62. pdf = Client.getOutputFile(this.body, 'pdf')
  63. } catch (e) {}
  64. expect(pdf).to.not.exist
  65. })
  66. })
  67. describe('syncToCode', function () {
  68. beforeEach(function (done) {
  69. Client.compile(this.project_id, this.request, done)
  70. })
  71. it('should error out with an invalid imageName', function (done) {
  72. Client.syncFromCodeWithImage(
  73. this.project_id,
  74. 'main.tex',
  75. 3,
  76. 5,
  77. 'something/evil:1337',
  78. (error, body) => {
  79. expect(String(error)).to.include('statusCode=400')
  80. expect(body).to.equal('invalid image')
  81. done()
  82. }
  83. )
  84. })
  85. it('should produce a mapping a valid imageName', function (done) {
  86. Client.syncFromCodeWithImage(
  87. this.project_id,
  88. 'main.tex',
  89. 3,
  90. 5,
  91. process.env.TEXLIVE_IMAGE,
  92. (error, result) => {
  93. expect(error).to.not.exist
  94. expect(result).to.deep.equal({
  95. pdf: [
  96. {
  97. page: 1,
  98. h: 133.768356,
  99. v: 134.764618,
  100. height: 6.918498,
  101. width: 343.71106,
  102. },
  103. ],
  104. downloadedFromCache: false,
  105. })
  106. done()
  107. }
  108. )
  109. })
  110. })
  111. describe('syncToPdf', function () {
  112. beforeEach(function (done) {
  113. Client.compile(this.project_id, this.request, done)
  114. })
  115. it('should error out with an invalid imageName', function (done) {
  116. Client.syncFromPdfWithImage(
  117. this.project_id,
  118. 'main.tex',
  119. 100,
  120. 200,
  121. 'something/evil:1337',
  122. (error, body) => {
  123. expect(String(error)).to.include('statusCode=400')
  124. expect(body).to.equal('invalid image')
  125. done()
  126. }
  127. )
  128. })
  129. it('should produce a mapping a valid imageName', function (done) {
  130. Client.syncFromPdfWithImage(
  131. this.project_id,
  132. 1,
  133. 100,
  134. 200,
  135. process.env.TEXLIVE_IMAGE,
  136. (error, result) => {
  137. expect(error).to.not.exist
  138. expect(result).to.deep.equal({
  139. code: [{ file: 'main.tex', line: 3, column: -1 }],
  140. downloadedFromCache: false,
  141. })
  142. done()
  143. }
  144. )
  145. })
  146. })
  147. describe('wordcount', function () {
  148. beforeEach(function (done) {
  149. Client.compile(this.project_id, this.request, done)
  150. })
  151. it('should error out with an invalid imageName', function (done) {
  152. Client.wordcountWithImage(
  153. this.project_id,
  154. 'main.tex',
  155. 'something/evil:1337',
  156. (error, body) => {
  157. expect(String(error)).to.include('statusCode=400')
  158. expect(body).to.equal('invalid image')
  159. done()
  160. }
  161. )
  162. })
  163. it('should produce a texcout a valid imageName', function (done) {
  164. Client.wordcountWithImage(
  165. this.project_id,
  166. 'main.tex',
  167. process.env.TEXLIVE_IMAGE,
  168. (error, result) => {
  169. expect(error).to.not.exist
  170. expect(result).to.exist
  171. expect(result.texcount).to.exist
  172. done()
  173. }
  174. )
  175. })
  176. })
  177. })