couchkeeper 0.6.7
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.
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +28 -0
- data/CHANGELOG.md +198 -0
- data/Gemfile +32 -0
- data/MIT-LICENSE +20 -0
- data/README.md +290 -0
- data/Rakefile +18 -0
- data/app/assets/javascripts/doorkeeper/application.js +2 -0
- data/app/assets/stylesheets/doorkeeper/application.css +18 -0
- data/app/assets/stylesheets/doorkeeper/form.css +13 -0
- data/app/controllers/doorkeeper/application_controller.rb +7 -0
- data/app/controllers/doorkeeper/applications_controller.rb +60 -0
- data/app/controllers/doorkeeper/authorizations_controller.rb +57 -0
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +12 -0
- data/app/controllers/doorkeeper/token_info_controller.rb +12 -0
- data/app/controllers/doorkeeper/tokens_controller.rb +20 -0
- data/app/helpers/doorkeeper/form_errors_helper.rb +9 -0
- data/app/validators/redirect_uri_validator.rb +23 -0
- data/app/views/doorkeeper/applications/_form.html.erb +34 -0
- data/app/views/doorkeeper/applications/edit.html.erb +13 -0
- data/app/views/doorkeeper/applications/index.html.erb +29 -0
- data/app/views/doorkeeper/applications/new.html.erb +13 -0
- data/app/views/doorkeeper/applications/show.html.erb +26 -0
- data/app/views/doorkeeper/authorizations/error.html.erb +6 -0
- data/app/views/doorkeeper/authorizations/new.html.erb +37 -0
- data/app/views/doorkeeper/authorizations/show.html.erb +4 -0
- data/app/views/doorkeeper/authorized_applications/index.html.erb +25 -0
- data/app/views/layouts/doorkeeper/application.html.erb +33 -0
- data/config/locales/en.yml +68 -0
- data/doorkeeper.gemspec +28 -0
- data/lib/doorkeeper.rb +64 -0
- data/lib/doorkeeper/config.rb +194 -0
- data/lib/doorkeeper/doorkeeper_for.rb +76 -0
- data/lib/doorkeeper/engine.rb +19 -0
- data/lib/doorkeeper/errors.rb +15 -0
- data/lib/doorkeeper/helpers/controller.rb +58 -0
- data/lib/doorkeeper/helpers/filter.rb +38 -0
- data/lib/doorkeeper/models/access_grant.rb +24 -0
- data/lib/doorkeeper/models/access_token.rb +95 -0
- data/lib/doorkeeper/models/accessible.rb +9 -0
- data/lib/doorkeeper/models/active_record/access_grant.rb +5 -0
- data/lib/doorkeeper/models/active_record/access_token.rb +21 -0
- data/lib/doorkeeper/models/active_record/application.rb +20 -0
- data/lib/doorkeeper/models/application.rb +33 -0
- data/lib/doorkeeper/models/couchbase/access_grant.rb +10 -0
- data/lib/doorkeeper/models/couchbase/access_token.rb +7 -0
- data/lib/doorkeeper/models/couchbase/application.rb +35 -0
- data/lib/doorkeeper/models/doorkeeper_access_grant/by_token/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_application_id/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_application_id_and_resource_owner_id/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_refresh_token/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_resource_owner_id/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_access_token/by_token/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_application/by_uid/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_application/by_uid_and_secret/map.js +5 -0
- data/lib/doorkeeper/models/doorkeeper_application/show_all/map.js +6 -0
- data/lib/doorkeeper/models/expirable.rb +21 -0
- data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +28 -0
- data/lib/doorkeeper/models/mongo_mapper/access_token.rb +51 -0
- data/lib/doorkeeper/models/mongo_mapper/application.rb +30 -0
- data/lib/doorkeeper/models/mongo_mapper/revocable.rb +15 -0
- data/lib/doorkeeper/models/mongoid/revocable.rb +15 -0
- data/lib/doorkeeper/models/mongoid/scopes.rb +15 -0
- data/lib/doorkeeper/models/mongoid2/access_grant.rb +22 -0
- data/lib/doorkeeper/models/mongoid2/access_token.rb +41 -0
- data/lib/doorkeeper/models/mongoid2/application.rb +22 -0
- data/lib/doorkeeper/models/mongoid3/access_grant.rb +22 -0
- data/lib/doorkeeper/models/mongoid3/access_token.rb +41 -0
- data/lib/doorkeeper/models/mongoid3/application.rb +22 -0
- data/lib/doorkeeper/models/ownership.rb +16 -0
- data/lib/doorkeeper/models/scopes.rb +17 -0
- data/lib/doorkeeper/oauth/authorization.rb +10 -0
- data/lib/doorkeeper/oauth/authorization/code.rb +32 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +28 -0
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +29 -0
- data/lib/doorkeeper/oauth/authorization_code_request.rb +82 -0
- data/lib/doorkeeper/oauth/client.rb +29 -0
- data/lib/doorkeeper/oauth/client/credentials.rb +21 -0
- data/lib/doorkeeper/oauth/client/methods.rb +18 -0
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +29 -0
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +35 -0
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +33 -0
- data/lib/doorkeeper/oauth/client_credentials_request.rb +47 -0
- data/lib/doorkeeper/oauth/code_request.rb +28 -0
- data/lib/doorkeeper/oauth/code_response.rb +37 -0
- data/lib/doorkeeper/oauth/error.rb +9 -0
- data/lib/doorkeeper/oauth/error_response.rb +44 -0
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +18 -0
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +13 -0
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +32 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +84 -0
- data/lib/doorkeeper/oauth/pre_authorization.rb +62 -0
- data/lib/doorkeeper/oauth/refresh_token_request.rb +58 -0
- data/lib/doorkeeper/oauth/scopes.rb +60 -0
- data/lib/doorkeeper/oauth/token.rb +36 -0
- data/lib/doorkeeper/oauth/token_request.rb +28 -0
- data/lib/doorkeeper/oauth/token_response.rb +29 -0
- data/lib/doorkeeper/rails/routes.rb +90 -0
- data/lib/doorkeeper/rails/routes/mapper.rb +28 -0
- data/lib/doorkeeper/rails/routes/mapping.rb +39 -0
- data/lib/doorkeeper/request.rb +33 -0
- data/lib/doorkeeper/request/authorization_code.rb +23 -0
- data/lib/doorkeeper/request/client_credentials.rb +23 -0
- data/lib/doorkeeper/request/code.rb +24 -0
- data/lib/doorkeeper/request/password.rb +23 -0
- data/lib/doorkeeper/request/refresh_token.rb +23 -0
- data/lib/doorkeeper/request/token.rb +24 -0
- data/lib/doorkeeper/server.rb +54 -0
- data/lib/doorkeeper/validations.rb +30 -0
- data/lib/doorkeeper/version.rb +3 -0
- data/lib/generators/doorkeeper/application_owner_generator.rb +15 -0
- data/lib/generators/doorkeeper/install_generator.rb +12 -0
- data/lib/generators/doorkeeper/migration_generator.rb +15 -0
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
- data/lib/generators/doorkeeper/templates/README +44 -0
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +7 -0
- data/lib/generators/doorkeeper/templates/indexes.rb +3 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +67 -0
- data/lib/generators/doorkeeper/templates/migration.rb +42 -0
- data/lib/generators/doorkeeper/views_generator.rb +15 -0
- data/script/rails +6 -0
- data/script/run_all +14 -0
- data/spec/controllers/applications_controller_spec.rb +18 -0
- data/spec/controllers/authorizations_controller_spec.rb +154 -0
- data/spec/controllers/protected_resources_controller_spec.rb +304 -0
- data/spec/controllers/token_info_controller_spec.rb +54 -0
- data/spec/controllers/tokens_controller_spec.rb +36 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +7 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +12 -0
- data/spec/dummy/app/controllers/home_controller.rb +17 -0
- data/spec/dummy/app/controllers/metal_controller.rb +11 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +5 -0
- data/spec/dummy/app/models/user.rb +27 -0
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +54 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +15 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +56 -0
- data/spec/dummy/config/initializers/secret_token.rb +9 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/doorkeeper.en.yml +5 -0
- data/spec/dummy/config/mongo.yml +11 -0
- data/spec/dummy/config/mongoid2.yml +9 -0
- data/spec/dummy/config/mongoid3.yml +18 -0
- data/spec/dummy/config/routes.rb +38 -0
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +9 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +5 -0
- data/spec/dummy/db/migrate/20120524202412_create_doorkeeper_tables.rb +44 -0
- data/spec/dummy/db/schema.rb +64 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/access_grant.rb +9 -0
- data/spec/factories/access_token.rb +7 -0
- data/spec/factories/application.rb +6 -0
- data/spec/generators/application_owner_generator_spec.rb +23 -0
- data/spec/generators/install_generator_spec.rb +31 -0
- data/spec/generators/migration_generator_spec.rb +20 -0
- data/spec/generators/templates/routes.rb +3 -0
- data/spec/generators/views_generator_spec.rb +27 -0
- data/spec/lib/config_spec.rb +170 -0
- data/spec/lib/models/expirable_spec.rb +51 -0
- data/spec/lib/models/revocable_spec.rb +31 -0
- data/spec/lib/models/scopes_spec.rb +32 -0
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +37 -0
- data/spec/lib/oauth/authorization_code_request_spec.rb +80 -0
- data/spec/lib/oauth/client/credentials_spec.rb +47 -0
- data/spec/lib/oauth/client/methods_spec.rb +54 -0
- data/spec/lib/oauth/client_credentials/creator_spec.rb +47 -0
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +57 -0
- data/spec/lib/oauth/client_credentials/validation_spec.rb +29 -0
- data/spec/lib/oauth/client_credentials_integration_spec.rb +27 -0
- data/spec/lib/oauth/client_credentials_request_spec.rb +64 -0
- data/spec/lib/oauth/client_spec.rb +39 -0
- data/spec/lib/oauth/code_request_spec.rb +44 -0
- data/spec/lib/oauth/error_response_spec.rb +40 -0
- data/spec/lib/oauth/error_spec.rb +19 -0
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +74 -0
- data/spec/lib/oauth/helpers/unique_token_spec.rb +20 -0
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +64 -0
- data/spec/lib/oauth/password_access_token_request_spec.rb +65 -0
- data/spec/lib/oauth/pre_authorization_spec.rb +80 -0
- data/spec/lib/oauth/refresh_token_request_spec.rb +56 -0
- data/spec/lib/oauth/scopes_spec.rb +115 -0
- data/spec/lib/oauth/token_request_spec.rb +46 -0
- data/spec/lib/oauth/token_response_spec.rb +52 -0
- data/spec/lib/oauth/token_spec.rb +83 -0
- data/spec/lib/server_spec.rb +24 -0
- data/spec/models/doorkeeper/access_grant_spec.rb +36 -0
- data/spec/models/doorkeeper/access_token_spec.rb +153 -0
- data/spec/models/doorkeeper/application_spec.rb +162 -0
- data/spec/requests/applications/applications_request_spec.rb +92 -0
- data/spec/requests/applications/authorized_applications_spec.rb +30 -0
- data/spec/requests/endpoints/authorization_spec.rb +47 -0
- data/spec/requests/endpoints/token_spec.rb +46 -0
- data/spec/requests/flows/authorization_code_errors_spec.rb +66 -0
- data/spec/requests/flows/authorization_code_spec.rb +135 -0
- data/spec/requests/flows/client_credentials_spec.rb +58 -0
- data/spec/requests/flows/implicit_grant_errors_spec.rb +31 -0
- data/spec/requests/flows/implicit_grant_spec.rb +19 -0
- data/spec/requests/flows/password_spec.rb +78 -0
- data/spec/requests/flows/refresh_token_spec.rb +71 -0
- data/spec/requests/flows/skip_authorization_spec.rb +40 -0
- data/spec/requests/protected_resources/metal_spec.rb +14 -0
- data/spec/requests/protected_resources/private_api_spec.rb +50 -0
- data/spec/routing/custom_controller_routes_spec.rb +44 -0
- data/spec/routing/default_routes_spec.rb +32 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_helper_integration.rb +40 -0
- data/spec/support/dependencies/factory_girl.rb +2 -0
- data/spec/support/helpers/access_token_request_helper.rb +11 -0
- data/spec/support/helpers/authorization_request_helper.rb +32 -0
- data/spec/support/helpers/config_helper.rb +9 -0
- data/spec/support/helpers/model_helper.rb +45 -0
- data/spec/support/helpers/request_spec_helper.rb +72 -0
- data/spec/support/helpers/url_helper.rb +51 -0
- data/spec/support/orm/active_record.rb +11 -0
- data/spec/support/orm/mongo_mapper.rb +26 -0
- data/spec/support/orm/mongoid.rb +31 -0
- data/spec/support/shared/controllers_shared_context.rb +60 -0
- data/spec/support/shared/models_shared_examples.rb +60 -0
- data/spec/validators/redirect_uri_validator_spec.rb +47 -0
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +356 -0
- metadata +430 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
require 'generators/doorkeeper/install_generator'
|
3
|
+
|
4
|
+
describe 'Doorkeeper::InstallGenerator' do
|
5
|
+
include GeneratorSpec::TestCase
|
6
|
+
|
7
|
+
tests Doorkeeper::InstallGenerator
|
8
|
+
destination ::File.expand_path("../tmp/dummy", __FILE__)
|
9
|
+
|
10
|
+
describe "after running the generator" do
|
11
|
+
before :each do
|
12
|
+
prepare_destination
|
13
|
+
FileUtils.mkdir(::File.expand_path("config", Pathname(destination_root)))
|
14
|
+
FileUtils.mkdir(::File.expand_path("db", Pathname(destination_root)))
|
15
|
+
FileUtils.copy_file(::File.expand_path("../templates/routes.rb", __FILE__), ::File.expand_path("config/routes.rb", Pathname.new(destination_root)))
|
16
|
+
run_generator
|
17
|
+
end
|
18
|
+
|
19
|
+
it "creates an initializer file" do
|
20
|
+
assert_file 'config/initializers/doorkeeper.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "copies the locale file" do
|
24
|
+
assert_file 'config/locales/doorkeeper.en.yml'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "adds sample route" do
|
28
|
+
assert_file "config/routes.rb", /use_doorkeeper/
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
require 'generators/doorkeeper/migration_generator'
|
3
|
+
|
4
|
+
describe 'Doorkeeper::MigrationGenerator' do
|
5
|
+
include GeneratorSpec::TestCase
|
6
|
+
|
7
|
+
tests Doorkeeper::MigrationGenerator
|
8
|
+
destination ::File.expand_path("../tmp/dummy", __FILE__)
|
9
|
+
|
10
|
+
describe "after running the generator" do
|
11
|
+
before :each do
|
12
|
+
prepare_destination
|
13
|
+
run_generator
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates a migration" do
|
17
|
+
assert_migration "db/migrate/create_doorkeeper_tables.rb"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
require 'generators/doorkeeper/views_generator'
|
3
|
+
|
4
|
+
describe Doorkeeper::Generators::ViewsGenerator do
|
5
|
+
include GeneratorSpec::TestCase
|
6
|
+
|
7
|
+
tests Doorkeeper::Generators::ViewsGenerator
|
8
|
+
destination File.expand_path('../tmp/dummy', __FILE__)
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
prepare_destination
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'create all views' do
|
15
|
+
run_generator
|
16
|
+
assert_file 'app/views/doorkeeper/applications/_form.html.erb'
|
17
|
+
assert_file 'app/views/doorkeeper/applications/edit.html.erb'
|
18
|
+
assert_file 'app/views/doorkeeper/applications/index.html.erb'
|
19
|
+
assert_file 'app/views/doorkeeper/applications/new.html.erb'
|
20
|
+
assert_file 'app/views/doorkeeper/applications/show.html.erb'
|
21
|
+
|
22
|
+
assert_file 'app/views/doorkeeper/authorizations/error.html.erb'
|
23
|
+
assert_file 'app/views/doorkeeper/authorizations/new.html.erb'
|
24
|
+
|
25
|
+
assert_file 'app/views/doorkeeper/authorized_applications/index.html.erb'
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
|
3
|
+
describe Doorkeeper, "configuration" do
|
4
|
+
subject { Doorkeeper.configuration }
|
5
|
+
|
6
|
+
describe "resource_owner_authenticator" do
|
7
|
+
it "sets the block that is accessible via authenticate_resource_owner" do
|
8
|
+
block = proc do end
|
9
|
+
Doorkeeper.configure do
|
10
|
+
orm DOORKEEPER_ORM
|
11
|
+
resource_owner_authenticator &block
|
12
|
+
end
|
13
|
+
subject.authenticate_resource_owner.should == block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "admin_authenticator" do
|
18
|
+
it "sets the block that is accessible via authenticate_admin" do
|
19
|
+
block = proc do end
|
20
|
+
Doorkeeper.configure do
|
21
|
+
orm DOORKEEPER_ORM
|
22
|
+
admin_authenticator &block
|
23
|
+
end
|
24
|
+
subject.authenticate_admin.should == block
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "access_token_expires_in" do
|
29
|
+
it "has 2 hours by default" do
|
30
|
+
subject.access_token_expires_in.should == 2.hours
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can change the value" do
|
34
|
+
Doorkeeper.configure do
|
35
|
+
orm DOORKEEPER_ORM
|
36
|
+
access_token_expires_in 4.hours
|
37
|
+
end
|
38
|
+
subject.access_token_expires_in.should == 4.hours
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can be set to nil" do
|
42
|
+
Doorkeeper.configure do
|
43
|
+
orm DOORKEEPER_ORM
|
44
|
+
access_token_expires_in nil
|
45
|
+
end
|
46
|
+
subject.access_token_expires_in.should be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "scopes" do
|
51
|
+
it "has default scopes" do
|
52
|
+
Doorkeeper.configure {
|
53
|
+
orm DOORKEEPER_ORM
|
54
|
+
default_scopes :public
|
55
|
+
}
|
56
|
+
subject.default_scopes.should include(:public)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'has optional scopes' do
|
60
|
+
Doorkeeper.configure {
|
61
|
+
orm DOORKEEPER_ORM
|
62
|
+
optional_scopes :write, :update
|
63
|
+
}
|
64
|
+
subject.optional_scopes.should include(:write, :update)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'has all scopes' do
|
68
|
+
Doorkeeper.configure do
|
69
|
+
orm DOORKEEPER_ORM
|
70
|
+
default_scopes :normal
|
71
|
+
optional_scopes :admin
|
72
|
+
end
|
73
|
+
subject.scopes.should include(:normal, :admin)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "use_refresh_token" do
|
78
|
+
it "is false by default" do
|
79
|
+
subject.refresh_token_enabled?.should be_false
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can change the value" do
|
83
|
+
Doorkeeper.configure {
|
84
|
+
orm DOORKEEPER_ORM
|
85
|
+
use_refresh_token
|
86
|
+
}
|
87
|
+
subject.refresh_token_enabled?.should be_true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'client_credentials' do
|
92
|
+
it 'has defaults order' do
|
93
|
+
subject.client_credentials_methods.should == [:from_basic, :from_params]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "can change the value" do
|
97
|
+
Doorkeeper.configure {
|
98
|
+
orm DOORKEEPER_ORM
|
99
|
+
client_credentials :from_digest, :from_params
|
100
|
+
}
|
101
|
+
subject.client_credentials_methods.should == [:from_digest, :from_params]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'access_token_credentials' do
|
106
|
+
it 'has defaults order' do
|
107
|
+
subject.access_token_methods.should == [:from_bearer_authorization, :from_access_token_param, :from_bearer_param]
|
108
|
+
end
|
109
|
+
|
110
|
+
it "can change the value" do
|
111
|
+
Doorkeeper.configure {
|
112
|
+
orm DOORKEEPER_ORM
|
113
|
+
access_token_methods :from_access_token_param, :from_bearer_param
|
114
|
+
}
|
115
|
+
subject.access_token_methods.should == [:from_access_token_param, :from_bearer_param]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "enable_application_owner" do
|
120
|
+
it "is disabled by default" do
|
121
|
+
Doorkeeper.configuration.enable_application_owner?.should_not be_true
|
122
|
+
end
|
123
|
+
|
124
|
+
context "when enabled without confirmation" do
|
125
|
+
before do
|
126
|
+
Doorkeeper.configure do
|
127
|
+
orm DOORKEEPER_ORM
|
128
|
+
enable_application_owner
|
129
|
+
end
|
130
|
+
end
|
131
|
+
it "adds support for application owner" do
|
132
|
+
Doorkeeper::Application.new.should respond_to :owner
|
133
|
+
end
|
134
|
+
it "Doorkeeper.configuration.confirm_application_owner? returns false" do
|
135
|
+
Doorkeeper.configuration.confirm_application_owner?.should_not be_true
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "when enabled with confirmation set to true" do
|
140
|
+
before do
|
141
|
+
Doorkeeper.configure do
|
142
|
+
orm DOORKEEPER_ORM
|
143
|
+
enable_application_owner :confirmation => true
|
144
|
+
end
|
145
|
+
end
|
146
|
+
it "adds support for application owner" do
|
147
|
+
Doorkeeper::Application.new.should respond_to :owner
|
148
|
+
end
|
149
|
+
it "Doorkeeper.configuration.confirm_application_owner? returns true" do
|
150
|
+
Doorkeeper.configuration.confirm_application_owner?.should be_true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'raises an exception when configuration is not set' do
|
157
|
+
old_config = Doorkeeper.configuration
|
158
|
+
Doorkeeper.module_eval do
|
159
|
+
@config = nil
|
160
|
+
end
|
161
|
+
|
162
|
+
expect do
|
163
|
+
Doorkeeper.configuration
|
164
|
+
end.to raise_error Doorkeeper::MissingConfiguration
|
165
|
+
|
166
|
+
Doorkeeper.module_eval do
|
167
|
+
@config = old_config
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timecop'
|
3
|
+
require 'active_support/time'
|
4
|
+
require 'doorkeeper/models/expirable'
|
5
|
+
|
6
|
+
describe 'Expirable' do
|
7
|
+
subject do
|
8
|
+
Class.new do
|
9
|
+
include Doorkeeper::Models::Expirable
|
10
|
+
end.new
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
subject.stub :created_at => 1.minute.ago
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :expired? do
|
18
|
+
it "is not expired if time has not passed" do
|
19
|
+
subject.stub :expires_in => 2.minutes
|
20
|
+
subject.should_not be_expired
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is expired if time has passed" do
|
24
|
+
subject.stub :expires_in => 10.seconds
|
25
|
+
subject.should be_expired
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is not expired if expires_in is not set" do
|
29
|
+
subject.stub :expires_in => nil
|
30
|
+
subject.should_not be_expired
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe :expires_in_seconds do
|
35
|
+
it "should return the amount of time remaining until the token is expired" do
|
36
|
+
subject.stub :expires_in => 2.minutes
|
37
|
+
subject.expires_in_seconds.should == 60
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return 0 when expired" do
|
41
|
+
subject.stub :expires_in => 30.seconds
|
42
|
+
subject.expires_in_seconds.should == 0
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return nil when expires_in is nil" do
|
46
|
+
subject.stub :expires_in => nil
|
47
|
+
subject.expires_in_seconds.should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
|
+
require 'doorkeeper/models/revocable'
|
4
|
+
|
5
|
+
describe 'Revocable' do
|
6
|
+
subject do
|
7
|
+
Class.new do
|
8
|
+
include Doorkeeper::Models::Revocable
|
9
|
+
end.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :revoke do
|
13
|
+
it "updates :revoked_at attribute with current time" do
|
14
|
+
clock = double :now => stub
|
15
|
+
subject.should_receive(:update_column).with(:revoked_at, clock.now)
|
16
|
+
subject.revoke(clock)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe :revoked? do
|
21
|
+
it "is revoked if :revoked_at is set" do
|
22
|
+
subject.stub :revoked_at => stub
|
23
|
+
subject.should be_revoked
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is not revoked if :revoked_at is not set" do
|
27
|
+
subject.stub :revoked_at => nil
|
28
|
+
subject.should_not be_revoked
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
3
|
+
require 'doorkeeper/oauth/scopes'
|
4
|
+
require 'doorkeeper/models/scopes'
|
5
|
+
|
6
|
+
describe 'Doorkeeper::Models::Scopes' do
|
7
|
+
subject do
|
8
|
+
Class.new(Hash) do
|
9
|
+
include Doorkeeper::Models::Scopes
|
10
|
+
end.new
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
subject[:scopes] = 'public admin'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :scopes do
|
18
|
+
it 'is a `Scopes` class' do
|
19
|
+
subject.scopes.should be_a(Doorkeeper::OAuth::Scopes)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'includes scopes' do
|
23
|
+
subject.scopes.should include(:public)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe :scopes_string do
|
28
|
+
it 'is a `Scopes` class' do
|
29
|
+
subject.scopes_string.should == 'public admin'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/core_ext/string'
|
3
|
+
require 'uri'
|
4
|
+
require 'rack/utils'
|
5
|
+
require 'doorkeeper/oauth/authorization/uri_builder'
|
6
|
+
|
7
|
+
module Doorkeeper::OAuth::Authorization
|
8
|
+
describe URIBuilder do
|
9
|
+
|
10
|
+
subject { Object.new.class.send :include, URIBuilder }
|
11
|
+
|
12
|
+
describe :uri_with_query do
|
13
|
+
it 'returns the uri with query' do
|
14
|
+
uri = subject.uri_with_query 'http://example.com/', :parameter => 'value'
|
15
|
+
uri.should == 'http://example.com/?parameter=value'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'rejects nil values' do
|
19
|
+
uri = subject.uri_with_query 'http://example.com/', :parameter => ""
|
20
|
+
uri.should == 'http://example.com/?'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'preserves original query parameters' do
|
24
|
+
uri = subject.uri_with_query 'http://example.com/?query1=value', :parameter => 'value'
|
25
|
+
uri.should =~ /query1=value/
|
26
|
+
uri.should =~ /parameter=value/
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe :uri_with_fragment do
|
31
|
+
it 'returns uri with parameters as fragments' do
|
32
|
+
uri = subject.uri_with_fragment 'http://example.com/', :parameter => 'value'
|
33
|
+
uri.should == 'http://example.com/#parameter=value'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper_integration'
|
2
|
+
|
3
|
+
module Doorkeeper::OAuth
|
4
|
+
describe AuthorizationCodeRequest do
|
5
|
+
let(:server) { mock :server, :access_token_expires_in => 2.days, :refresh_token_enabled? => false }
|
6
|
+
let(:grant) { FactoryGirl.create :access_grant }
|
7
|
+
let(:client) { grant.application }
|
8
|
+
|
9
|
+
subject do
|
10
|
+
AuthorizationCodeRequest.new server, grant, client, :redirect_uri => client.redirect_uri
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'issues a new token for the client' do
|
14
|
+
expect do
|
15
|
+
subject.authorize
|
16
|
+
end.to change { client.access_tokens.count }.by(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "issues the token with same grant's scopes" do
|
20
|
+
subject.authorize
|
21
|
+
Doorkeeper::AccessToken.last.scopes.should == grant.scopes
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'revokes the grant' do
|
25
|
+
expect do
|
26
|
+
subject.authorize
|
27
|
+
end.to change { grant.reload.accessible? }
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'requires the grant to be accessible' do
|
31
|
+
grant.revoke
|
32
|
+
subject.validate
|
33
|
+
subject.error.should == :invalid_grant
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'requires the grant' do
|
37
|
+
subject.grant = nil
|
38
|
+
subject.validate
|
39
|
+
subject.error.should == :invalid_grant
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'requires the client' do
|
43
|
+
subject.client = nil
|
44
|
+
subject.validate
|
45
|
+
subject.error.should == :invalid_client
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'requires the redirect_uri' do
|
49
|
+
subject.redirect_uri = nil
|
50
|
+
subject.validate
|
51
|
+
subject.error.should == :invalid_request
|
52
|
+
end
|
53
|
+
|
54
|
+
it "matches the redirect_uri with grant's one" do
|
55
|
+
subject.redirect_uri = 'http://other.com'
|
56
|
+
subject.validate
|
57
|
+
subject.error.should == :invalid_grant
|
58
|
+
end
|
59
|
+
|
60
|
+
it "matches the client with grant's one" do
|
61
|
+
subject.client = FactoryGirl.create :application
|
62
|
+
subject.validate
|
63
|
+
subject.error.should == :invalid_grant
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'skips token creation if there is a matching one' do
|
67
|
+
FactoryGirl.create(:access_token, :application_id => client.id, :resource_owner_id => grant.resource_owner_id, :scopes => "public write")
|
68
|
+
expect do
|
69
|
+
subject.authorize
|
70
|
+
end.to_not change { Doorkeeper::AccessToken.count }
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'revokes matching token if expired' do
|
74
|
+
token = FactoryGirl.create(:access_token, :application_id => client.id, :resource_owner_id => grant.resource_owner_id, :scopes => "public write", :expires_in => -100)
|
75
|
+
expect do
|
76
|
+
subject.authorize
|
77
|
+
end.to change { token.reload.revoked? }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|