Add privilegedExecution flag to database and Poseidon Strategy

This commit is contained in:
Sebastian Serth
2022-09-24 00:05:03 +02:00
committed by Sebastian Serth
parent dffeca27de
commit eb188dcd71
13 changed files with 51 additions and 10 deletions

View File

@ -10,6 +10,7 @@ FactoryBot.define do
help
name { 'CoffeeScript' }
network_enabled { false }
privileged_execution { false }
permitted_execution_time { 10.seconds }
pool_size { 0 }
run_command { 'coffee' }
@ -25,6 +26,7 @@ FactoryBot.define do
help
name { 'HTML5' }
network_enabled { false }
privileged_execution { false }
permitted_execution_time { 10.seconds }
pool_size { 0 }
run_command { 'touch' }
@ -42,6 +44,7 @@ FactoryBot.define do
help
name { 'Java 8' }
network_enabled { false }
privileged_execution { false }
permitted_execution_time { 10.seconds }
pool_size { 0 }
run_command { 'make run' }
@ -59,6 +62,7 @@ FactoryBot.define do
help
name { 'JRuby 1.7' }
network_enabled { false }
privileged_execution { false }
permitted_execution_time { 10.seconds }
pool_size { 0 }
run_command { 'jruby %{filename}' }
@ -76,6 +80,7 @@ FactoryBot.define do
help
name { 'Node.js' }
network_enabled { false }
privileged_execution { false }
permitted_execution_time { 10.seconds }
pool_size { 0 }
run_command { 'node %{filename}' }
@ -91,6 +96,7 @@ FactoryBot.define do
help
name { 'Python 3.4' }
network_enabled { false }
privileged_execution { false }
permitted_execution_time { 10.seconds }
pool_size { 0 }
run_command { 'python3 %{filename}' }
@ -108,6 +114,7 @@ FactoryBot.define do
help
name { 'Ruby 2.2' }
network_enabled { false }
privileged_execution { false }
permitted_execution_time { 10.seconds }
pool_size { 0 }
run_command { 'ruby %{filename}' }
@ -126,6 +133,7 @@ FactoryBot.define do
help
name { 'Sinatra' }
network_enabled { true }
privileged_execution { false }
permitted_execution_time { 15.minutes }
pool_size { 0 }
run_command { 'ruby %{filename}' }
@ -143,6 +151,7 @@ FactoryBot.define do
help
name { 'SQLite' }
network_enabled { false }
privileged_execution { false }
permitted_execution_time { 1.minute }
pool_size { 0 }
run_command { 'sqlite3 /database.db -init %{filename} -html' }

View File

@ -247,7 +247,11 @@ describe Runner::Strategy::Poseidon do
WebMock
.stub_request(:post, "#{described_class.config[:url]}/runners/#{runner_id}/execute")
.with(
body: {command: command, timeLimit: execution_environment.permitted_execution_time},
body: {
command: command,
timeLimit: execution_environment.permitted_execution_time,
privilegedExecution: execution_environment.privileged_execution,
},
headers: {'Content-Type' => 'application/json'}
)
.to_return(body: response_body, status: response_status)

View File

@ -3,7 +3,7 @@
require 'rails_helper'
describe ExecutionEnvironment do
let(:execution_environment) { described_class.create.tap {|execution_environment| execution_environment.update(network_enabled: nil) } }
let(:execution_environment) { described_class.create.tap {|execution_environment| execution_environment.update(network_enabled: nil, privileged_execution: nil) } }
it 'validates that the Docker image works' do
allow(execution_environment).to receive(:validate_docker_image?).and_return(true)
@ -56,6 +56,12 @@ describe ExecutionEnvironment do
expect(execution_environment.errors[:network_enabled]).to be_blank
end
it 'validates the presence of the privileged_execution enabled flag' do
expect(execution_environment.errors[:privileged_execution]).to be_present
execution_environment.update(privileged_execution: false)
expect(execution_environment.errors[:privileged_execution]).to be_blank
end
it 'validates the numericality of the permitted run time' do
execution_environment.update(permitted_execution_time: Math::PI)
expect(execution_environment.errors[:permitted_execution_time]).to be_present