debian-mirror-gitlab/spec/controllers/admin/applications_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

156 lines
4.8 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Admin::ApplicationsController do
2017-08-17 22:00:37 +05:30
let(:admin) { create(:admin) }
let(:application) { create(:oauth_application, owner_id: nil, owner_type: nil) }
before do
sign_in(admin)
end
2019-12-04 20:38:33 +05:30
describe 'GET #index' do
render_views
it 'renders the application form' do
get :index
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-12-04 20:38:33 +05:30
end
end
2017-08-17 22:00:37 +05:30
describe 'GET #new' do
it 'renders the application form' do
get :new
expect(response).to render_template :new
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
end
end
describe 'GET #edit' do
it 'renders the application form' do
2019-02-15 15:39:39 +05:30
get :edit, params: { id: application.id }
2017-08-17 22:00:37 +05:30
expect(response).to render_template :edit
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
end
end
2023-05-27 22:25:52 +05:30
describe 'PUT #renew' do
let(:oauth_params) do
{
id: application.id
}
end
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
subject { put :renew, params: oauth_params }
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
it { is_expected.to have_gitlab_http_status(:ok) }
it { expect { subject }.to change { application.reload.secret } }
2022-10-11 01:57:18 +05:30
2023-06-20 00:43:36 +05:30
it 'returns the secret in json format' do
subject
expect(json_response['secret']).not_to be_nil
end
2023-05-27 22:25:52 +05:30
context 'when renew fails' do
2022-10-11 01:57:18 +05:30
before do
2023-05-27 22:25:52 +05:30
allow_next_found_instance_of(Doorkeeper::Application) do |application|
allow(application).to receive(:save).and_return(false)
end
2022-10-11 01:57:18 +05:30
end
2023-05-27 22:25:52 +05:30
it { expect { subject }.not_to change { application.reload.secret } }
2023-06-20 00:43:36 +05:30
it { is_expected.to have_gitlab_http_status(:unprocessable_entity) }
2023-05-27 22:25:52 +05:30
end
end
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
describe 'POST #create' do
it 'creates the application' do
create_params = attributes_for(:application, trusted: true, confidential: false, scopes: ['api'])
2017-08-17 22:00:37 +05:30
2023-05-27 22:25:52 +05:30
expect do
post :create, params: { doorkeeper_application: create_params }
end.to change { Doorkeeper::Application.count }.by(1)
2017-08-17 22:00:37 +05:30
2023-05-27 22:25:52 +05:30
application = Doorkeeper::Application.last
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template :show
expect(application).to have_attributes(create_params.except(:uid, :owner_type))
2017-08-17 22:00:37 +05:30
end
it 'renders the application form on errors' do
expect do
2019-02-15 15:39:39 +05:30
post :create, params: { doorkeeper_application: attributes_for(:application).merge(redirect_uri: nil) }
2017-08-17 22:00:37 +05:30
end.not_to change { Doorkeeper::Application.count }
expect(response).to render_template :new
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
end
2020-03-13 15:44:24 +05:30
context 'when the params are for a confidential application' do
2023-05-27 22:25:52 +05:30
it 'creates a confidential application' do
create_params = attributes_for(:application, confidential: true, scopes: ['read_user'])
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
expect do
post :create, params: { doorkeeper_application: create_params }
end.to change { Doorkeeper::Application.count }.by(1)
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
application = Doorkeeper::Application.last
2022-10-11 01:57:18 +05:30
2023-05-27 22:25:52 +05:30
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template :show
expect(application).to have_attributes(create_params.except(:uid, :owner_type))
2020-03-13 15:44:24 +05:30
end
end
2020-09-03 11:15:55 +05:30
context 'when scopes are not present' do
it 'renders the application form on errors' do
create_params = attributes_for(:application, trusted: true, confidential: false)
expect do
post :create, params: { doorkeeper_application: create_params }
end.not_to change { Doorkeeper::Application.count }
expect(response).to render_template :new
end
end
2017-08-17 22:00:37 +05:30
end
describe 'PATCH #update' do
it 'updates the application' do
2020-03-13 15:44:24 +05:30
doorkeeper_params = { redirect_uri: 'http://example.com/', trusted: true, confidential: false }
patch :update, params: { id: application.id, doorkeeper_application: doorkeeper_params }
2017-09-10 17:25:29 +05:30
application.reload
2017-08-17 22:00:37 +05:30
expect(response).to redirect_to(admin_application_path(application))
2020-03-13 15:44:24 +05:30
expect(application)
.to have_attributes(redirect_uri: 'http://example.com/', trusted: true, confidential: false)
2017-08-17 22:00:37 +05:30
end
it 'renders the application form on errors' do
2019-02-15 15:39:39 +05:30
patch :update, params: { id: application.id, doorkeeper_application: { redirect_uri: nil } }
2017-08-17 22:00:37 +05:30
expect(response).to render_template :edit
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
end
2020-03-13 15:44:24 +05:30
context 'when updating the application to be confidential' do
it 'successfully sets the application to confidential' do
doorkeeper_params = { confidential: true }
patch :update, params: { id: application.id, doorkeeper_application: doorkeeper_params }
expect(response).to redirect_to(admin_application_path(application))
expect(application).to be_confidential
end
end
2017-08-17 22:00:37 +05:30
end
end