Skip to content

Commit 131a0d0

Browse files
committed
Brain dump cache related behavior
This is the spec outline for how I believe the new caching layer should behave. From this we can see there is some overlap in behavior across the states. Additionally, it seems we may have some slight adjustments to the existing behavior. I believe we can prove that everything is backwards compatible though, so it should not be an issue.
1 parent 83bee50 commit 131a0d0

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

spec/kracken/controllers/token_authenticatable_spec.rb

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ module Kracken
44
class TokenAuthController < BaseControllerDouble
55
include Kracken::Controllers::TokenAuthenticatable
66
public :authenticate_user_with_token!
7-
public :current_user
7+
# The module includes things as private so that they are not accidentally
8+
# exposed as controller routes. However, we really treat some of them as the
9+
# "public" API for the module:
10+
public :current_auth_info,
11+
:current_team_ids,
12+
:current_user,
13+
:current_user_id
814

915
def authenticate_or_request_with_http_token(realm = nil)
1016
/\AToken token="(?<token>.*)"\z/ =~ request.env['HTTP_AUTHORIZATION']
@@ -14,11 +20,36 @@ def authenticate_or_request_with_http_token(realm = nil)
1420

1521
RSpec.describe Controllers::TokenAuthenticatable do
1622
describe "authenticating via a token" do
23+
context "on a cache hit" do
24+
it "munges the request headers to support parameterized tokens"
25+
it "leaves the request header unchange when with no parameterized token"
26+
it "uses the exising cache to bypass the authentication process"
27+
it "returns the auth info"
28+
it "exposes the auth info via the `current_` helpers"
29+
it "lazy loads the current user"
30+
end
31+
32+
context "on a cache miss with an invalid token" do
33+
it "munges the request headers to support parameterized tokens"
34+
it "leaves the request header unchange when with no parameterized token"
35+
it "follows the token authentication process"
36+
it "returns nil"
37+
it "doesn't cache invalid tokens"
38+
end
39+
1740
context "on a cache miss with a valid token" do
1841
before do
1942
allow(Authenticator).to receive(:user_with_token)
2043
end
2144

45+
it "follows the token authentication process"
46+
it "returns the auth info"
47+
it "exposes the auth info via the `current_` helpers"
48+
it "sets the auth info as the cache value"
49+
it "sets the cache expiration to one minute by default"
50+
it "sets the cache expiration to the environment setting `KRACKEN_TOKEN_TTL` when available"
51+
it "eager loads the current user"
52+
2253
it "munges the request headers to support parameterized tokens" do
2354
controller = TokenAuthController.new
2455
controller.request.env = {

0 commit comments

Comments
 (0)