devise_oauth2_providable 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,6 @@ require 'expirable_token'
2
2
 
3
3
  class AuthorizationCode < ActiveRecord::Base
4
4
  include ExpirableToken
5
-
6
5
  def access_token
7
6
  @access_token ||= expired! && user.access_tokens.create(:client => client)
8
7
  end
@@ -12,7 +12,7 @@ module Devise
12
12
  t.string :secret
13
13
  t.timestamps
14
14
  end
15
- migration.add_index :clients, :identifier
15
+ migration.add_index :clients, :identifier, :unique => true
16
16
 
17
17
  migration.create_table :access_tokens do |t|
18
18
  t.belongs_to :user, :client, :refresh_token
@@ -20,7 +20,7 @@ module Devise
20
20
  t.datetime :expires_at
21
21
  t.timestamps
22
22
  end
23
- migration.add_index :access_tokens, :token
23
+ migration.add_index :access_tokens, :token, :unique => true
24
24
  migration.add_index :access_tokens, :expires_at
25
25
  migration.add_index :access_tokens, :user_id
26
26
  migration.add_index :access_tokens, :client_id
@@ -31,7 +31,7 @@ module Devise
31
31
  t.datetime :expires_at
32
32
  t.timestamps
33
33
  end
34
- migration.add_index :refresh_tokens, :token
34
+ migration.add_index :refresh_tokens, :token, :unique => true
35
35
  migration.add_index :refresh_tokens, :expires_at
36
36
  migration.add_index :refresh_tokens, :user_id
37
37
  migration.add_index :refresh_tokens, :client_id
@@ -43,7 +43,7 @@ module Devise
43
43
  t.string :redirect_uri
44
44
  t.timestamps
45
45
  end
46
- migration.add_index :authorization_codes, :token
46
+ migration.add_index :authorization_codes, :token, :unique => true
47
47
  migration.add_index :authorization_codes, :expires_at
48
48
  migration.add_index :authorization_codes, :user_id
49
49
  migration.add_index :authorization_codes, :client_id
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module Oauth2Providable
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
@@ -24,7 +24,7 @@ ActiveRecord::Schema.define(:version => 20110511210926) do
24
24
 
25
25
  add_index "access_tokens", ["client_id"], :name => "index_access_tokens_on_client_id"
26
26
  add_index "access_tokens", ["expires_at"], :name => "index_access_tokens_on_expires_at"
27
- add_index "access_tokens", ["token"], :name => "index_access_tokens_on_token"
27
+ add_index "access_tokens", ["token"], :name => "index_access_tokens_on_token", :unique => true
28
28
  add_index "access_tokens", ["user_id"], :name => "index_access_tokens_on_user_id"
29
29
 
30
30
  create_table "authorization_codes", :force => true do |t|
@@ -39,7 +39,7 @@ ActiveRecord::Schema.define(:version => 20110511210926) do
39
39
 
40
40
  add_index "authorization_codes", ["client_id"], :name => "index_authorization_codes_on_client_id"
41
41
  add_index "authorization_codes", ["expires_at"], :name => "index_authorization_codes_on_expires_at"
42
- add_index "authorization_codes", ["token"], :name => "index_authorization_codes_on_token"
42
+ add_index "authorization_codes", ["token"], :name => "index_authorization_codes_on_token", :unique => true
43
43
  add_index "authorization_codes", ["user_id"], :name => "index_authorization_codes_on_user_id"
44
44
 
45
45
  create_table "clients", :force => true do |t|
@@ -52,7 +52,7 @@ ActiveRecord::Schema.define(:version => 20110511210926) do
52
52
  t.datetime "updated_at"
53
53
  end
54
54
 
55
- add_index "clients", ["identifier"], :name => "index_clients_on_identifier"
55
+ add_index "clients", ["identifier"], :name => "index_clients_on_identifier", :unique => true
56
56
 
57
57
  create_table "refresh_tokens", :force => true do |t|
58
58
  t.integer "user_id"
@@ -65,7 +65,7 @@ ActiveRecord::Schema.define(:version => 20110511210926) do
65
65
 
66
66
  add_index "refresh_tokens", ["client_id"], :name => "index_refresh_tokens_on_client_id"
67
67
  add_index "refresh_tokens", ["expires_at"], :name => "index_refresh_tokens_on_expires_at"
68
- add_index "refresh_tokens", ["token"], :name => "index_refresh_tokens_on_token"
68
+ add_index "refresh_tokens", ["token"], :name => "index_refresh_tokens_on_token", :unique => true
69
69
  add_index "refresh_tokens", ["user_id"], :name => "index_refresh_tokens_on_user_id"
