oauth2_provider_engine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/oauth2_provider/application.js +52 -0
  5. data/app/assets/javascripts/oauth2_provider/highcharts.js +162 -0
  6. data/app/assets/javascripts/oauth2_provider/jquery.tagsinput.js +218 -0
  7. data/app/assets/stylesheets/oauth2_provider/gh-buttons.css +388 -0
  8. data/app/assets/stylesheets/oauth2_provider/gh-icons.png +0 -0
  9. data/app/assets/stylesheets/oauth2_provider/jquery.tagsinput.css +6 -0
  10. data/app/assets/stylesheets/oauth2_provider/reset.css +2 -0
  11. data/app/assets/stylesheets/oauth2_provider/template.css +52 -0
  12. data/app/controllers/oauth2_provider/accesses_controller.rb +39 -0
  13. data/app/controllers/oauth2_provider/application_controller.rb +17 -0
  14. data/app/controllers/oauth2_provider/authorize_controller.rb +141 -0
  15. data/app/controllers/oauth2_provider/clients_controller.rb +85 -0
  16. data/app/controllers/oauth2_provider/scopes_controller.rb +63 -0
  17. data/app/controllers/oauth2_provider/token_controller.rb +187 -0
  18. data/app/helpers/clients_helper.rb +5 -0
  19. data/app/helpers/oauth2_provider/application_helper.rb +4 -0
  20. data/app/models/oauth2_provider/client.rb +129 -0
  21. data/app/models/oauth2_provider/document.rb +15 -0
  22. data/app/models/oauth2_provider/oauth_access.rb +80 -0
  23. data/app/models/oauth2_provider/oauth_authorization.rb +70 -0
  24. data/app/models/oauth2_provider/oauth_daily_request.rb +54 -0
  25. data/app/models/oauth2_provider/oauth_refresh_token.rb +20 -0
  26. data/app/models/oauth2_provider/oauth_token.rb +78 -0
  27. data/app/models/oauth2_provider/scope.rb +39 -0
  28. data/app/views/layouts/oauth2_provider/application.html.erb +62 -0
  29. data/app/views/oauth2_provider/accesses/index.html.erb +25 -0
  30. data/app/views/oauth2_provider/accesses/show.html.erb +35 -0
  31. data/app/views/oauth2_provider/clients/_form.html.erb +50 -0
  32. data/app/views/oauth2_provider/clients/edit.html.erb +9 -0
  33. data/app/views/oauth2_provider/clients/index.html.erb +43 -0
  34. data/app/views/oauth2_provider/clients/new.html.erb +8 -0
  35. data/app/views/oauth2_provider/clients/show.html.erb +49 -0
  36. data/app/views/oauth2_provider/scopes/_form.html.erb +35 -0
  37. data/app/views/oauth2_provider/scopes/edit.html.erb +8 -0
  38. data/app/views/oauth2_provider/scopes/index.html.erb +27 -0
  39. data/app/views/oauth2_provider/scopes/new.html.erb +7 -0
  40. data/app/views/oauth2_provider/scopes/show.html.erb +19 -0
  41. data/app/views/shared/authorize.html.erb +34 -0
  42. data/app/views/shared/token.json.erb +8 -0
  43. data/config/locales/en.yml +31 -0
  44. data/config/oauth.yml +4 -0
  45. data/config/routes.rb +25 -0
  46. data/lib/oauth2_provider.rb +38 -0
  47. data/lib/oauth2_provider/controller_mixin.rb +53 -0
  48. data/lib/oauth2_provider/engine.rb +4 -0
  49. data/lib/oauth2_provider_engine.rb +1 -0
  50. data/lib/oauth2_provider_engine/version.rb +3 -0
  51. data/test/dummy/CHANGELOG.rdoc +67 -0
  52. data/test/dummy/Gemfile +53 -0
  53. data/test/dummy/Gemfile.lock +254 -0
  54. data/test/dummy/README.rdoc +522 -0
  55. data/test/dummy/Rakefile +7 -0
  56. data/test/dummy/VERSION +1 -0
  57. data/test/dummy/app/assets/stylesheets/reset.css +2 -0
  58. data/test/dummy/app/assets/stylesheets/template.css +52 -0
  59. data/test/dummy/app/controllers/application_controller.rb +52 -0
  60. data/test/dummy/app/controllers/pastas_controller.rb +23 -0
  61. data/test/dummy/app/controllers/pizzas_controller.rb +23 -0
  62. data/test/dummy/app/controllers/sessions_controller.rb +26 -0
  63. data/test/dummy/app/controllers/users_controller.rb +59 -0
  64. data/test/dummy/app/models/user.rb +50 -0
  65. data/test/dummy/app/views/layouts/application.html.erb +65 -0
  66. data/test/dummy/app/views/sessions/new.html.erb +25 -0
  67. data/test/dummy/app/views/shared/403.json.erb +4 -0
  68. data/test/dummy/app/views/shared/404.json.erb +6 -0
  69. data/test/dummy/app/views/shared/422.json.erb +5 -0
  70. data/test/dummy/app/views/shared/500.json.erb +4 -0
  71. data/test/dummy/app/views/shared/html/404.html.erb +0 -0
  72. data/test/dummy/app/views/shared/html/422.html.erb +0 -0
  73. data/test/dummy/app/views/users/_form.html.erb +27 -0
  74. data/test/dummy/app/views/users/edit.html.erb +8 -0
  75. data/test/dummy/app/views/users/index.html.erb +20 -0
  76. data/test/dummy/app/views/users/new.html.erb +46 -0
  77. data/test/dummy/app/views/users/show.html.erb +15 -0
  78. data/test/dummy/app/views/users/show.json.erb +6 -0
  79. data/test/dummy/config.ru +4 -0
  80. data/test/dummy/config/application.rb +57 -0
  81. data/test/dummy/config/boot.rb +13 -0
  82. data/test/dummy/config/cucumber.yml +8 -0
  83. data/test/dummy/config/environment.rb +5 -0
  84. data/test/dummy/config/environments/development.rb +32 -0
  85. data/test/dummy/config/environments/production.rb +58 -0
  86. data/test/dummy/config/environments/test.rb +35 -0
  87. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  88. data/test/dummy/config/initializers/inflections.rb +10 -0
  89. data/test/dummy/config/initializers/mime_types.rb +5 -0
  90. data/test/dummy/config/initializers/secret_token.rb +7 -0
  91. data/test/dummy/config/initializers/session_store.rb +8 -0
  92. data/test/dummy/config/initializers/test.rb +3 -0
  93. data/test/dummy/config/locales/en.yml +1 -0
  94. data/test/dummy/config/mongoid.yml +20 -0
  95. data/test/dummy/config/routes.rb +22 -0
  96. data/test/dummy/db/seeds.rb +7 -0
  97. data/test/dummy/doc/README_FOR_APP +2 -0
  98. data/test/dummy/lib/tasks/cucumber.rake +53 -0
  99. data/test/dummy/lib/tasks/watchr.rake +5 -0
  100. data/test/dummy/public/404.html +26 -0
  101. data/test/dummy/public/422.html +26 -0
  102. data/test/dummy/public/500.html +4 -0
  103. data/test/dummy/public/favicon.ico +0 -0
  104. data/test/dummy/public/robots.txt +5 -0
  105. data/test/dummy/script/cucumber +10 -0
  106. data/test/dummy/script/rails +6 -0
  107. data/test/dummy/spec/acceptance/acceptance_helper.rb +5 -0
  108. data/test/dummy/spec/acceptance/accesses_controller_spec.rb +77 -0
  109. data/test/dummy/spec/acceptance/clients_controller_spec.rb +218 -0
  110. data/test/dummy/spec/acceptance/oauth_authorize_controller_spec.rb +241 -0
  111. data/test/dummy/spec/acceptance/oauth_token_controller_spec.rb +196 -0
  112. data/test/dummy/spec/acceptance/resource_controller_spec.rb +143 -0
  113. data/test/dummy/spec/acceptance/scopes_controller_spec.rb +227 -0
  114. data/test/dummy/spec/acceptance/support/helpers.rb +81 -0
  115. data/test/dummy/spec/acceptance/support/paths.rb +9 -0
  116. data/test/dummy/spec/acceptance/support/view_helpers.rb +52 -0
  117. data/test/dummy/spec/acceptance/users_controller_spec.rb +198 -0
  118. data/test/dummy/spec/extras/scope_spec.rb +105 -0
  119. data/test/dummy/spec/factories/oauth.rb +106 -0
  120. data/test/dummy/spec/models/oauth/client_spec.rb +123 -0
  121. data/test/dummy/spec/models/oauth/oauth_access_spec.rb +48 -0
  122. data/test/dummy/spec/models/oauth/oauth_authorization_spec.rb +50 -0
  123. data/test/dummy/spec/models/oauth/oauth_daily_request_spec.rb +14 -0
  124. data/test/dummy/spec/models/oauth/oauth_refresh_token_spec.rb +11 -0
  125. data/test/dummy/spec/models/oauth/oauth_token_spec.rb +55 -0
  126. data/test/dummy/spec/models/scope_spec.rb +17 -0
  127. data/test/dummy/spec/spec_helper.rb +39 -0
  128. data/test/dummy/spec/support/settings_helper.rb +28 -0
  129. data/test/dummy/test/initializers/capybara_headers_hack.rb +23 -0
  130. data/test/oauth2_provider_test.rb +7 -0
  131. data/test/test_helper.rb +15 -0
  132. metadata +387 -0
