AllowedImageNamesTests.js 4.5 KB

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