Skip to content

Commit

Permalink
Log out when client cookie set to non existing customer (hotfix)
Browse files Browse the repository at this point in the history
In normal circumstances this should not happen, but here we reset production data. Which may cause some people left with a cookie set.
  • Loading branch information
andrzejkrzywda committed Jan 7, 2024
1 parent e240d37 commit 6906ed5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rails_application/app/controllers/client/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class OrdersController < ApplicationController
layout 'client_panel'

def index
if ClientOrders::Client.find_by(uid: cookies[:client_id]).nil?
redirect_to logout_path
return
end
render html: ClientOrders::OrdersList.build(view_context, cookies[:client_id]), layout: true
end

Expand Down
11 changes: 11 additions & 0 deletions rails_application/test/integration/login_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def test_login_with_incorrect_password
refute cookies["client_id"].present?
end

def test_cookies_set_to_not_existing_customer_should_log_out_and_redirect_to_login
cookies["client_id"] = "not-existing-customer"

get "/client_orders"
follow_redirect!
follow_redirect!

refute cookies["client_id"].present?
assert_equal "/clients", response.original_url
end

private

def set_password(customer_id, password)
Expand Down

0 comments on commit 6906ed5

Please sign in to comment.