Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CDN assets for SaaS in OCP (#3199)
Detailed info about this commit in it's original PR: #3072
- Loading branch information
Showing
16 changed files
with
157 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@javascript | ||
Feature: Asset host | ||
In order to reduce the network traffic from the web server | ||
As master, provider or developer | ||
I want to load all assets from the configured CDN | ||
|
||
Rule: Master | ||
Background: | ||
Given master is the provider | ||
|
||
Scenario: Asset host not configured | ||
When master admin is logged in | ||
Then assets shouldn't be loaded from the asset host | ||
|
||
Scenario: Master dashboard with asset host configured | ||
When the asset host is set to "cdn.3scale.localhost" | ||
When master admin is logged in | ||
Then assets should be loaded from the asset host | ||
|
||
Rule: Provider | ||
Background: | ||
Given the asset host is set to "cdn.3scale.localhost" | ||
And a provider is logged in | ||
And the provider has one buyer | ||
|
||
Scenario: Provider dashboard with asset host configured | ||
Then assets should be loaded from the asset host | ||
|
||
Scenario: Developer portal with asset host configured | ||
When the buyer logs in to the provider | ||
Then javascript assets should be loaded from the asset host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
Given /^the asset host is set to "(.*)"$/ do |asset_host| | ||
cdn_url = "#{asset_host}:#{Capybara.current_session.server.port}" | ||
Rails.configuration.asset_host = cdn_url | ||
Rails.configuration.three_scale.asset_host = cdn_url | ||
end | ||
|
||
Then /^((javascript|font)\s)?assets should be loaded from the asset host$/ do |asset_type| | ||
cdn_url = Rails.configuration.asset_host | ||
js_regexp = Regexp.new("https?://#{cdn_url}/packs.*?\\.js") | ||
font_regexp = Regexp.new("https?://#{cdn_url}/packs.*?\\.eot") | ||
|
||
assert_not_nil Capybara.page.source.match js_regexp if ['javascript', nil].include? asset_type | ||
assert_not_nil Capybara.page.source.match font_regexp if ['font', nil].include? asset_type | ||
end | ||
|
||
Then /^assets shouldn't be loaded from the asset host$/ do | ||
# When no CDN is set, we expect to find relative paths for fonts and js | ||
js_regexp = Regexp.new('src="/packs.*?\.js"') | ||
font_regexp = Regexp.new('url\(/packs.*?\.eot\)') | ||
|
||
assert_not_nil Capybara.page.source.match js_regexp | ||
assert_not_nil Capybara.page.source.match font_regexp | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :webpacker do | ||
|
||
task :check_asset_host do | ||
if Rails.configuration.three_scale.asset_host.present? | ||
STDERR.puts "*** Asset host must be null during compilation time. See https://github.com/3scale/porta/pull/3072 ***" | ||
return false | ||
end | ||
end | ||
|
||
Rake::Task['webpacker:compile'].enhance [:check_asset_host] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters