AllowedImageNames.js 4.4 KB

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