AllowedImageNames.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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('wordcount', 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.wordcountWithImage(
  73. this.project_id,
  74. 'main.tex',
  75. 'something/evil:1337',
  76. (error, result) => {
  77. expect(String(error)).to.include('statusCode=400')
  78. }
  79. )
  80. })
  81. it('should produce a texcout a valid imageName', function () {
  82. Client.wordcountWithImage(
  83. this.project_id,
  84. 'main.tex',
  85. process.env.TEXLIVE_IMAGE,
  86. (error, result) => {
  87. expect(error).to.not.exist
  88. expect(result).to.exist
  89. expect(result.texcount).to.exist
  90. }
  91. )
  92. })
  93. })
  94. })