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