@@ -14,53 +14,55 @@ def authenticate_or_request_with_http_token(realm = nil)
14
14
15
15
RSpec . describe Controllers ::TokenAuthenticatable do
16
16
describe "authenticating via a token" do
17
- before do
18
- allow ( Authenticator ) . to receive ( :user_with_token )
19
- end
17
+ context "on a cache miss with a valid token" do
18
+ before do
19
+ allow ( Authenticator ) . to receive ( :user_with_token )
20
+ end
20
21
21
- it "munges the request headers to support parameterized tokens" do
22
- controller = TokenAuthController . new
23
- controller . request . env = {
24
- 'HTTP_AUTHORIZATION' => 'Token token="header token"'
25
- }
26
- controller . params = { token : "param token" }
22
+ it "munges the request headers to support parameterized tokens" do
23
+ controller = TokenAuthController . new
24
+ controller . request . env = {
25
+ 'HTTP_AUTHORIZATION' => 'Token token="header token"'
26
+ }
27
+ controller . params = { token : "param token" }
27
28
28
- expect {
29
- controller . authenticate_user_with_token!
30
- } . to change {
31
- controller . request . env
32
- } . from (
33
- 'HTTP_AUTHORIZATION' => 'Token token="header token"'
34
- ) . to (
35
- 'HTTP_AUTHORIZATION' => 'Token token="param token"'
36
- )
37
- end
29
+ expect {
30
+ controller . authenticate_user_with_token!
31
+ } . to change {
32
+ controller . request . env
33
+ } . from (
34
+ 'HTTP_AUTHORIZATION' => 'Token token="header token"'
35
+ ) . to (
36
+ 'HTTP_AUTHORIZATION' => 'Token token="param token"'
37
+ )
38
+ end
38
39
39
- it "leaves the request header unchange when with no parameterized token" do
40
- controller = TokenAuthController . new
41
- controller . request . env = {
42
- 'HTTP_AUTHORIZATION' => 'Token token="any token"'
43
- }
40
+ it "leaves the request header unchange when with no parameterized token" do
41
+ controller = TokenAuthController . new
42
+ controller . request . env = {
43
+ 'HTTP_AUTHORIZATION' => 'Token token="any token"'
44
+ }
44
45
45
- expect {
46
- controller . authenticate_user_with_token!
47
- } . not_to change { controller . request . env } . from (
48
- 'HTTP_AUTHORIZATION' => 'Token token="any token"'
49
- )
50
- end
46
+ expect {
47
+ controller . authenticate_user_with_token!
48
+ } . not_to change { controller . request . env } . from (
49
+ 'HTTP_AUTHORIZATION' => 'Token token="any token"'
50
+ )
51
+ end
51
52
52
- it "authenticates the current user via the token" do
53
- a_user = instance_double ( User )
54
- allow ( Authenticator ) . to receive ( :user_with_token ) . with ( "any token" )
55
- . and_return ( a_user )
56
- controller = TokenAuthController . new
57
- controller . request . env = {
58
- 'HTTP_AUTHORIZATION' => 'Token token="any token"'
59
- }
53
+ it "authenticates the current user via the token" do
54
+ a_user = instance_double ( User )
55
+ allow ( Authenticator ) . to receive ( :user_with_token ) . with ( "any token" )
56
+ . and_return ( a_user )
57
+ controller = TokenAuthController . new
58
+ controller . request . env = {
59
+ 'HTTP_AUTHORIZATION' => 'Token token="any token"'
60
+ }
60
61
61
- expect {
62
- controller . authenticate_user_with_token!
63
- } . to change { controller . current_user } . from ( nil ) . to ( a_user )
62
+ expect {
63
+ controller . authenticate_user_with_token!
64
+ } . to change { controller . current_user } . from ( nil ) . to ( a_user )
65
+ end
64
66
end
65
67
end
66
68
end
0 commit comments