Commit ab9e5cc1 authored by James Edwards-Jones's avatar James Edwards-Jones

GithubService license check

parent b9e08d97
......@@ -3,6 +3,7 @@ class Projects::ServicesController < Projects::ApplicationController
# Authorize
before_action :authorize_admin_project!
before_action :ensure_service_enabled
before_action :service, only: [:edit, :update, :test]
respond_to :html
......@@ -54,4 +55,8 @@ class Projects::ServicesController < Projects::ApplicationController
def service
@service ||= @project.find_or_initialize_service(params[:id])
end
def ensure_service_enabled
render_404 unless service
end
end
......@@ -451,6 +451,10 @@ module EE
disabled_services.push('jenkins', 'jenkins_deprecated')
end
unless feature_available?(:github_project_service_integration)
disabled_services.push('github')
end
disabled_services
end
end
......
......@@ -42,6 +42,7 @@ class License < ActiveRecord::Base
external_files_in_gitlab_ci
file_locks
geo
github_project_service_integration
group_issue_boards
jira_dev_panel_integration
ldap_group_sync_filter
......
......@@ -51,6 +51,8 @@ class GithubService < Service
end
def execute(data)
return if disabled?
status_message = StatusMessage.from_pipeline_data(project, data)
update_status(status_message)
......@@ -80,6 +82,10 @@ class GithubService < Service
private
def disabled?
project.disabled_services.include?(to_param)
end
def update_status(status_message)
notifier.notify(status_message.sha,
status_message.status,
......
......@@ -7,20 +7,40 @@ describe 'User activates GitHub Service' do
before do
project.add_master(user)
sign_in(user)
end
context 'without a license' do
it "is excluded from the integrations index" do
visit project_settings_integrations_path(project)
expect(page).not_to have_link('GitHub')
end
visit(project_settings_integrations_path(project))
it 'renders 404 when trying to access service settings directly' do
visit edit_project_service_path(project, :github)
click_link('GitHub')
expect(page).to have_gitlab_http_status(404)
end
end
it 'activates service' do
check('Active')
fill_in "Token", with: "aaaaaaaaaa"
fill_in "Api url", with: "https://api.github.com"
fill_in "Owner", with: "h5bp"
fill_in "Repository name", with: "html5-boilerplate"
click_button('Save')
context 'with valid license' do
before do
stub_licensed_features(github_project_service_integration: true)
visit project_settings_integrations_path(project)
click_link('GitHub')
end
it 'activates service' do
check('Active')
fill_in "Token", with: "aaaaaaaaaa"
fill_in "Api url", with: "https://api.github.com"
fill_in "Owner", with: "h5bp"
fill_in "Repository name", with: "html5-boilerplate"
click_button('Save')
expect(page).to have_content('GitHub activated.')
expect(page).to have_content('GitHub activated.')
end
end
end
......@@ -23,6 +23,10 @@ describe GithubService do
subject { described_class.create(service_params) }
before do
stub_licensed_features(github_project_service_integration: true)
end
describe "Associations" do
it { is_expected.to belong_to :project }
end
......@@ -143,6 +147,16 @@ describe GithubService do
subject.execute(pipeline_sample_data)
end
end
context 'without a license' do
it 'does nothing' do
stub_licensed_features(github_project_service_integration: false)
result = subject.execute(pipeline_sample_data)
expect(result).to be_nil
end
end
end
describe '#can_test?' do
......@@ -196,5 +210,15 @@ describe GithubService do
expect(result[:success]).to eq false
expect(result[:result].to_s).to end_with('401 - Bad credentials')
end
context 'without a license' do
it 'fails gracefully' do
stub_licensed_features(github_project_service_integration: false)
result = subject.test(pipeline_sample_data)
expect(result[:success]).to eq false
end
end
end
end
......@@ -22,6 +22,5 @@ describe 'User views services' do
expect(page).to have_content('Asana')
expect(page).to have_content('Irker (IRC gateway)')
expect(page).to have_content('Packagist')
expect(page).to have_content('GitHub')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment