AllowedImageNamesTests.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. })
  105. done()
  106. }
  107. )
  108. })
  109. })
  110. describe('syncToPdf', function () {
  111. beforeEach(function (done) {
  112. Client.compile(this.project_id, this.request, done)
  113. })
  114. it('should error out with an invalid imageName', function (done) {
  115. Client.syncFromPdfWithImage(
  116. this.project_id,
  117. 'main.tex',
  118. 100,
  119. 200,
  120. 'something/evil:1337',
  121. (error, body) => {
  122. expect(String(error)).to.include('statusCode=400')
  123. expect(body).to.equal('invalid image')
  124. done()
  125. }
  126. )
  127. })
  128. it('should produce a mapping a valid imageName', function (done) {
  129. Client.syncFromPdfWithImage(
  130. this.project_id,
  131. 1,
  132. 100,
  133. 200,
  134. process.env.TEXLIVE_IMAGE,
  135. (error, result) => {
  136. expect(error).to.not.exist
  137. expect(result).to.deep.equal({
  138. code: [{ file: 'main.tex', line: 3, column: -1 }],
  139. })
  140. done()
  141. }
  142. )
  143. })
  144. })
  145. describe('wordcount', function () {
  146. beforeEach(function (done) {
  147. Client.compile(this.project_id, this.request, done)
  148. })
  149. it('should error out with an invalid imageName', function (done) {
  150. Client.wordcountWithImage(
  151. this.project_id,
  152. 'main.tex',
  153. 'something/evil:1337',
  154. (error, body) => {
  155. expect(String(error)).to.include('statusCode=400')
  156. expect(body).to.equal('invalid image')
  157. done()
  158. }
  159. )
  160. })
  161. it('should produce a texcout a valid imageName', function (done) {
  162. Client.wordcountWithImage(
  163. this.project_id,
  164. 'main.tex',
  165. process.env.TEXLIVE_IMAGE,
  166. (error, result) => {
  167. expect(error).to.not.exist
  168. expect(result).to.exist
  169. expect(result.texcount).to.exist
  170. done()
  171. }
  172. )
  173. })
  174. })
  175. })