Commit 16462e82 authored by Corinna Wiesner's avatar Corinna Wiesner Committed by Douglas Barbosa Alexandre

Support new gitlab-license gem version

parent 94fbd217
......@@ -300,7 +300,7 @@ gem 'gon', '~> 6.4.0'
gem 'request_store', '~> 1.5'
gem 'base32', '~> 0.3.0'
gem "gitlab-license", "~> 1.4"
gem 'gitlab-license', '~> 1.5'
# Protect against bruteforcing
gem 'rack-attack', '~> 6.3.0'
......
......@@ -474,7 +474,7 @@ GEM
opentracing (~> 0.4)
pg_query (~> 1.3)
redis (> 3.0.0, < 5.0.0)
gitlab-license (1.4.0)
gitlab-license (1.5.0)
gitlab-mail_room (0.0.9)
gitlab-markup (1.7.1)
gitlab-net-dns (0.9.1)
......@@ -1454,7 +1454,7 @@ DEPENDENCIES
gitlab-fog-azure-rm (~> 1.0.1)
gitlab-fog-google (~> 1.13)
gitlab-labkit (~> 0.16.2)
gitlab-license (~> 1.4)
gitlab-license (~> 1.5)
gitlab-mail_room (~> 0.0.9)
gitlab-markup (~> 1.7.1)
gitlab-net-dns (~> 0.9.1)
......
......@@ -552,7 +552,11 @@ class License < ApplicationRecord
end
def cloud_license?
license&.type == CLOUD_LICENSE_TYPE
!!license&.cloud_licensing?
end
def usage_ping?
!!license&.usage_ping_required_metrics?
end
def license_type
......
......@@ -23,7 +23,7 @@ RSpec.describe Admin::LicensesController do
context 'when the license is for a cloud license' do
it 'redirects back' do
license = build_license(type: 'cloud')
license = build_license(cloud_licensing_enabled: true)
expect do
post :create, params: { license: { data: license.data } }
......@@ -69,14 +69,19 @@ RSpec.describe Admin::LicensesController do
end
end
def build_license(type: nil, restrictions: {})
def build_license(cloud_licensing_enabled: false, restrictions: {})
license_restrictions = {
trial: false,
plan: License::PREMIUM_PLAN,
active_user_count: 1,
previous_user_count: 1
}.merge(restrictions)
gl_license = build(:gitlab_license, type: type, restrictions: license_restrictions)
gl_license = build(
:gitlab_license,
cloud_licensing_enabled: cloud_licensing_enabled,
restrictions: license_restrictions
)
build(:license, data: gl_license.export)
end
......
......@@ -16,7 +16,7 @@ FactoryBot.define do
end
trait :cloud do
type { 'cloud' }
cloud_licensing_enabled { true }
end
transient do
......
......@@ -12,7 +12,7 @@ RSpec.describe 'Admin views Cloud License', :js do
end
context 'Cloud license' do
let_it_be(:license) { create_current_license(type: License::CLOUD_LICENSE_TYPE, plan: License::ULTIMATE_PLAN) }
let_it_be(:license) { create_current_license(cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN) }
before do
visit(admin_cloud_license_path)
......@@ -35,7 +35,7 @@ RSpec.describe 'Admin views Cloud License', :js do
end
it 'fails to sync the subscription' do
create_current_license(type: License::CLOUD_LICENSE_TYPE, plan: License::ULTIMATE_PLAN, expires_at: nil)
create_current_license(cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN, expires_at: nil)
page.within(find('#content-body', match: :first)) do
click_button('Sync subscription details')
......
......@@ -51,7 +51,6 @@ RSpec.describe Resolvers::Admin::CloudLicenses::LicenseHistoryEntriesResolver do
it 'returns the license history entries', :enable_admin_mode do
today = Date.current
type = License::CLOUD_LICENSE_TYPE
past_license = create_license(
data: { starts_at: today - 1.month, expires_at: today + 11.months },
......@@ -59,8 +58,12 @@ RSpec.describe Resolvers::Admin::CloudLicenses::LicenseHistoryEntriesResolver do
)
expired_license = create_license(data: { starts_at: today - 1.year, expires_at: today - 1.month })
another_license = create_license(data: { starts_at: today - 1.month, expires_at: today + 1.year })
future_license = create_license(data: { starts_at: today + 1.month, expires_at: today + 13.months, type: type })
current_license = create_license(data: { starts_at: today - 15.days, expires_at: today + 11.months, type: type })
future_license = create_license(
data: { starts_at: today + 1.month, expires_at: today + 13.months, cloud_licensing_enabled: true }
)
current_license = create_license(
data: { starts_at: today - 15.days, expires_at: today + 11.months, cloud_licensing_enabled: true }
)
expect(result).to eq(
[
......
......@@ -12,7 +12,7 @@ RSpec.describe GitlabSchema.types['CurrentLicense'], :enable_admin_mode do
}
end
let_it_be(:license) { create_current_license(licensee: licensee, type: License::CLOUD_LICENSE_TYPE) }
let_it_be(:license) { create_current_license(licensee: licensee, cloud_licensing_enabled: true) }
let(:fields) do
%w[last_sync billable_users_count maximum_user_count users_over_license_count]
......
......@@ -12,7 +12,7 @@ RSpec.describe GitlabSchema.types['LicenseHistoryEntry'], :enable_admin_mode do
}
end
let_it_be(:license) { create_current_license(licensee: licensee, type: License::CLOUD_LICENSE_TYPE) }
let_it_be(:license) { create_current_license(licensee: licensee, cloud_licensing_enabled: true) }
def query(field_name)
%(
......
......@@ -105,7 +105,7 @@ RSpec.describe License do
let(:gitlab_license) do
build(
:gitlab_license,
type: described_class::CLOUD_LICENSE_TYPE,
cloud_licensing_enabled: true,
starts_at: Date.current,
restrictions: { active_user_count: 10, previous_user_count: previous_user_count }
)
......@@ -1418,12 +1418,38 @@ RSpec.describe License do
it { is_expected.to be false }
end
context 'when the license is not a cloud license' do
context 'when the license has cloud licensing disabled' do
let(:gl_license) { build(:gitlab_license, cloud_licensing_enabled: false) }
it { is_expected.to be false }
end
context 'when the license is a cloud license' do
let(:gl_license) { build(:gitlab_license, type: described_class::CLOUD_LICENSE_TYPE) }
context 'when the license has cloud licensing enabled' do
let(:gl_license) { build(:gitlab_license, cloud_licensing_enabled: true) }
it { is_expected.to be true }
end
end
describe '#usage_ping?' do
subject { license.usage_ping? }
context 'when no license provided' do
before do
license.data = nil
end
it { is_expected.to be false }
end
context 'when the license has usage ping required metrics disabled' do
let(:gl_license) { build(:gitlab_license, usage_ping_required_metrics_enabled: false) }
it { is_expected.to be false }
end
context 'when the license has usage ping required metrics enabled' do
let(:gl_license) { build(:gitlab_license, usage_ping_required_metrics_enabled: true) }
it { is_expected.to be true }
end
......@@ -1437,7 +1463,7 @@ RSpec.describe License do
end
context 'when the license is a cloud license' do
let(:gl_license) { build(:gitlab_license, type: described_class::CLOUD_LICENSE_TYPE) }
let(:gl_license) { build(:gitlab_license, cloud_licensing_enabled: true) }
it { is_expected.to eq(described_class::CLOUD_LICENSE_TYPE) }
end
......
......@@ -71,8 +71,19 @@ RSpec.describe API::License, api: true do
end
describe 'DELETE /license/:id' do
let(:license_type) { nil }
let(:license) { create(:license, created_at: Time.now, data: build(:gitlab_license, type: license_type, starts_at: Date.today, expires_at: Date.today, restrictions: { add_ons: { 'GitLab_DeployBoard' => 1 }, active_user_count: 2 }).export) }
let(:cloud_licensing_enabled) { false }
let(:license) do
gitlab_license = build(
:gitlab_license,
cloud_licensing_enabled: cloud_licensing_enabled,
starts_at: Date.current,
expires_at: Date.current,
restrictions: { add_ons: { 'GitLab_DeployBoard' => 1 }, active_user_count: 2 }
)
create(:license, created_at: Time.now, data: gitlab_license.export)
end
let(:endpoint) { "/license/#{license.id}" }
it 'destroys a license and returns 204' do
......@@ -98,7 +109,7 @@ RSpec.describe API::License, api: true do
end
context 'with a cloud license' do
let(:license_type) { License::CLOUD_LICENSE_TYPE }
let(:cloud_licensing_enabled) { true }
it 'returns 422 and does not delete the license' do
delete api(endpoint, admin)
......
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