mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add enableConversions flag to disable conversions which we can't do on
k8
This commit is contained in:
parent
982c180225
commit
3614f217e6
5 changed files with 43 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
exec = require('child_process').exec
|
exec = require('child_process').exec
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
|
Settings = require "settings-sharelatex"
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
|
@ -10,6 +11,9 @@ module.exports =
|
||||||
opts =
|
opts =
|
||||||
timeout: 30 * 1000
|
timeout: 30 * 1000
|
||||||
killSignal: "SIGKILL"
|
killSignal: "SIGKILL"
|
||||||
|
if !Settings.enableConversions
|
||||||
|
error = new Error("Image conversions are disabled")
|
||||||
|
return callback(error)
|
||||||
exec args, opts,(err, stdout, stderr)->
|
exec args, opts,(err, stdout, stderr)->
|
||||||
if err? and err.signal == 'SIGKILL'
|
if err? and err.signal == 'SIGKILL'
|
||||||
logger.warn {err: err, stderr: stderr, localPath: localPath}, "optimiser timeout reached"
|
logger.warn {err: err, stderr: stderr, localPath: localPath}, "optimiser timeout reached"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
_ = require("underscore")
|
_ = require("underscore")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
child_process = require('child_process')
|
child_process = require('child_process')
|
||||||
|
Settings = require "settings-sharelatex"
|
||||||
|
|
||||||
# execute a command in the same way as 'exec' but with a timeout that
|
# execute a command in the same way as 'exec' but with a timeout that
|
||||||
# kills all child processes
|
# kills all child processes
|
||||||
|
@ -9,6 +10,10 @@ child_process = require('child_process')
|
||||||
# group, then we can kill everything in that process group.
|
# group, then we can kill everything in that process group.
|
||||||
|
|
||||||
module.exports = (command, options, callback = (err, stdout, stderr) ->) ->
|
module.exports = (command, options, callback = (err, stdout, stderr) ->) ->
|
||||||
|
if !Settings.enableConversions
|
||||||
|
error = new Error("Image conversions are disabled")
|
||||||
|
return callback(error)
|
||||||
|
|
||||||
# options are {timeout: number-of-milliseconds, killSignal: signal-name}
|
# options are {timeout: number-of-milliseconds, killSignal: signal-name}
|
||||||
[cmd, args...] = command
|
[cmd, args...] = command
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ settings =
|
||||||
# Any commands to wrap the convert utility in, for example ["nice"], or ["firejail", "--profile=/etc/firejail/convert.profile"]
|
# Any commands to wrap the convert utility in, for example ["nice"], or ["firejail", "--profile=/etc/firejail/convert.profile"]
|
||||||
convertCommandPrefix: []
|
convertCommandPrefix: []
|
||||||
|
|
||||||
|
enableConversions: false
|
||||||
|
|
||||||
# Filestore health check
|
# Filestore health check
|
||||||
# ----------------------
|
# ----------------------
|
||||||
|
|
|
@ -11,13 +11,16 @@ describe "ImageOptimiser", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@child_process =
|
@child_process =
|
||||||
exec : sinon.stub()
|
exec : sinon.stub()
|
||||||
|
@settings =
|
||||||
|
enableConversions:true
|
||||||
@optimiser = SandboxedModule.require modulePath, requires:
|
@optimiser = SandboxedModule.require modulePath, requires:
|
||||||
'child_process': @child_process
|
'child_process': @child_process
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
warn:->
|
warn:->
|
||||||
|
"settings-sharelatex": @settings
|
||||||
|
|
||||||
|
|
||||||
@sourcePath = "/this/path/here.eps"
|
@sourcePath = "/this/path/here.eps"
|
||||||
@error = "Error"
|
@error = "Error"
|
||||||
|
@ -33,18 +36,29 @@ describe "ImageOptimiser", ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
||||||
it "should return the errro the file", (done)->
|
it "should return the error", (done)->
|
||||||
@child_process.exec.callsArgWith(2, @error)
|
@child_process.exec.callsArgWith(2, @error)
|
||||||
@optimiser.compressPng @sourcePath, (err)=>
|
@optimiser.compressPng @sourcePath, (err)=>
|
||||||
err.should.equal @error
|
err.should.equal @error
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'when optimiser is sigkilled', ->
|
describe 'when enableConversions is disabled', ->
|
||||||
|
|
||||||
it 'should not produce an error', (done) ->
|
it 'should produce an error', (done) ->
|
||||||
@error = new Error('woops')
|
@settings.enableConversions = false
|
||||||
@error.signal = 'SIGKILL'
|
@child_process.exec.callsArgWith(2)
|
||||||
@child_process.exec.callsArgWith(2, @error)
|
@optimiser.compressPng @sourcePath, (err)=>
|
||||||
@optimiser.compressPng @sourcePath, (err)=>
|
@child_process.exec.called.should.equal false
|
||||||
expect(err).to.equal(null)
|
expect(err).to.exist
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
describe 'when optimiser is sigkilled', ->
|
||||||
|
|
||||||
|
it 'should not produce an error', (done) ->
|
||||||
|
@error = new Error('woops')
|
||||||
|
@error.signal = 'SIGKILL'
|
||||||
|
@child_process.exec.callsArgWith(2, @error)
|
||||||
|
@optimiser.compressPng @sourcePath, (err)=>
|
||||||
|
expect(err).to.equal(null)
|
||||||
|
done()
|
||||||
|
|
|
@ -9,11 +9,13 @@ SandboxedModule = require('sandboxed-module')
|
||||||
describe "SafeExec", ->
|
describe "SafeExec", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@settings =
|
||||||
|
enableConversions:true
|
||||||
@safe_exec = SandboxedModule.require modulePath, requires:
|
@safe_exec = SandboxedModule.require modulePath, requires:
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
|
"settings-sharelatex": @settings
|
||||||
@options = {timeout: 10*1000, killSignal: "SIGTERM" }
|
@options = {timeout: 10*1000, killSignal: "SIGTERM" }
|
||||||
|
|
||||||
describe "safe_exec", ->
|
describe "safe_exec", ->
|
||||||
|
@ -24,6 +26,12 @@ describe "SafeExec", ->
|
||||||
should.not.exist(err)
|
should.not.exist(err)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it "should error when conversions are disabled", (done) ->
|
||||||
|
@settings.enableConversions = false
|
||||||
|
@safe_exec ["/bin/echo", "hello"], @options, (err, stdout, stderr) =>
|
||||||
|
expect(err).to.exist
|
||||||
|
done()
|
||||||
|
|
||||||
it "should execute a command with non-zero exit status", (done) ->
|
it "should execute a command with non-zero exit status", (done) ->
|
||||||
@safe_exec ["/usr/bin/env", "false"], @options, (err, stdout, stderr) =>
|
@safe_exec ["/usr/bin/env", "false"], @options, (err, stdout, stderr) =>
|
||||||
stdout.should.equal ""
|
stdout.should.equal ""
|
Loading…
Reference in a new issue