@@ -0,0 +1,106 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../support/settings_helper')
2
+ include SettingsHelper
3
+
4
+ FactoryGirl.define do
5
+
6
+ factory :user do
7
+ email "alice@example.com"
8
+ password "example"
9
+ admin false
10
+ end
11
+
12
+ factory :user_bob, class: User do
13
+ email "bob@example.com"
14
+ password "example"
15
+ admin false
16
+ end
17
+
18
+ factory :admin, class: User do
19
+ email "admin@example.com"
20
+ password "example"
21
+ admin true
22
+ end
23
+
24
+ factory :oauth_access, class: Oauth2Provider::OauthAccess do
25
+ client_uri CLIENT_URI
26
+ resource_owner_uri USER_URI
27
+ end
28
+
29
+
30
+ factory :oauth_authorization, class: Oauth2Provider::OauthAuthorization do
31
+ client_uri CLIENT_URI
32
+ resource_owner_uri USER_URI
33
+ scope ALL_SCOPE
34
+ end
35
+
36
+
37
+ factory :oauth_token, class: Oauth2Provider::OauthToken do
38
+ client_uri CLIENT_URI
39
+ resource_owner_uri USER_URI
40
+ scope ALL_SCOPE
41
+ end
42
+
43
+ factory :oauth_token_read, parent: :oauth_token do
44
+ scope READ_SCOPE
45
+ end
46
+
47
+
48
+ factory :client, class: Oauth2Provider::Client do
49
+ uri CLIENT_URI
50
+ name "the client"
51
+ created_from USER_URI
52
+ redirect_uri REDIRECT_URI
53
+ scope ["pizzas"]
54
+ scope_values ALL_SCOPE
55
+ end
56
+
57
+ factory :client_read, parent: :client do
58
+ uri ANOTHER_CLIENT_URI
59
+ scope ["pizzas/read"]
60
+ scope_values READ_SCOPE
61
+ end
62
+
63
+ factory :client_not_owned, parent: :client do
64
+ name "Not owned client"
65
+ created_from ANOTHER_USER_URI
66
+ end
67
+
68
+
69
+ factory :scope, class: Oauth2Provider::Scope do
70
+ uri SCOPE_URI
71
+ name "pizzas"
72
+ end
73
+
74
+ factory :scope_pizzas_read, parent: :scope do
75
+ name "pizzas/read"
76
+ values ["pizzas/index", "pizzas/show"]
77
+ end
78
+
79
+ factory :scope_pizzas_all, parent: :scope do
80
+ name "pizzas"
81
+ values ["pizzas/read", "pizzas/create", "pizzas/update", "pizzas/destroy"]
82
+ end
83
+
84
+ factory :scope_pastas_read, parent: :scope do
85
+ name "pastas/read"
86
+ values ["pastas/index", "pastas/show"]
87
+ end
88
+
89
+ factory :scope_pastas_all, parent: :scope do
90
+ name "pastas"
91
+ values ["pastas/create", "pastas/update", "pastas/destroy", "pastas/read"]
92
+ end
93
+
94
+ factory :scope_read, parent: :scope do
95
+ name "read"
96
+ values ["pizzas/read", "pastas/read"]
97
+ end
98
+
99
+ factory :scope_all, parent: :scope do
100
+ name "all"
101
+ values ["pizzas", "pastas"]
102
+ end
103
+
104
+ end
105
+
106
+
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+ module Oauth2Provider
3
+ describe Client do
4
+ before { @client = FactoryGirl.create(:client) }
5
+ subject { @client }
6
+
7
+ it { should validate_presence_of(:name) }
8
+ it { should validate_presence_of(:uri) }
9
+ it { VALID_URIS.each{|uri| should allow_value(uri).for(:uri) } }
10
+ it { should validate_presence_of(:created_from) }
11
+ it { VALID_URIS.each{|uri| should allow_value(uri).for(:created_from) } }
12
+ it { should validate_presence_of(:redirect_uri) }
13
+ it { VALID_URIS.each{|uri| should allow_value(uri).for(:redirect_uri) } }
14
+
15
+ its(:secret) { should_not be_nil }
16
+
17
+ it ".granted!" do
18
+ lambda{ subject.granted! }.should change{ subject.granted_times }.by(1)
19
+ end
20
+
21
+ it ".revoked!" do
22
+ lambda{ subject.revoked! }.should change{ subject.revoked_times }.by(1)
23
+ end
24
+
25
+ it { should_not be_blocked }
26
+ context "#block!" do
27
+ before { @authorization = FactoryGirl.create(:oauth_authorization) }
28
+ before { @another_authorization = FactoryGirl.create(:oauth_authorization, client_uri: ANOTHER_CLIENT_URI) }
29
+ before { @token = FactoryGirl.create(:oauth_token) }
30
+ before { @another_token = FactoryGirl.create(:oauth_token, client_uri: ANOTHER_CLIENT_URI) }
31
+
32
+ before { subject.block! }
33
+
34
+ it { should be_blocked }
35
+ it { @authorization.reload.should be_blocked }
36
+ it { @another_authorization.reload.should_not be_blocked }
37
+ it { @token.reload.should be_blocked }
38
+ it { @another_token.reload.should_not be_blocked }
39
+
40
+ context "#unblock!" do
41
+ before { subject.unblock! }
42
+
43
+ it { should_not be_blocked }
44
+ it { @authorization.reload.should be_blocked }
45
+ it { @token.reload.should be_blocked }
46
+ end
47
+ end
48
+
49
+ context ".find_by_secret" do
50
+ let(:found) { Client.where_secret(subject.secret, subject.uri).first }
51
+ it { found.should_not be_nil }
52
+ end
53
+
54
+ context ".where_scope" do
55
+ context "with complete scope" do
56
+ let(:scope) { ALL_SCOPE }
57
+ subject { Client.where_scope(scope).first }
58
+ it { should_not be_nil }
59
+ end
60
+
61
+ context "with partial scope" do
62
+ let(:scope) { ["pizzas/show", "pizzas/create"] }
63
+ subject { Client.where_scope(scope).first }
64
+ it { should_not be_nil }
65
+ end
66
+
67
+ context "with invalid scope" do
68
+ let(:scope) { ["type.write", "reresource.not_existingg"] }
69
+ subject { Client.where_scope(scope).first }
70
+ it { should be_nil }
71
+ end
72
+ end
73
+
74
+ context "#destroy" do
75
+ subject { FactoryGirl.create(:client) }
76
+ before do
77
+ OauthAuthorization.destroy_all
78
+ 3.times { FactoryGirl.create(:oauth_authorization) }
79
+ OauthToken.destroy_all
80
+ 3.times { FactoryGirl.create(:oauth_token) }
81
+ end
82
+
83
+ it "should remove related authorizations" do
84
+ lambda{ subject.destroy }.should change{
85
+ OauthAuthorization.all.size
86
+ }.by(-3)
87
+ end
88
+
89
+ it "should remove related tokens" do
90
+ lambda{ subject.destroy }.should change{
91
+ OauthToken.all.size
92
+ }.by(-3)
93
+ end
94
+ end
95
+
96
+ context ".sync_clients_with_scope" do
97
+ before { Client.destroy_all }
98
+ before { Scope.destroy_all }
99
+
100
+ before { @client = FactoryGirl.create(:client) }
101
+ before { @read_client = FactoryGirl.create(:client_read) }
102
+ before { @scope = FactoryGirl.create(:scope_pizzas_all) }
103
+ before { @scope_read = FactoryGirl.create(:scope_pizzas_read, values: ["pizzas/show"]) }
104
+ before { Client.sync_clients_with_scope("pizzas/read") }
105
+
106
+ context "with indirect scope" do
107
+ subject { @client.reload.scope_values }
108
+ it { should include "pizzas/show" }
109
+ it { should include "pizzas/create" }
110
+ it { should include "pizzas/update" }
111
+ it { should include "pizzas/destroy" }
112
+ it { should_not include "pizzas/index" }
113
+ end
114
+
115
+ context "with direct scope" do
116
+ subject { @read_client.reload.scope_values }
117
+ it { should include "pizzas/show" }
118
+ it { should_not include "pizzas/index" }
119
+ end
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Oauth2Provider::OauthAccess do
4
+ before { @access = FactoryGirl.create(:oauth_access) }
5
+ subject { @access }
6
+
7
+ it { should validate_presence_of(:client_uri) }
8
+ it { should validate_presence_of(:resource_owner_uri) }
9
+ it { should_not be_blocked }
10
+
11
+ context "#block!" do
12
+ before { @authorization = FactoryGirl.create(:oauth_authorization) }
13
+ before { @another_authorization = FactoryGirl.create(:oauth_authorization, client_uri: ANOTHER_CLIENT_URI) }
14
+ before { @token = FactoryGirl.create(:oauth_token) }
15
+ before { @another_token = FactoryGirl.create(:oauth_token, client_uri: ANOTHER_CLIENT_URI) }
16
+
17
+ before { subject.block! }
18
+
19
+ it { should be_blocked }
20
+ it { @authorization.reload.should be_blocked }
21
+ it { @another_authorization.reload.should_not be_blocked }
22
+ it { @token.reload.should be_blocked }
23
+ it { @another_token.reload.should_not be_blocked }
24
+
25
+ context "#unblock!" do
26
+ before { subject.unblock! }
27
+
28
+ it { should_not be_blocked }
29
+ it { @authorization.reload.should be_blocked }
30
+ it { @token.reload.should be_blocked }
31
+ end
32
+ end
33
+
34
+ context "when increment access" do
35
+ let(:today) { Chronic.parse("today at midday") }
36
+ let(:tomorrow) { Chronic.parse("tomorrow at midday") }
37
+
38
+ it "should create or increment the daily requests counter" do
39
+ Delorean.time_travel_to today
40
+ 3.times { @access.accessed! }
41
+ @access.daily_requests.times.should == 3
42
+ Delorean.time_travel_to tomorrow
43
+ @access.accessed!
44
+ @access.daily_requests.times.should == 1
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Oauth2Provider::OauthAuthorization do
4
+ before { @authorization = FactoryGirl.create(:oauth_authorization) }
5
+ subject { @authorization }
6
+
7
+ it { should validate_presence_of(:client_uri) }
8
+ it { VALID_URIS.each{|uri| should allow_value(uri).for(:client_uri) } }
9
+ it { should validate_presence_of(:resource_owner_uri) }
10
+ it { VALID_URIS.each{|uri| should allow_value(uri).for(:resource_owner_uri) } }
11
+
12
+ its(:code) { should_not be_nil }
13
+ its(:expire_at) { should_not be_nil }
14
+
15
+ it { should_not be_blocked }
16
+ context "#block" do
17
+ before { subject.block! }
18
+ it { should be_blocked }
19
+ end
20
+
21
+ context ".block_client!" do
22
+ before { @another_client_authorization = FactoryGirl.create(:oauth_authorization, client_uri: ANOTHER_CLIENT_URI) }
23
+ before { Oauth2Provider::OauthAuthorization.block_client!(CLIENT_URI) }
24
+
25
+ it { @authorization.reload.should be_blocked }
26
+ it { @another_client_authorization.reload.should_not be_blocked }
27
+ end
28
+
29
+ context ".block_access!" do
30
+ before { @another_client_authorization = FactoryGirl.create(:oauth_authorization, client_uri: ANOTHER_CLIENT_URI)}
31
+ before { @another_owner_authorization = FactoryGirl.create(:oauth_authorization, resource_owner_uri: ANOTHER_USER_URI) }
32
+ before { Oauth2Provider::OauthAuthorization.block_access!(CLIENT_URI, USER_URI) }
33
+
34
+ it { @authorization.reload.should be_blocked }
35
+ it { @another_client_authorization.reload.should_not be_blocked }
36
+ it { @another_owner_authorization.reload.should_not be_blocked }
37
+ end
38
+
39
+ it "#expired?" do
40
+ subject.should_not be_expired
41
+ Delorean.time_travel_to("in 151 seconds")
42
+ subject.should be_expired
43
+ end
44
+
45
+ it ".where_code_and_client_uri" do
46
+ result = Oauth2Provider::OauthAuthorization.where_code_and_client_uri(subject.code, subject.client_uri).first
47
+ result.should == subject
48
+ end
49
+
50
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Oauth2Provider::OauthToken do
4
+
5
+ let(:access) { FactoryGirl.create(:oauth_access) }
6
+ let(:time) { Chronic.parse("17 august 1982") }
7
+ let(:day_requests) { access.daily_requests(time) }
8
+
9
+ its(:day) { day_requests.day.should == "17" }
10
+ its(:month) { day_requests.month.should == "08" }
11
+ its(:year) { day_requests.year.should == "1982" }
12
+ its(:time_id) { day_requests.time_id.should == "19820817" }
13
+
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Oauth2Provider::OauthRefreshToken do
4
+ before { @token = FactoryGirl.create(:oauth_token) }
5
+ before { @refresh_token = Oauth2Provider::OauthRefreshToken.create(access_token: @token.token) }
6
+ subject { @refresh_token }
7
+
8
+ it { should validate_presence_of :access_token }
9
+
10
+ its(:refresh_token) {should_not be_nil }
11
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Oauth2Provider::OauthToken do
4
+ before { @token = FactoryGirl.create(:oauth_token) }
5
+ subject { @token }
6
+
7
+ it { should validate_presence_of(:client_uri) }
8
+ it { VALID_URIS.each{|uri| should allow_value(uri).for(:client_uri) } }
9
+ it { should validate_presence_of(:resource_owner_uri) }
10
+ it { VALID_URIS.each{|uri| should allow_value(uri).for(:resource_owner_uri) } }
11
+
12
+ its(:token) { should_not be_nil }
13
+ its(:refresh_token) { should_not be_nil }
14
+ it { should_not be_blocked }
15
+
16
+ context "#block!" do
17
+ before { subject.block! }
18
+ it { should be_blocked }
19
+ end
20
+
21
+ context ".block_client!" do
22
+ before { @another_client_token = FactoryGirl.create(:oauth_token, client_uri: ANOTHER_CLIENT_URI) }
23
+ before { Oauth2Provider::OauthToken.block_client!(CLIENT_URI) }
24
+
25
+ it { @token.reload.should be_blocked }
26
+ it { @another_client_token.should_not be_blocked }
27
+ end
28
+
29
+ context ".block_access!" do
30
+ before { @another_client_token = FactoryGirl.create(:oauth_token, client_uri: ANOTHER_CLIENT_URI)}
31
+ before { @another_owner_token = FactoryGirl.create(:oauth_token, resource_owner_uri: ANOTHER_USER_URI) }
32
+ before { Oauth2Provider::OauthToken.block_access!(CLIENT_URI, USER_URI) }
33
+
34
+ it { @token.reload.should be_blocked }
35
+ it { @another_client_token.should_not be_blocked }
36
+ it { @another_owner_token.should_not be_blocked }
37
+ end
38
+
39
+ context ".exist" do
40
+ it "should find the token" do
41
+ existing = Oauth2Provider::OauthToken.exist(@token.client_uri,
42
+ @token.resource_owner_uri,
43
+ @token.scope).first
44
+ existing.should_not be_nil
45
+ end
46
+ end
47
+
48
+
49
+ it "#expired?" do
50
+ subject.should_not be_expired
51
+ Delorean.time_travel_to("in #{Oauth2Provider.settings["token_expires_in"]} seconds")
52
+ subject.should be_expired
53
+ end
54
+
55
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Oauth2Provider::Scope do
4
+ before { @scope = FactoryGirl.create(:scope, values: ALL_SCOPE) }
5
+ subject { @scope }
6
+
7
+ it { should validate_presence_of(:name) }
8
+ it { should validate_presence_of(:name) }
9
+
10
+ it { VALID_URIS.each{|uri| should allow_value(uri).for(:uri) } }
11
+ it { INVALID_URIS.each{|uri| should_not allow_value(uri).for(:uri) } }
12
+
13
+ it { should_not allow_mass_assignment_of(:values) }
14
+ it { should_not allow_mass_assignment_of(:uri) }
15
+
16
+ its(:values) { should be_a_kind_of Array }
17
+ end
@@ -0,0 +1,39 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
9
+
10
+ # Require shared examples ruby files
11
+ Dir[Rails.root.join("spec/**/shared/*.rb")].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+
15
+ # Include helpers and global vars
16
+ config.include SettingsHelper
17
+
18
+ # Include extra rspec matchers
19
+ config.include Mongoid::Matchers
20
+
21
+ # Include time travel methods
22
+ config.include Delorean
23
+
24
+ # Mock library
25
+ config.mock_with :rspec
26
+
27
+ # User cleanup before each test
28
+ config.before(:each) do
29
+ User.destroy_all
30
+ end
31
+
32
+ # Cleaning up MongoDB afterspecs have ben executed
33
+ config.after :suite do
34
+ Mongoid.master.collections.select do |collection|
35
+ collection.name !~ /system/
36
+ end.each(&:drop)
37
+ end
38
+
39
+ end