class Aladdin::Submission
Student submission.
DANGER DANGER DANGER ==¶ ↑
The scratchspace code assumes that there is only one submission at a time, it’s unsuitable for production use. It does not impose any security restrictions at all.
Constants
- SCRATCHSPACE
Attributes
logger[R]
Public Class Methods
new(id, type, params, input, logger)
click to toggle source
Creates a new student submission. @param [String] id exercise ID @param [Type] type problem or code @param [Hash] params form values @param [String] input student input
# File lib/aladdin/submission.rb, line 22 def initialize(id, type, params, input, logger) @id, @type, @params, @input, @logger = id, type, params, input, logger end
Public Instance Methods
verify()
click to toggle source
Verifies the student’s submission.
# File lib/aladdin/submission.rb, line 27 def verify case @type when Type::CODE then verify_code when Type::PROBLEM then verify_problem end end
Private Instance Methods
enter_scratchspace()
click to toggle source
# File lib/aladdin/submission.rb, line 71 def enter_scratchspace # TODO: handle errors Dir.mkdir SCRATCHSPACE Dir.chdir SCRATCHSPACE end
exit_scratchspace()
click to toggle source
# File lib/aladdin/submission.rb, line 77 def exit_scratchspace # TODO: handle errors Dir.chdir '..' FileUtils.rm_rf SCRATCHSPACE end
scratchspace() { || ... }
click to toggle source
# File lib/aladdin/submission.rb, line 64 def scratchspace enter_scratchspace results = yield exit_scratchspace return results end
verify_code()
click to toggle source
Executes the verification script and returns the JSON-encoded results. @example
./verify --id=0 --input=path/to/student/input
# File lib/aladdin/submission.rb, line 53 def verify_code scratchspace do # FIXME: catch errors filename = SecureRandom.uuid IO.write(filename, @input) bin = File.join '..', Aladdin.config[:verify]['bin'] `#{bin} --id=#{@id} --input=#{filename}` IO.read 'genie-results.json' end end
verify_problem()
click to toggle source
Verifies problem answers by comparing the submitted answer against the answer in the solution file. @return [String] (json-encoded) true iff the submitted answer is correct.
# File lib/aladdin/submission.rb, line 41 def verify_problem id = @id.gsub File::SEPARATOR, '' # protect against directory attacks solution = File.expand_path id + Spirit::SOLUTION_EXT, Spirit::SOLUTION_DIR File.open(solution, 'rb') { |f| same? @params['answer'], Marshal.restore(f) }.to_json rescue => e logger.warn e.message false.to_json end