summaryrefslogtreecommitdiff
path: root/spec/support/api/scopes/read_user_shared_examples.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/api/scopes/read_user_shared_examples.rb')
-rw-r--r--spec/support/api/scopes/read_user_shared_examples.rb67
1 files changed, 57 insertions, 10 deletions
diff --git a/spec/support/api/scopes/read_user_shared_examples.rb b/spec/support/api/scopes/read_user_shared_examples.rb
index bb5f493f3fd..cae6099a0c2 100644
--- a/spec/support/api/scopes/read_user_shared_examples.rb
+++ b/spec/support/api/scopes/read_user_shared_examples.rb
@@ -1,21 +1,68 @@
shared_examples_for 'allows the "read_user" scope' do
- describe 'when the requesting token has the "read_user" scope' do
- let(:token) { create(:personal_access_token, scopes: ['read_user'], user: user) }
+ context 'for personal access tokens' do
+ context 'when the requesting token has the "api" scope' do
+ let(:token) { create(:personal_access_token, scopes: ['api'], user: user) }
+
+ it 'returns a "200" response' do
+ get api_call.call(path, user, personal_access_token: token)
+
+ expect(response).to have_http_status(200)
+ end
+ end
+
+ context 'when the requesting token has the "read_user" scope' do
+ let(:token) { create(:personal_access_token, scopes: ['read_user'], user: user) }
- it 'returns a "200" response' do
- get api_call.call(path, user, personal_access_token: token)
+ it 'returns a "200" response' do
+ get api_call.call(path, user, personal_access_token: token)
- expect(response).to have_http_status(200)
+ expect(response).to have_http_status(200)
+ end
+ end
+
+ context 'when the requesting token does not have any required scope' do
+ let(:token) { create(:personal_access_token, scopes: ['read_registry'], user: user) }
+
+ it 'returns a "401" response' do
+ get api_call.call(path, user, personal_access_token: token)
+
+ expect(response).to have_http_status(401)
+ end
end
end
- describe 'when the requesting token does not have any required scope' do
- let(:token) { create(:personal_access_token, scopes: ['read_registry'], user: user) }
+ context 'for doorkeeper (OAuth) tokens' do
+ let!(:user) {create(:user)}
+ let!(:application) { Doorkeeper::Application.create!(name: "MyApp", redirect_uri: "https://app.com", owner: user) }
- it 'returns a "401" response' do
- get api_call.call(path, user, personal_access_token: token)
+ context 'when the requesting token has the "api" scope' do
+ let!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id, scopes: "api" }
- expect(response).to have_http_status(401)
+ it 'returns a "200" response' do
+ get api_call.call(path, user, oauth_access_token: token)
+
+ expect(response).to have_http_status(200)
+ end
+ end
+
+ context 'when the requesting token has the "read_user" scope' do
+ let!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id, scopes: "read_user" }
+
+ it 'returns a "200" response' do
+ get api_call.call(path, user, oauth_access_token: token)
+
+ expect(response).to have_http_status(200)
+ end
+ end
+
+ context 'when the requesting token does not have any required scope' do
+ let!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id, scopes: "invalid" }
+
+ it 'returns a "403" response' do
+ get api_call.call(path, user, oauth_access_token: token)
+
+ expect(response).to have_http_status(403)
+ end
end
end
end