diff options
author | Marin Jankovski <maxlazio@gmail.com> | 2014-12-29 11:30:55 +0300 |
---|---|---|
committer | Marin Jankovski <maxlazio@gmail.com> | 2014-12-29 11:30:55 +0300 |
commit | 42fb42aed4cc30d101e81fa5934d9f1b9521dfce (patch) | |
tree | 2efa529fe83f7d06d815bd153ae1ea9f8e1f4b7a /spec | |
parent | 1c089a8561556377dccbf661a3016cac2329c713 (diff) | |
parent | 6cf501004b54c1b311ea7c6c364cfb4a88c1060b (diff) |
Merge branch 'master' into developer_can_push_to_protected_branches_option
Conflicts:
db/schema.rb
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/api_helpers_spec.rb | 1 | ||||
-rw-r--r-- | spec/requests/api/doorkeeper_access_spec.rb | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/spec/requests/api/api_helpers_spec.rb b/spec/requests/api/api_helpers_spec.rb index e2f222c0d34..cc071342d7c 100644 --- a/spec/requests/api/api_helpers_spec.rb +++ b/spec/requests/api/api_helpers_spec.rb @@ -41,6 +41,7 @@ describe API, api: true do describe ".current_user" do it "should return nil for an invalid token" do env[API::APIHelpers::PRIVATE_TOKEN_HEADER] = 'invalid token' + self.class.any_instance.stub(:doorkeeper_guard){ false } current_user.should be_nil end diff --git a/spec/requests/api/doorkeeper_access_spec.rb b/spec/requests/api/doorkeeper_access_spec.rb new file mode 100644 index 00000000000..ddef99d77af --- /dev/null +++ b/spec/requests/api/doorkeeper_access_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe API::API, api: true do + include ApiHelpers + + let!(:user) { create(:user) } + let!(:application) { Doorkeeper::Application.create!(:name => "MyApp", :redirect_uri => "https://app.com", :owner => user) } + let!(:token) { Doorkeeper::AccessToken.create! :application_id => application.id, :resource_owner_id => user.id } + + + describe "when unauthenticated" do + it "returns authentication success" do + get api("/user"), :access_token => token.token + response.status.should == 200 + end + end + + describe "when token invalid" do + it "returns authentication error" do + get api("/user"), :access_token => "123a" + response.status.should == 401 + end + end + + describe "authorization by private token" do + it "returns authentication success" do + get api("/user", user) + response.status.should == 200 + end + end +end |