debian-mirror-gitlab/spec/controllers/projects/settings/access_tokens_controller_spec.rb

54 lines
1.5 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require('spec_helper')
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::Settings::AccessTokensController do
2020-05-24 23:13:21 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
2021-01-03 14:25:43 +05:30
let_it_be(:bot_user) { create(:user, :project_bot) }
2020-05-24 23:13:21 +05:30
before_all do
project.add_maintainer(user)
2021-01-03 14:25:43 +05:30
project.add_maintainer(bot_user)
2020-05-24 23:13:21 +05:30
end
before do
sign_in(user)
end
2021-01-03 14:25:43 +05:30
shared_examples 'feature unavailable' do
context 'user is not a maintainer' do
2020-05-24 23:13:21 +05:30
before do
2021-01-03 14:25:43 +05:30
project.add_developer(user)
2020-05-24 23:13:21 +05:30
end
it { is_expected.to have_gitlab_http_status(:not_found) }
end
end
describe '#index' do
subject { get :index, params: { namespace_id: project.namespace, project_id: project } }
2021-01-03 14:25:43 +05:30
it_behaves_like 'feature unavailable'
it_behaves_like 'project access tokens available #index'
2020-05-24 23:13:21 +05:30
end
2021-01-03 14:25:43 +05:30
describe '#create' do
let(:access_token_params) { { name: 'Nerd bot', scopes: ["api"], expires_at: Date.today + 1.month } }
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
subject { post :create, params: { namespace_id: project.namespace, project_id: project }.merge(project_access_token: access_token_params) }
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
it_behaves_like 'feature unavailable'
it_behaves_like 'project access tokens available #create'
2020-05-24 23:13:21 +05:30
end
2021-01-03 14:25:43 +05:30
describe '#revoke', :sidekiq_inline do
let(:project_access_token) { create(:personal_access_token, user: bot_user) }
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
subject { put :revoke, params: { namespace_id: project.namespace, project_id: project, id: project_access_token } }
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
it_behaves_like 'feature unavailable'
it_behaves_like 'project access tokens available #revoke'
2020-05-24 23:13:21 +05:30
end
end