Skip to content

Commit 8f7e6d7

Browse files
Updates specs, and adds manifest file for CI
1 parent a6ebd4c commit 8f7e6d7

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

lib/kracken/controllers/authenticatable.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Authenticatable
66

77
def self.included(base)
88
base.instance_exec do
9-
before_action :handle_user_cache_cookie!
9+
before_action :handle_user_cache_key!
1010
before_action :authenticate_user!
1111
helper_method :sign_out_path, :sign_up_path, :sign_in_path,
1212
:current_user, :user_signed_in?
@@ -64,13 +64,12 @@ def check_token_expiry!
6464
#
6565
# This method will:
6666
#
67-
# - Check for the `_radius_user_cache_key` tld cookie
68-
# - If the key is "none" log them out
67+
# - Check for the presence of a user cache key in Redis
6968
# - Compare it to the `user_cache_key` in the session
7069
# - If they don't match, redirect them to the oauth provider and
71-
# delete the cookie
70+
# delete the session
7271
#
73-
def handle_user_cache_cookie!
72+
def handle_user_cache_key!
7473
return unless session_present?
7574
return if session_and_redis_match?
7675

spec/kracken/controllers/authenticatable_spec.rb

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -136,47 +136,34 @@ class ControllerDouble < BaseControllerDouble
136136
expect(controller).to_not have_received(:redirect_to)
137137
end
138138

139-
context "user cache cookie" do
140-
it "nothing if the cache cookie does not exist" do
141-
allow(controller).to receive(:request).and_return(double(format: nil, fullpath: nil))
142-
allow(controller).to receive(:redirect_to)
139+
context "user cache key" do
140+
it "ends session and redirects if stored key does not match session key" do
143141
controller.session[:user_cache_key] = "123"
142+
controller.session[:user_uid] = "123"
144143

145-
controller.handle_user_cache_cookie!
146-
147-
expect(controller).to_not have_received(:redirect_to)
148-
end
149-
150-
it "signs the current user out when the cache cookie is 'none'" do
151144
allow(controller).to receive(:request).and_return(double(format: nil, fullpath: nil))
152145
allow(controller).to receive(:redirect_to)
153-
controller.cookies[:_radius_user_cache_key] = "123"
154-
controller.session[:user_cache_key] = "123"
146+
allow(Kracken::SessionManager).to receive(:get).and_return("456")
155147

156-
controller.handle_user_cache_cookie!
148+
expect(controller).to receive(:redirect_to).with("/")
149+
expect(controller.session).to receive(:delete).with(:user_id)
150+
expect(controller.session).to receive(:delete).with(:user_uid)
151+
expect(controller.session).to receive(:delete).with(:user_cache_key)
157152

158-
expect(controller).to_not have_received(:redirect_to)
153+
controller.handle_user_cache_key!
159154
end
160155

161-
it "redirects when the cache cookie is different than the session" do
162-
allow(controller).to receive(:request).and_return(double(format: nil, fullpath: nil))
163-
allow(controller).to receive(:cookies).and_return({_radius_user_cache_key: "123"})
164-
allow(controller).to receive(:redirect_to)
165-
controller.handle_user_cache_cookie!
166-
167-
expect(controller).to have_received(:redirect_to).with("/")
168-
end
156+
it "does nothing if session keys match" do
157+
controller.session[:user_cache_key] = "123"
158+
controller.session[:user_uid] = "123"
169159

170-
it "does not redirect when the cache cookie matches the session" do
171-
controller.session = spy
160+
allow(controller).to receive(:request).and_return(double(format: nil, fullpath: nil))
172161
allow(controller).to receive(:redirect_to)
173-
controller.cookies[:_radius_user_cache_key] = "none"
162+
allow(Kracken::SessionManager).to receive(:get).and_return("123")
174163

175-
controller.handle_user_cache_cookie!
164+
expect(controller).to_not receive(:redirect_to).with("/")
176165

177-
expect(controller).to_not have_received(:redirect_to)
178-
expect(controller.session).to have_received(:delete).with(:user_id)
179-
expect(controller.session).to have_received(:delete).with(:user_cache_key)
166+
controller.handle_user_cache_key!
180167
end
181168
end
182169
end

0 commit comments

Comments
 (0)