2019-09-06 01:20:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Pages::LookupPath do
|
2020-11-10 16:08:51 -05:00
|
|
|
let(:project) { create(:project, :pages_private, pages_https_only: true) }
|
2019-09-06 01:20:05 -04:00
|
|
|
|
|
|
|
subject(:lookup_path) { described_class.new(project) }
|
|
|
|
|
2020-09-04 14:08:48 -04:00
|
|
|
before do
|
|
|
|
stub_pages_setting(access_control: true, external_https: ["1.1.1.1:443"])
|
2020-11-10 16:08:51 -05:00
|
|
|
stub_pages_object_storage(::Pages::DeploymentUploader)
|
2020-09-04 14:08:48 -04:00
|
|
|
end
|
|
|
|
|
2019-09-06 01:20:05 -04:00
|
|
|
describe '#project_id' do
|
|
|
|
it 'delegates to Project#id' do
|
2020-09-04 14:08:48 -04:00
|
|
|
expect(lookup_path.project_id).to eq(project.id)
|
2019-09-06 01:20:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#access_control' do
|
|
|
|
it 'delegates to Project#private_pages?' do
|
|
|
|
expect(lookup_path.access_control).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#https_only' do
|
|
|
|
subject(:lookup_path) { described_class.new(project, domain: domain) }
|
|
|
|
|
|
|
|
context 'when no domain provided' do
|
|
|
|
let(:domain) { nil }
|
|
|
|
|
|
|
|
it 'delegates to Project#pages_https_only?' do
|
|
|
|
expect(lookup_path.https_only).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is domain provided' do
|
|
|
|
let(:domain) { instance_double(PagesDomain, https?: false) }
|
|
|
|
|
|
|
|
it 'takes into account the https setting of the domain' do
|
|
|
|
expect(lookup_path.https_only).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#source' do
|
2020-11-10 16:08:51 -05:00
|
|
|
let(:source) { lookup_path.source }
|
2020-09-04 14:08:48 -04:00
|
|
|
|
2020-11-10 16:08:51 -05:00
|
|
|
shared_examples 'uses disk storage' do
|
|
|
|
it 'uses disk storage', :aggregate_failures do
|
|
|
|
expect(source[:type]).to eq('file')
|
|
|
|
expect(source[:path]).to eq(project.full_path + "/public/")
|
2020-09-04 14:08:48 -04:00
|
|
|
end
|
2019-09-06 01:20:05 -04:00
|
|
|
end
|
|
|
|
|
2020-09-04 14:08:48 -04:00
|
|
|
include_examples 'uses disk storage'
|
|
|
|
|
2021-01-21 13:09:11 -05:00
|
|
|
it 'return nil when legacy storage is disabled and there is no deployment' do
|
|
|
|
stub_feature_flags(pages_serve_from_legacy_storage: false)
|
|
|
|
expect(Gitlab::ErrorTracking).to receive(:track_exception)
|
|
|
|
.with(described_class::LegacyStorageDisabledError)
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
expect(source).to eq(nil)
|
|
|
|
end
|
|
|
|
|
2020-11-10 16:08:51 -05:00
|
|
|
context 'when there is pages deployment' do
|
|
|
|
let(:deployment) { create(:pages_deployment, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.mark_pages_as_deployed
|
|
|
|
project.pages_metadatum.update!(pages_deployment: deployment)
|
|
|
|
end
|
|
|
|
|
2020-11-17 10:09:28 -05:00
|
|
|
it 'uses deployment from object storage' do
|
2020-12-01 10:09:28 -05:00
|
|
|
freeze_time do
|
2020-11-17 10:09:28 -05:00
|
|
|
expect(source).to(
|
|
|
|
eq({
|
|
|
|
type: 'zip',
|
|
|
|
path: deployment.file.url(expire_at: 1.day.from_now),
|
|
|
|
global_id: "gid://gitlab/PagesDeployment/#{deployment.id}",
|
|
|
|
sha256: deployment.file_sha256,
|
|
|
|
file_size: deployment.size,
|
|
|
|
file_count: deployment.file_count
|
|
|
|
})
|
|
|
|
)
|
2020-11-10 16:08:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when deployment is in the local storage' do
|
|
|
|
before do
|
|
|
|
deployment.file.migrate!(::ObjectStorage::Store::LOCAL)
|
|
|
|
end
|
|
|
|
|
2020-11-17 10:09:28 -05:00
|
|
|
it 'uses file protocol' do
|
2020-12-01 10:09:28 -05:00
|
|
|
freeze_time do
|
2020-11-17 10:09:28 -05:00
|
|
|
expect(source).to(
|
|
|
|
eq({
|
|
|
|
type: 'zip',
|
|
|
|
path: 'file://' + deployment.file.path,
|
|
|
|
global_id: "gid://gitlab/PagesDeployment/#{deployment.id}",
|
|
|
|
sha256: deployment.file_sha256,
|
|
|
|
file_size: deployment.size,
|
|
|
|
file_count: deployment.file_count
|
|
|
|
})
|
|
|
|
)
|
2020-11-10 16:08:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pages_serve_with_zip_file_protocol feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(pages_serve_with_zip_file_protocol: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'uses disk storage'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pages_serve_from_deployments feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(pages_serve_from_deployments: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'uses disk storage'
|
|
|
|
end
|
|
|
|
end
|
2021-01-26 13:09:30 -05:00
|
|
|
|
|
|
|
context 'when deployment were created during migration' do
|
|
|
|
before do
|
|
|
|
FileUtils.mkdir_p File.join(project.pages_path, "public")
|
|
|
|
File.open(File.join(project.pages_path, "public/index.html"), "w") do |f|
|
|
|
|
f.write("Hello!")
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(::Pages::MigrateLegacyStorageToDeploymentService.new(project).execute[:status]).to eq(:success)
|
|
|
|
|
|
|
|
project.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:deployment) { project.pages_metadatum.pages_deployment }
|
|
|
|
|
|
|
|
it 'uses deployment from object storage' do
|
|
|
|
freeze_time do
|
|
|
|
expect(source).to(
|
|
|
|
eq({
|
|
|
|
type: 'zip',
|
|
|
|
path: deployment.file.url(expire_at: 1.day.from_now),
|
|
|
|
global_id: "gid://gitlab/PagesDeployment/#{deployment.id}",
|
|
|
|
sha256: deployment.file_sha256,
|
|
|
|
file_size: deployment.size,
|
|
|
|
file_count: deployment.file_count
|
|
|
|
})
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pages_serve_from_migrated_zip feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(pages_serve_from_migrated_zip: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'uses disk storage'
|
|
|
|
end
|
|
|
|
end
|
2019-09-06 01:20:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#prefix' do
|
2019-09-25 05:06:04 -04:00
|
|
|
it 'returns "/" for pages group root projects' do
|
|
|
|
project = instance_double(Project, pages_group_root?: true)
|
|
|
|
lookup_path = described_class.new(project, trim_prefix: 'mygroup')
|
|
|
|
|
2019-09-06 01:20:05 -04:00
|
|
|
expect(lookup_path.prefix).to eq('/')
|
|
|
|
end
|
2019-09-25 05:06:04 -04:00
|
|
|
|
|
|
|
it 'returns the project full path with the provided prefix removed' do
|
|
|
|
project = instance_double(Project, pages_group_root?: false, full_path: 'mygroup/myproject')
|
|
|
|
lookup_path = described_class.new(project, trim_prefix: 'mygroup')
|
|
|
|
|
|
|
|
expect(lookup_path.prefix).to eq('/myproject/')
|
|
|
|
end
|
2019-09-06 01:20:05 -04:00
|
|
|
end
|
|
|
|
end
|