Commit ed5a02c9 authored by Rubén Dávila's avatar Rubén Dávila

Make reject_unsigned_commits rule work for Silver and Gold plans.

Also fix some broken specs
parent 58126159
......@@ -116,7 +116,6 @@ class License < ActiveRecord::Base
multiple_ldap_servers
object_storage
repository_size_limit
reject_unsigned_commits
].freeze
validate :valid_license
......
......@@ -22,7 +22,7 @@ class PushRule < ActiveRecord::Base
end
def commit_signature_allowed?(commit)
return true unless License.feature_available?(:reject_unsigned_commits)
return true unless available?(:reject_unsigned_commits)
return true unless reject_unsigned_commits
commit.has_signature?
......@@ -75,6 +75,14 @@ class PushRule < ActiveRecord::Base
is_sample?
end
def available?(feature_sym)
if global?
License.feature_available?(feature_sym)
else
project&.feature_available?(feature_sym)
end
end
private
def data_match?(data, regex)
......
- return unless License.feature_available?(:reject_unsigned_commits)
- return unless push_rule.available?(:reject_unsigned_commits)
- form = local_assigns.fetch(:form)
- push_rule = local_assigns.fetch(:push_rule)
......
require 'spec_helper'
feature 'Projects > Push Rules', :js do
let(:user) { create(:user) }
let(:project) { create(:project, :repository, namespace: user.namespace) }
before do
project.team << [user, :master]
sign_in(user)
end
describe 'Reject unsigned commits rule' do
context 'unlicensed' do
before do
stub_licensed_features(reject_unsigned_commits: false)
end
it 'does not render the setting checkbox' do
visit project_settings_repository_path(project)
expect(page).not_to have_content('Reject unsigned commits')
end
end
context 'licensed' do
let(:bronze_plan) { Plan.find_by!(name: 'bronze') }
let(:gold_plan) { Plan.find_by!(name: 'gold') }
before do
stub_licensed_features(reject_unsigned_commits: true)
end
it 'renders the setting checkbox' do
visit project_settings_repository_path(project)
expect(page).to have_content('Reject unsigned commits')
end
describe 'with GL.com plans' do
before do
stub_application_setting(check_namespace_plan: true)
end
context 'when disabled' do
it 'does not render the setting checkbox' do
project.namespace.update!(plan_id: bronze_plan.id)
visit project_settings_repository_path(project)
expect(page).not_to have_content('Reject unsigned commits')
end
end
context 'when enabled' do
it 'renders the setting checkbox' do
project.namespace.update!(plan_id: gold_plan.id)
visit project_settings_repository_path(project)
expect(page).to have_content('Reject unsigned commits')
end
end
end
end
end
end
......@@ -371,6 +371,10 @@ describe Gitlab::Checks::ChangeAccess do
end
context 'GPG sign rules' do
before do
stub_licensed_features(reject_unsigned_commits: true)
end
let(:push_rule) { create(:push_rule, reject_unsigned_commits: true) }
it_behaves_like 'check ignored when push rule unlicensed'
......
......@@ -49,6 +49,7 @@ describe PushRule do
end
describe '#commit_signature_allowed?' do
let!(:premium_license) { create(:license, plan: License::PREMIUM_PLAN) }
let(:signed_commit) { double(has_signature?: true) }
let(:unsigned_commit) { double(has_signature?: false) }
......@@ -135,4 +136,65 @@ describe PushRule do
end
end
end
describe '#available?' do
shared_examples 'an unavailable push_rule' do
it 'is not available' do
expect(push_rule.available?(:reject_unsigned_commits)).to eq(false)
end
end
shared_examples 'an available push_rule' do
it 'is available' do
expect(push_rule.available?(:reject_unsigned_commits)).to eq(true)
end
end
describe 'reject_unsigned_commits' do
context 'with the global push_rule' do
let(:push_rule) { create(:push_rule_sample) }
context 'with a EE starter license' do
let!(:license) { create(:license, plan: License::STARTER_PLAN) }
it_behaves_like 'an unavailable push_rule'
end
context 'with a EE premium license' do
let!(:license) { create(:license, plan: License::PREMIUM_PLAN) }
it_behaves_like 'an available push_rule'
end
end
context 'with GL.com plans' do
let(:group) { create(:group, plan: Plan.find_by!(name: gl_plan)) }
let(:project) { create(:project, namespace: group) }
let(:push_rule) { create(:push_rule, project: project) }
before do
create(:license, plan: License::PREMIUM_PLAN)
stub_application_setting(check_namespace_plan: true)
end
context 'with a Bronze plan' do
let(:gl_plan) { ::EE::Namespace::BRONZE_PLAN }
it_behaves_like 'an unavailable push_rule'
end
context 'with a Silver plan' do
let(:gl_plan) { ::EE::Namespace::SILVER_PLAN }
it_behaves_like 'an available push_rule'
end
context 'with a Gold plan' do
let(:gl_plan) { ::EE::Namespace::GOLD_PLAN }
it_behaves_like 'an available push_rule'
end
end
end
end
end
......@@ -14,11 +14,11 @@ RSpec.configure do |config|
end
config.before(:each, :js) do
DatabaseCleaner.strategy = :truncation, { except: ['licenses'] }
DatabaseCleaner.strategy = :truncation, { except: %w[licenses plans] }
end
config.before(:each, :truncate) do
DatabaseCleaner.strategy = :truncation, { except: ['licenses'] }
DatabaseCleaner.strategy = :truncation, { except: %w[licenses plans] }
end
config.before(:each, :migration) do
......
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