70
70
 
71
71
  create_table "users", :force => true do |t|
@@ -15,6 +15,13 @@ describe ProtectedController do
15
15
  end
16
16
  it { should respond_with :ok }
17
17
  end
18
+ context 'with valid bearer token in query string' do
19
+ before do
20
+ get :index, :bearer_token => @token.token, :format => 'json'
21
+ end
22
+ it { should respond_with :ok }
23
+ end
24
+
18
25
  context 'with invalid bearer token in query param' do
19
26
  before do
20
27
  get :index, :bearer_token => 'invalid', :format => 'json'
@@ -23,10 +30,13 @@ describe ProtectedController do
23
30
  end
24
31
  context 'with valid bearer token in header and query string' do
25
32
  before do
26
- @request.env['HTTP_AUTHORIZATION'] = "Bearer #{@token.token}"
27
- get :index, :bearer_token => @token.token, :format => 'json'
28
33
  end
29
- it { should respond_with :unauthorized }
34
+ it 'raises error' do
35
+ lambda {
36
+ @request.env['HTTP_AUTHORIZATION'] = "Bearer #{@token.token}"
37
+ get :index, :bearer_token => @token.token, :format => 'json'
38
+ }.should raise_error
39
+ end
30
40
  end
31
41
  end
32
42
  end
@@ -16,7 +16,7 @@ describe AccessToken do
16
16
  it { should allow_mass_assignment_of :refresh_token }
17
17
  it { should have_db_index :client_id }
18
18
  it { should have_db_index :user_id }
19
- it { should have_db_index :token }
19
+ it { should have_db_index(:token).unique(true) }
20
20
  it { should have_db_index :expires_at }
21
21
  end
22
22
 
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe AuthorizationCode do
4
+ describe 'basic authorization code instance' do
5
+ subject do
6
+ client = Client.create! :name => 'test', :redirect_uri => 'http://localhost:3000', :website => 'http://localhost'
7
+ AuthorizationCode.create! :client => client
8
+ end
9
+ it { should validate_presence_of :token }
10
+ it { should validate_uniqueness_of :token }
11
+ it { should belong_to :user }
12
+ it { should belong_to :client }
13
+ it { should validate_presence_of :client }
14
+ it { should validate_presence_of :expires_at }
15
+ it { should have_db_index :client_id }
16
+ it { should have_db_index :user_id }
17
+ it { should have_db_index(:token).unique(true) }
18
+ it { should have_db_index :expires_at }
19
+ end
20
+ end
21
+
@@ -8,5 +8,6 @@ describe Client do
8
8
  it { should validate_presence_of :redirect_uri }
9
9
  it { should validate_uniqueness_of :identifier }
10
10
  it { should have_many :refresh_tokens }
11
+ it { should have_db_index(:identifier).unique(true) }
11
12
  end
12
13
  end
@@ -15,7 +15,7 @@ describe RefreshToken do
15
15
  it { should have_many :access_tokens }
16
16
  it { should have_db_index :client_id }
17
17
  it { should have_db_index :user_id }
18
- it { should have_db_index :token }
18
+ it { should have_db_index(:token).unique(true) }
19
19
  it { should have_db_index :expires_at }
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_oauth2_providable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Sonnek
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-18 00:00:00 Z
18
+ date: 2011-05-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails
@@ -164,6 +164,7 @@ files:
164
164
  - spec/rails_app/spec/controllers/protected_controller_spec.rb
165
165
  - spec/rails_app/spec/integration/token_endpoint_spec.rb
166
166
  - spec/rails_app/spec/models/access_token_spec.rb
167
+ - spec/rails_app/spec/models/authorization_code_spec.rb
167
168
  - spec/rails_app/spec/models/client_spec.rb
168
169
  - spec/rails_app/spec/models/refresh_token_spec.rb
169
170
  - spec/rails_app/spec/models/user_spec.rb
@@ -253,6 +254,7 @@ test_files:
253
254
  - spec/rails_app/spec/controllers/protected_controller_spec.rb
254
255
  - spec/rails_app/spec/integration/token_endpoint_spec.rb
255
256
  - spec/rails_app/spec/models/access_token_spec.rb
257
+ - spec/rails_app/spec/models/authorization_code_spec.rb
256
258
  - spec/rails_app/spec/models/client_spec.rb
257
259
  - spec/rails_app/spec/models/refresh_token_spec.rb
258
260
  - spec/rails_app/spec/models/user_spec.rb