Commit 112dea5f authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'bring-jh-changes' into 'master'

Very first changes for loading JH extension

See merge request gitlab-org/gitlab!58886
parents f7d91046 931099d6
......@@ -84,3 +84,4 @@ module AppearancesHelper
end
AppearancesHelper.prepend_if_ee('EE::AppearancesHelper')
AppearancesHelper.prepend_if_jh('JH::AppearancesHelper')
......@@ -194,10 +194,16 @@ module ApplicationHelper
end
end
def promo_host
# This needs to be used outside of Rails
def self.promo_host
'about.gitlab.com'
end
# Convenient method for Rails helper
def promo_host
ApplicationHelper.promo_host
end
def promo_url
'https://' + promo_host
end
......@@ -406,3 +412,4 @@ module ApplicationHelper
end
ApplicationHelper.prepend_if_ee('EE::ApplicationHelper')
ApplicationHelper.prepend_if_jh('JH::ApplicationHelper')
......@@ -57,21 +57,29 @@ module Gitlab
config.generators.templates.push("#{config.root}/generator_templates")
if Gitlab.ee?
ee_paths = config.eager_load_paths.each_with_object([]) do |path, memo|
ee_path = config.root.join('ee', Pathname.new(path).relative_path_from(config.root))
memo << ee_path.to_s
load_paths = lambda do |dir:|
ext_paths = config.eager_load_paths.each_with_object([]) do |path, memo|
ext_path = config.root.join(dir, Pathname.new(path).relative_path_from(config.root))
memo << ext_path.to_s
end
ee_paths << "#{config.root}/ee/app/replicators"
ext_paths << "#{config.root}/#{dir}/app/replicators"
# Eager load should load CE first
config.eager_load_paths.push(*ee_paths)
config.helpers_paths.push "#{config.root}/ee/app/helpers"
config.eager_load_paths.push(*ext_paths)
config.helpers_paths.push "#{config.root}/#{dir}/app/helpers"
# Other than Ruby modules we load EE first
config.paths['lib/tasks'].unshift "#{config.root}/ee/lib/tasks"
config.paths['app/views'].unshift "#{config.root}/ee/app/views"
# Other than Ruby modules we load extensions first
config.paths['lib/tasks'].unshift "#{config.root}/#{dir}/lib/tasks"
config.paths['app/views'].unshift "#{config.root}/#{dir}/app/views"
end
Gitlab.ee do
load_paths.call(dir: 'ee')
end
Gitlab.jh do
load_paths.call(dir: 'jh')
end
# Rake tasks ignore the eager loading settings, so we need to set the
......
......@@ -31,6 +31,12 @@ module InjectEnterpriseEditionModule
include(ee_module) if Gitlab.ee?
end
def prepend_if_jh(constant, with_descendants: false)
return unless Gitlab.jh?
prepend_module(constant.constantize, with_descendants)
end
private
def prepend_module(mod, with_descendants)
......
# frozen_string_literal: true
Gitlab.ee do
load_license = lambda do |dir:, license_name:|
prefix = ENV['GITLAB_LICENSE_MODE'] == 'test' ? 'test_' : ''
public_key_file = File.read(Rails.root.join(".#{prefix}license_encryption_key.pub"))
public_key_file = File.read(Rails.root.join(dir, ".#{prefix}license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key
rescue
warn "WARNING: No valid license encryption key provided."
warn "WARNING: No valid #{license_name} encryption key provided."
end
Gitlab.ee do
load_license.call(dir: '.', license_name: 'license')
end
Gitlab.jh do
load_license.call(dir: 'jh', license_name: 'JH license')
end
......@@ -35,5 +35,6 @@ ActiveSupport::Inflector.inflections do |inflect|
vulnerability_feedback
)
inflect.acronym 'EE'
inflect.acronym 'JH'
inflect.acronym 'CSP'
end
......@@ -65,7 +65,7 @@ RSpec.describe 'Billing plan pages', :feature, :js do
it 'displays the contact sales link' do
# see ApplicationHelper#contact_sales_url
contact_sales_url = 'https://about.gitlab.com/sales'
contact_sales_url = "https://#{ApplicationHelper.promo_host}/sales"
page.within('.content') do
expect(page).to have_link('Contact sales', href: %r{#{contact_sales_url}\?test=inappcontactsales(bronze|premium|gold)})
end
......
......@@ -108,10 +108,21 @@ module Gitlab
!%w[true 1].include?(ENV['FOSS_ONLY'].to_s)
end
def self.jh?
@is_jh ||=
ee? &&
root.join('jh').exist? &&
!%w[true 1].include?(ENV['EE_ONLY'].to_s)
end
def self.ee
yield if ee?
end
def self.jh
yield if jh?
end
def self.http_proxy_env?
HTTP_PROXY_ENV_VARS.any? { |name| ENV[name] }
end
......
......@@ -6,6 +6,11 @@ module Gitlab
::Gitlab.dev_or_test_env? ? 'https://customers.stg.gitlab.com' : 'https://customers.gitlab.com'
end
SUBSCRIPTIONS_URL = ENV.fetch('CUSTOMER_PORTAL_URL', default_subscriptions_url).freeze
def self.subscriptions_url
ENV.fetch('CUSTOMER_PORTAL_URL', default_subscriptions_url)
end
end
end
Gitlab::SubscriptionPortal.prepend_if_jh('JH::Gitlab::SubscriptionPortal')
Gitlab::SubscriptionPortal::SUBSCRIPTIONS_URL = Gitlab::SubscriptionPortal.subscriptions_url.freeze
......@@ -97,6 +97,10 @@ function rspec_paralellized_job() {
spec_folder_prefix="ee/"
fi
if [[ "${test_tool}" =~ "-jh" ]]; then
spec_folder_prefix="jh/"
fi
export KNAPSACK_LOG_LEVEL="debug"
export KNAPSACK_REPORT_PATH="knapsack/${report_name}_report.json"
......
......@@ -596,7 +596,7 @@ RSpec.describe 'Admin updates settings' do
context 'Nav bar' do
it 'shows default help links in nav' do
default_support_url = 'https://about.gitlab.com/getting-help/'
default_support_url = "https://#{ApplicationHelper.promo_host}/getting-help/"
visit root_dashboard_path
......
......@@ -168,11 +168,13 @@ RSpec.describe ApplicationHelper do
it { expect(helper.active_when(false)).to eq(nil) }
end
describe '#promo_host' do
subject { helper.promo_host }
unless Gitlab.jh?
describe '#promo_host' do
subject { helper.promo_host }
it 'returns the url' do
is_expected.to eq('about.gitlab.com')
it 'returns the url' do
is_expected.to eq('about.gitlab.com')
end
end
end
......@@ -180,7 +182,7 @@ RSpec.describe ApplicationHelper do
subject { helper.promo_url }
it 'returns the url' do
is_expected.to eq('https://about.gitlab.com')
is_expected.to eq("https://#{helper.promo_host}")
end
it 'changes if promo_host changes' do
......@@ -194,7 +196,7 @@ RSpec.describe ApplicationHelper do
subject { helper.contact_sales_url }
it 'returns the url' do
is_expected.to eq('https://about.gitlab.com/sales')
is_expected.to eq("https://#{helper.promo_host}/sales")
end
it 'changes if promo_url changes' do
......
......@@ -3,39 +3,41 @@
require 'spec_helper'
RSpec.describe ::Gitlab::SubscriptionPortal do
describe '.default_subscriptions_url' do
subject { described_class.default_subscriptions_url }
context 'on non test and non dev environments' do
before do
allow(Rails).to receive_message_chain(:env, :test?).and_return(false)
allow(Rails).to receive_message_chain(:env, :development?).and_return(false)
unless Gitlab.jh?
describe '.default_subscriptions_url' do
subject { described_class.default_subscriptions_url }
context 'on non test and non dev environments' do
before do
allow(Rails).to receive_message_chain(:env, :test?).and_return(false)
allow(Rails).to receive_message_chain(:env, :development?).and_return(false)
end
it 'returns production subscriptions app URL' do
is_expected.to eq('https://customers.gitlab.com')
end
end
it 'returns production subscriptions app URL' do
is_expected.to eq('https://customers.gitlab.com')
end
end
context 'on dev environment' do
before do
allow(Rails).to receive_message_chain(:env, :test?).and_return(false)
allow(Rails).to receive_message_chain(:env, :development?).and_return(true)
end
context 'on dev environment' do
before do
allow(Rails).to receive_message_chain(:env, :test?).and_return(false)
allow(Rails).to receive_message_chain(:env, :development?).and_return(true)
it 'returns staging subscriptions app url' do
is_expected.to eq('https://customers.stg.gitlab.com')
end
end
it 'returns staging subscriptions app url' do
is_expected.to eq('https://customers.stg.gitlab.com')
end
end
context 'on test environment' do
before do
allow(Rails).to receive_message_chain(:env, :test?).and_return(true)
allow(Rails).to receive_message_chain(:env, :development?).and_return(false)
end
context 'on test environment' do
before do
allow(Rails).to receive_message_chain(:env, :test?).and_return(true)
allow(Rails).to receive_message_chain(:env, :development?).and_return(false)
end
it 'returns staging subscriptions app url' do
is_expected.to eq('https://customers.stg.gitlab.com')
it 'returns staging subscriptions app url' do
is_expected.to eq('https://customers.stg.gitlab.com')
end
end
end
end
......
......@@ -247,75 +247,117 @@ RSpec.describe Gitlab do
end
end
describe '.ee?' do
describe 'ee? and jh?' do
before do
stub_env('FOSS_ONLY', nil) # Make sure the ENV is clean
# Make sure the ENV is clean
stub_env('FOSS_ONLY', nil)
stub_env('EE_ONLY', nil)
described_class.instance_variable_set(:@is_ee, nil)
described_class.instance_variable_set(:@is_jh, nil)
end
after do
described_class.instance_variable_set(:@is_ee, nil)
described_class.instance_variable_set(:@is_jh, nil)
end
context 'for EE' do
before do
root = Pathname.new('dummy')
license_path = double(:path, exist?: true)
def stub_path(*paths, **arguments)
root = Pathname.new('dummy')
pathname = double(:path, **arguments)
allow(described_class)
.to receive(:root)
.and_return(root)
allow(described_class)
.to receive(:root)
.and_return(root)
allow(root).to receive(:join)
paths.each do |path|
allow(root)
.to receive(:join)
.with('ee/app/models/license.rb')
.and_return(license_path)
.with(path)
.and_return(pathname)
end
end
context 'when using FOSS_ONLY=1' do
describe '.ee?' do
context 'for EE' do
before do
stub_env('FOSS_ONLY', '1')
stub_path('ee/app/models/license.rb', exist?: true)
end
it 'returns not to be EE' do
expect(described_class).not_to be_ee
context 'when using FOSS_ONLY=1' do
before do
stub_env('FOSS_ONLY', '1')
end
it 'returns not to be EE' do
expect(described_class).not_to be_ee
end
end
end
context 'when using FOSS_ONLY=0' do
before do
stub_env('FOSS_ONLY', '0')
context 'when using FOSS_ONLY=0' do
before do
stub_env('FOSS_ONLY', '0')
end
it 'returns to be EE' do
expect(described_class).to be_ee
end
end
it 'returns to be EE' do
expect(described_class).to be_ee
context 'when using default FOSS_ONLY' do
it 'returns to be EE' do
expect(described_class).to be_ee
end
end
end
context 'when using default FOSS_ONLY' do
it 'returns to be EE' do
expect(described_class).to be_ee
context 'for CE' do
before do
stub_path('ee/app/models/license.rb', exist?: false)
end
it 'returns not to be EE' do
expect(described_class).not_to be_ee
end
end
end
context 'for CE' do
before do
root = double(:path)
license_path = double(:path, exists?: false)
describe '.jh?' do
context 'for JH' do
before do
stub_path(
'ee/app/models/license.rb',
'jh',
exist?: true)
end
allow(described_class)
.to receive(:root)
.and_return(Pathname.new('dummy'))
context 'when using default FOSS_ONLY and EE_ONLY' do
it 'returns to be JH' do
expect(described_class).to be_jh
end
end
allow(root)
.to receive(:join)
.with('ee/app/models/license.rb')
.and_return(license_path)
end
context 'when using FOSS_ONLY=1' do
before do
stub_env('FOSS_ONLY', '1')
end
it 'returns not to be JH' do
expect(described_class).not_to be_jh
end
end
context 'when using EE_ONLY=1' do
before do
stub_env('EE_ONLY', '1')
end
it 'returns not to be EE' do
expect(described_class).not_to be_ee
it 'returns not to be JH' do
expect(described_class).not_to be_jh
end
end
end
end
end
......
......@@ -55,6 +55,7 @@ require 'rainbow/ext/string'
Rainbow.enabled = false
require_relative('../ee/spec/spec_helper') if Gitlab.ee?
require_relative('../jh/spec/spec_helper') if Gitlab.jh?
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
......
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