Updated

spec/requests / admin_user_persistence_token_spec.rb

D
104 lines of codes
1 methods
223.7 complexity/method
3 churn
223.67 complexity
16 duplications
require 'rails_helper' RSpec.describe "admin user persistence token", type: :request, csrf: false do let(:user_attributes) do { first_name: "System", last_name: "Administrator", email: "admin@petition.parliament.uk", password: "L3tme1n!", password_confirmation: "L3tme1n!" } end let(:login_params) do { email: "admin@petition.parliament.uk", password: "L3tme1n!" } end before do FactoryBot.create(:sysadmin_user, user_attributes) end def new_browser open_session do |s|
  1. new_browser has the variable name 's'
s.reset!
  1. new_browser refers to 's' more than self (maybe move it to another class?) Locations: 0 1 2
s.host! "moderate.petition.parliament.uk"
  1. new_browser refers to 's' more than self (maybe move it to another class?) Locations: 0 1 2
s.https!
  1. new_browser refers to 's' more than self (maybe move it to another class?) Locations: 0 1 2
end end context "when a new session is created" do it "logs out existing sessions" do
  1. context(when a new session is created)::it#logs out existing sessions has a flog score of 70
s1 = new_browser s1.post "/admin/user_sessions", admin_user_session: login_params expect(s1.response.status).to eq(302) expect(s1.response.headers["Location"]).to eq("https://moderate.petition.parliament.uk/admin") s2 = new_browser s2.post "/admin/user_sessions", admin_user_session: login_params expect(s2.response.status).to eq(302) expect(s2.response.headers["Location"]).to eq("https://moderate.petition.parliament.uk/admin") s1.get("/admin") expect(s1.response.status).to eq(302) expect(s1.response.headers["Location"]).to eq("https://moderate.petition.parliament.uk/admin/login") end end context "when a session is destroyed" do it "resets the persistence token" do
  1. context(when a session is destroyed)::it#resets the persistence token has a flog score of 73
s1 = new_browser s1.post "/admin/user_sessions", admin_user_session: login_params expect(s1.response.status).to eq(302) expect(s1.response.headers["Location"]).to eq("https://moderate.petition.parliament.uk/admin") s2 = new_browser s2.cookies["admin_user_credentials"] = s1.cookies["admin_user_credentials"] s1.get("/admin/logout") expect(s1.response.status).to eq(302) expect(s1.response.headers["Location"]).to eq("https://moderate.petition.parliament.uk/admin/login") s2.get("/admin") expect(s2.response.status).to eq(302) expect(s2.response.headers["Location"]).to eq("https://moderate.petition.parliament.uk/admin/login") end end context "when a session is stale" do before do host! "moderate.petition.parliament.uk" https! end it "resets the persistence token" do
  1. context(when a session is stale)::it#resets the persistence token has a flog score of 64
Site.instance.update(login_timeout: 600) travel_to 5.minutes.ago do
  1. Similar code found in 2 nodes Locations: 0 1
post "/admin/user_sessions", admin_user_session: login_params expect(response).to redirect_to("/admin") end get "/admin" expect(response).to be_successful travel_to 15.minutes.from_now do get "/admin" expect(response).to redirect_to("/admin/login") end Site.instance.update(login_timeout: 1800) travel_to 15.minutes.from_now do get "/admin" expect(response).to redirect_to("/admin/login") end end end end