edurange / edurange-server

cloud-based interactive security exercises
https://www.edurange.org
MIT License
14 stars 14 forks source link

Can't destroy scenario when original scenario directory is moved or deleted. #48

Open newjam opened 5 years ago

newjam commented 5 years ago

Steps to reproduce

  1. Create Scenario
  2. Delete directory scenario was created from
  3. Destroy scenario (Either with or without saving)

When you try to destroy without saving:

Completed 500 Internal Server Error in 18ms (ActiveRecord: 2.8ms)

Errno::ENOENT (No such file or directory @ rb_sysopen - /root/edurange-server/scenarios/development/getting_started/getting_started.yml):
  app/models/statistic.rb:306:in `initialize'
  app/models/statistic.rb:306:in `open'
  app/models/statistic.rb:306:in `block in save_scenario_yml'
  app/models/statistic.rb:305:in `open'
  app/models/statistic.rb:305:in `save_scenario_yml'
  app/models/scenario.rb:63:in `save_questions_and_answers'
  app/controllers/scenarios_controller.rb:187:in `destroyme'

  Rendered /usr/local/rvm/gems/ruby-2.5.1@edurange/gems/actionpack-4.2.11/lib/action_dispatch/middleware/templates/rescues/_source.erb (3.9ms)
  Rendered /usr/local/rvm/gems/ruby-2.5.1@edurange/gems/actionpack-4.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (0.6ms)
  Rendered /usr/local/rvm/gems/ruby-2.5.1@edurange/gems/actionpack-4.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (0.7ms)
  Rendered /usr/local/rvm/gems/ruby-2.5.1@edurange/gems/actionpack-4.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb (20.6ms)

When you try to destroy with saving:

Completed 500 Internal Server Error in 39ms (ActiveRecord: 7.6ms)

Errno::ENOENT (No such file or directory @ rb_sysopen - /root/edurange-server/scenarios/development/getting_started/getting_started.yml):
  app/models/scenario.rb:171:in `initialize'
  app/models/scenario.rb:171:in `open'
  app/models/scenario.rb:171:in `update_yml'
  app/controllers/scenarios_controller.rb:185:in `destroyme'

  Rendered /usr/local/rvm/gems/ruby-2.5.1@edurange/gems/actionpack-4.2.11/lib/action_dispatch/middleware/templates/rescues/_source.erb (3.7ms)
  Rendered /usr/local/rvm/gems/ruby-2.5.1@edurange/gems/actionpack-4.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (0.8ms)
  Rendered /usr/local/rvm/gems/ruby-2.5.1@edurange/gems/actionpack-4.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (0.8ms)
  Rendered /usr/local/rvm/gems/ruby-2.5.1@edurange/gems/actionpack-4.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb (21.4ms)

Destroy with saving attempts to rewrite the original scenario files, so it makes sense there would be an issue. This case should still be handled, though.

Destroy without saving shouldn't need the original files. We should be loading the scenario entirely into the database and the scenario shouldn't need to look at the source files again.