Prechádzať zdrojové kódy

Merge pull request #29638 from overleaf/bg-add-shell-escape-tests-to-clsi

add shell escape tests to clsi

GitOrigin-RevId: 6cd3ab24fa76f74dccfec43bf6a3d06c0fe9ec6a
Brian Gough 9 mesiacov pred
rodič
commit
4ca1407ab9

+ 37 - 0
services/clsi/test/acceptance/js/SimpleLatexFileTests.js

@@ -1,6 +1,7 @@
 const Client = require('./helpers/Client')
 const { fetchNothing } = require('@overleaf/fetch-utils')
 const ClsiApp = require('./helpers/ClsiApp')
+const { expect } = require('chai')
 
 describe('Simple LaTeX file', function () {
   const content = `\
@@ -92,4 +93,40 @@ Hello world
       })
     })
   }
+
+  describe('document with shell commands', function () {
+    before(async function () {
+      this.project_id = Client.randomId()
+      this.request = {
+        resources: [
+          {
+            path: 'main.tex',
+            content: `\
+\\documentclass{article}
+\\begin{document}
+Testing system calls:
+\\immediate\\write18{/bin/date > date.txt}
+The current date from system is: \\input{date.txt}
+The current date from popen is: \\input{"|date"}
+\\end{document}\
+`,
+          },
+        ],
+      }
+      await ClsiApp.ensureRunning()
+    })
+
+    it('should compile successfully', async function () {
+      const body = await Client.compile(this.project_id, this.request)
+      expect(body).to.exist
+      expect(body.compile?.status, 'compile status').to.equal('success')
+    })
+
+    it('should return the PDF', async function () {
+      const body = await Client.compile(this.project_id, this.request)
+      const pdf = Client.getOutputFile(body, 'pdf')
+      expect(pdf, 'pdf file not produced').to.exist
+      expect(pdf.type, 'invalid pdf file').to.equal('pdf')
+    })
+  })
 })

+ 14 - 0
services/clsi/test/acceptance/js/SmokeTest.js

@@ -0,0 +1,14 @@
+const Client = require('./helpers/Client')
+const ClsiApp = require('./helpers/ClsiApp')
+const { expect } = require('chai')
+
+describe('Smoke Test', function () {
+  before(async function () {
+    await ClsiApp.ensureRunning()
+  })
+
+  it('should compile the test document and return a response of "OK"', async function () {
+    const response = await Client.smokeTest()
+    expect(response).to.equal('OK')
+  })
+})

+ 12 - 1
services/clsi/test/acceptance/js/helpers/Client.js

@@ -1,5 +1,9 @@
 const express = require('express')
-const { fetchJson, fetchNothing } = require('@overleaf/fetch-utils')
+const {
+  fetchJson,
+  fetchNothing,
+  fetchString,
+} = require('@overleaf/fetch-utils')
 const fs = require('node:fs')
 const fsPromises = require('node:fs/promises')
 const Settings = require('@overleaf/settings')
@@ -177,12 +181,19 @@ async function compileDirectory(projectId, baseDirectory, directory) {
   return await compile(projectId, req)
 }
 
+function smokeTest() {
+  return fetchString(`${host}/smoke_test_force`, {
+    method: 'GET',
+  })
+}
+
 module.exports = {
   randomId,
   compile,
   stopCompile,
   clearCache,
   getOutputFile,
+  smokeTest,
   runFakeFilestoreService,
   startFakeFilestoreApp,
   syncFromCode,

+ 21 - 0
services/clsi/test/smoke/js/SmokeTests.js

@@ -54,6 +54,9 @@ module.exports = {
 \\documentclass{article}
 \\usepackage{tikz}
 \\usetikzlibrary{calc,fadings,decorations.pathreplacing}
+\\usepackage{ifplatform} % test shell escape, conditionals to test which platform is being used
+\\usepackage{minted}  % to test shell commands
+\\usepackage{bashful} % to test shell commands
 \\begin{document}
 \\begin{tikzpicture}
   \\def\\nuPi{3.1459265}
@@ -79,6 +82,24 @@ module.exports = {
     }
   }
 \\end{tikzpicture}
+
+% Test minted (shell commands)
+\\begin{minted}{python}
+x = 1 + 2
+\\end{minted}
+
+% Test bashful (shell commands)
+\\bash[stdout,stderr]
+date
+\\END
+
+% Test system
+\\immediate\\write18{/bin/date > date.txt}
+\\input date.txt
+
+% Test popen
+\\input{"|date"}
+
 \\end{document}\
 `,
               },