Commit 7c79dba3 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Very first changes for loading JH extension

parent 409ada30
......@@ -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')
......@@ -73,6 +73,23 @@ module Gitlab
config.paths['app/views'].unshift "#{config.root}/ee/app/views"
end
if Gitlab.jh?
jh_paths = config.eager_load_paths.each_with_object([]) do |path, memo|
jh_path = config.root.join('jh', Pathname.new(path).relative_path_from(config.root))
memo << jh_path.to_s
end
jh_paths << "#{config.root}/jh/app/replicators"
# Eager load should load CE/EE first
config.eager_load_paths.push(*jh_paths)
config.helpers_paths.push "#{config.root}/jh/app/helpers"
# Other than Ruby modules we load JH first
config.paths['lib/tasks'].unshift "#{config.root}/jh/lib/tasks"
config.paths['app/views'].unshift "#{config.root}/jh/app/views"
end
# Rake tasks ignore the eager loading settings, so we need to set the
# autoload paths explicitly
config.autoload_paths = config.eager_load_paths.dup
......
......@@ -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)
......
......@@ -8,3 +8,12 @@ Gitlab.ee do
rescue
warn "WARNING: No valid license encryption key provided."
end
Gitlab.jh do
prefix = ENV['GITLAB_LICENSE_MODE'] == 'test' ? 'test_' : ''
public_key_file = File.read(Rails.root.join("jh", ".#{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 JH license encryption key provided."
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/app/helpers/jh/appearances_helper.rb').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"
......
......@@ -588,7 +588,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/app/helpers/jh/appearances_helper.rb',
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
......
......@@ -57,6 +57,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