|
16 | 16 |
|
17 | 17 | expect(current_path).to eql "/dashboard" |
18 | 18 | end |
| 19 | + |
| 20 | + context "Submitting a form with an invalid CSRF token" do |
| 21 | + before(:all) do |
| 22 | + ActionController::Base.allow_forgery_protection = true |
| 23 | + end |
| 24 | + |
| 25 | + context "When logging in" do |
| 26 | + it "should redirect back and show a helpful message" do |
| 27 | + visit "/users/sign_in" |
| 28 | + fill_in "user_email", with: user.email |
| 29 | + fill_in "user_password", with: DEFAULT_USER_PASSWORD |
| 30 | + first('input[name="authenticity_token"]', visible: false).set("NOTAVALIDCSRFTOKEN") |
| 31 | + page.execute_script("$(\"meta[name='csrf-token']\").attr('content', 'NOTAVALIDCSRFTOKEN');") |
| 32 | + click_button "Log in" |
| 33 | + expect(current_path).to eql "/users/sign_in" |
| 34 | + expect(page).to have_content "Your session expired. This could be due to leaving a page open for a long time, or having multiple tabs open. Try resubmitting." |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + context "When logged in and creating a distribution" do |
| 39 | + before do |
| 40 | + create(:partner, organization: organization, name: "Test Partner") |
| 41 | + storage_location = create(:storage_location, organization: organization, name: "Test Storage Location") |
| 42 | + setup_storage_location(storage_location) |
| 43 | + end |
| 44 | + it "should redirect back and show a helpful message" do |
| 45 | + sign_in(user) |
| 46 | + visit new_distribution_path |
| 47 | + select "Test Partner", from: "Partner" |
| 48 | + select "Test Storage Location", from: "From storage location" |
| 49 | + first('input[name="authenticity_token"]', visible: false).set("NOTAVALIDCSRFTOKEN") |
| 50 | + page.execute_script("$(\"meta[name='csrf-token']\").attr('content', 'NOTAVALIDCSRFTOKEN');") |
| 51 | + click_button "Save" |
| 52 | + expect(current_path).to eql new_distribution_path |
| 53 | + expect(page).to have_content "Your session expired. This could be due to leaving a page open for a long time, or having multiple tabs open. Try resubmitting." |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + after(:all) do |
| 58 | + ActionController::Base.allow_forgery_protection = false |
| 59 | + end |
| 60 | + end |
19 | 61 | end |
0 commit comments