2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-08 02:15:45 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Oauth::ApplicationsController do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
context 'project members' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
it 'shows list of applications' do
|
|
|
|
get :index
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-06-08 02:15:45 -04:00
|
|
|
end
|
|
|
|
|
2018-09-21 04:03:00 -04:00
|
|
|
it 'shows list of applications' do
|
2018-09-20 07:02:59 -04:00
|
|
|
disable_user_oauth
|
2016-06-08 02:15:45 -04:00
|
|
|
|
|
|
|
get :index
|
|
|
|
|
2018-09-20 07:02:59 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
it 'creates an application' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :create, params: oauth_params
|
2018-09-20 07:02:59 -04:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(302)
|
|
|
|
expect(response).to redirect_to(oauth_application_path(Doorkeeper::Application.last))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects back to profile page if OAuth applications are disabled' do
|
|
|
|
disable_user_oauth
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :create, params: oauth_params
|
2018-09-20 07:02:59 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2016-06-08 02:15:45 -04:00
|
|
|
expect(response).to redirect_to(profile_path)
|
|
|
|
end
|
2018-11-28 17:53:48 -05:00
|
|
|
|
|
|
|
context 'redirect_uri' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
it 'shows an error for a forbidden URI' do
|
|
|
|
invalid_uri_params = {
|
|
|
|
doorkeeper_application: {
|
|
|
|
name: 'foo',
|
|
|
|
redirect_uri: 'javascript://alert()'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :create, params: invalid_uri_params
|
2018-11-28 17:53:48 -05:00
|
|
|
|
|
|
|
expect(response.body).to include 'Redirect URI is forbidden by the server'
|
|
|
|
end
|
|
|
|
end
|
2016-06-08 02:15:45 -04:00
|
|
|
end
|
|
|
|
end
|
2018-09-20 07:02:59 -04:00
|
|
|
|
|
|
|
def disable_user_oauth
|
|
|
|
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:user_oauth_applications?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def oauth_params
|
|
|
|
{
|
|
|
|
doorkeeper_application: {
|
|
|
|
name: 'foo',
|
|
|
|
redirect_uri: 'http://example.org'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2016-06-08 02:15:45 -04:00
|
|
|
end
|