summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-26 14:34:31 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-26 14:34:31 +0000
commitc85ab58601ab9ac12cd72fa8a96b298875b37039 (patch)
tree165c7a04f5e77f9aa422667f37e901c960019f65 /spec
parent5bc4a1efecfffbd467d7e2e2f42f3f1bf6e6f030 (diff)
downloadgitlab-ce-c85ab58601ab9ac12cd72fa8a96b298875b37039.tar.gz
Add latest changes from gitlab-org/security/gitlab@13-0-stable-ee
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/oauth/authorizations_controller_spec.rb78
-rw-r--r--spec/features/oauth_provider_authorize_spec.rb21
-rw-r--r--spec/support/shared_examples/features/secure_oauth_authorizations_shared_examples.rb19
3 files changed, 86 insertions, 32 deletions
diff --git a/spec/controllers/oauth/authorizations_controller_spec.rb b/spec/controllers/oauth/authorizations_controller_spec.rb
index 1b4bebd9707..f975502ca4e 100644
--- a/spec/controllers/oauth/authorizations_controller_spec.rb
+++ b/spec/controllers/oauth/authorizations_controller_spec.rb
@@ -3,7 +3,6 @@
require 'spec_helper'
describe Oauth::AuthorizationsController do
- let(:user) { create(:user) }
let!(:application) { create(:oauth_application, scopes: 'api read_user', redirect_uri: 'http://example.com') }
let(:params) do
{
@@ -19,53 +18,68 @@ describe Oauth::AuthorizationsController do
end
describe 'GET #new' do
- context 'without valid params' do
- it 'returns 200 code and renders error view' do
- get :new
+ context 'when the user is confirmed' do
+ let(:user) { create(:user) }
- expect(response).to have_gitlab_http_status(:ok)
- expect(response).to render_template('doorkeeper/authorizations/error')
+ context 'without valid params' do
+ it 'returns 200 code and renders error view' do
+ get :new
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template('doorkeeper/authorizations/error')
+ end
end
- end
- context 'with valid params' do
- render_views
+ context 'with valid params' do
+ render_views
- it 'returns 200 code and renders view' do
- get :new, params: params
+ it 'returns 200 code and renders view' do
+ get :new, params: params
- expect(response).to have_gitlab_http_status(:ok)
- expect(response).to render_template('doorkeeper/authorizations/new')
- end
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template('doorkeeper/authorizations/new')
+ end
- it 'deletes session.user_return_to and redirects when skip authorization' do
- application.update(trusted: true)
- request.session['user_return_to'] = 'http://example.com'
+ it 'deletes session.user_return_to and redirects when skip authorization' do
+ application.update(trusted: true)
+ request.session['user_return_to'] = 'http://example.com'
- get :new, params: params
+ get :new, params: params
- expect(request.session['user_return_to']).to be_nil
- expect(response).to have_gitlab_http_status(:found)
- end
+ expect(request.session['user_return_to']).to be_nil
+ expect(response).to have_gitlab_http_status(:found)
+ end
- context 'when there is already an access token for the application' do
- context 'when the request scope matches any of the created token scopes' do
- before do
- scopes = Doorkeeper::OAuth::Scopes.from_string('api')
+ context 'when there is already an access token for the application' do
+ context 'when the request scope matches any of the created token scopes' do
+ before do
+ scopes = Doorkeeper::OAuth::Scopes.from_string('api')
- allow(Doorkeeper.configuration).to receive(:scopes).and_return(scopes)
+ allow(Doorkeeper.configuration).to receive(:scopes).and_return(scopes)
- create :oauth_access_token, application: application, resource_owner_id: user.id, scopes: scopes
- end
+ create :oauth_access_token, application: application, resource_owner_id: user.id, scopes: scopes
+ end
- it 'authorizes the request and redirects' do
- get :new, params: params
+ it 'authorizes the request and redirects' do
+ get :new, params: params
- expect(request.session['user_return_to']).to be_nil
- expect(response).to have_gitlab_http_status(:found)
+ expect(request.session['user_return_to']).to be_nil
+ expect(response).to have_gitlab_http_status(:found)
+ end
end
end
end
end
+
+ context 'when the user is unconfirmed' do
+ let(:user) { create(:user, confirmed_at: nil) }
+
+ it 'returns 200 and renders error view' do
+ get :new, params: params
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template('doorkeeper/authorizations/error')
+ end
+ end
end
end
diff --git a/spec/features/oauth_provider_authorize_spec.rb b/spec/features/oauth_provider_authorize_spec.rb
new file mode 100644
index 00000000000..284fe3b0af9
--- /dev/null
+++ b/spec/features/oauth_provider_authorize_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'OAuth Provider' do
+ describe 'Standard OAuth Authorization' do
+ let(:application) { create(:oauth_application, scopes: 'read_user') }
+
+ before do
+ sign_in(user)
+
+ visit oauth_authorization_path(client_id: application.uid,
+ redirect_uri: application.redirect_uri.split.first,
+ response_type: 'code',
+ state: 'my_state',
+ scope: 'read_user')
+ end
+
+ it_behaves_like 'Secure OAuth Authorizations'
+ end
+end
diff --git a/spec/support/shared_examples/features/secure_oauth_authorizations_shared_examples.rb b/spec/support/shared_examples/features/secure_oauth_authorizations_shared_examples.rb
new file mode 100644
index 00000000000..028e075c87a
--- /dev/null
+++ b/spec/support/shared_examples/features/secure_oauth_authorizations_shared_examples.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'Secure OAuth Authorizations' do
+ context 'when user is confirmed' do
+ let(:user) { create(:user) }
+
+ it 'asks the user to authorize the application' do
+ expect(page).to have_text "Authorize #{application.name} to use your account?"
+ end
+ end
+
+ context 'when user is unconfirmed' do
+ let(:user) { create(:user, confirmed_at: nil) }
+
+ it 'displays an error' do
+ expect(page).to have_text I18n.t('doorkeeper.errors.messages.unconfirmed_email')
+ end
+ end
+end