This instance was upgraded to Heptapod 0.27.2 on 2021-12-08 at 22:00 UTC+1

Commit c5f02e00 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 4094dc97d61d
......@@ -87,7 +87,7 @@ def sign_in_using_ldap_credentials(user:)
click_element :sign_in_button
end
Page::Main::Menu.perform(&:has_personal_area?)
Page::Main::Menu.perform(&:signed_in?)
end
def self.path
......
......@@ -96,6 +96,10 @@ def has_admin_area_link?(wait: Capybara.default_max_wait_time)
has_element?(:admin_area_link, wait: wait)
end
def has_no_admin_area_link?(wait: Capybara.default_max_wait_time)
has_no_element?(:admin_area_link, wait: wait)
end
def click_stop_impersonation_link
click_element(:stop_impersonation_link)
end
......
# frozen_string_literal: true
module QA
module Scenario
module Test
module Integration
class LDAPNoServer < Test::Instance::All
tags :ldap_no_server
end
end
end
end
end
# frozen_string_literal: true
module QA
module Service
class LDAP
include Service::Shellout
def initialize(volume)
@image = 'osixia/openldap:latest'
@name = 'ldap-server'
@network = Runtime::Scenario.attributes[:network] || 'test'
@volume = volume
end
def network
shell "docker network inspect #{@network}"
rescue CommandError
'bridge'
else
@network
end
def pull
shell "docker pull #{@image}"
end
def host_name
"#{@name}.#{network}"
end
def register!
shell <<~CMD.tr("\n", ' ')
docker run -d --rm
--network #{network}
--hostname #{host_name}
--name #{@name}
-p 389:389
--volume #{volume_or_fixture(@volume)}:/container/service/slapd/assets/config/bootstrap/ldif/custom
#{@image} --copy-service
CMD
end
def remove!
shell "docker rm -f #{@name}" if running?
end
def running?
`docker ps -f name=#{@name}`.include?(@name)
end
def volume_or_fixture(volume_name)
if volume_exists?(volume_name)
volume_name
else
File.expand_path("../fixtures/ldap/#{volume_name}", __dir__)
end
end
def volume_exists?(volume_name)
`docker volume ls -q -f name=#{volume_name}`.include?(volume_name)
end
end
end
end
......@@ -8,6 +8,14 @@
end
end
describe QA::Scenario::Test::Integration::LDAPNoServer do
context '#perform' do
it_behaves_like 'a QA scenario class' do
let(:tags) { [:ldap_no_server] }
end
end
end
describe QA::Scenario::Test::Integration::LDAPTLS do
context '#perform' do
it_behaves_like 'a QA scenario class' do
......
......@@ -98,8 +98,11 @@ def index
# remove line below once `privacy_policy_update_callout`
# feature flag is removed and `gon` reverts back to
# to not setting any variables.
it_behaves_like 'setting gon variables'
# it_behaves_like 'not setting gon variables'
if Gitlab.ee?
it_behaves_like 'setting gon variables'
else
it_behaves_like 'not setting gon variables'
end
end
end
......@@ -110,8 +113,11 @@ def index
# remove line below once `privacy_policy_update_callout`
# feature flag is removed and `gon` reverts back to
# to not setting any variables.
it_behaves_like 'setting gon variables'
# it_behaves_like 'not setting gon variables'
if Gitlab.ee?
it_behaves_like 'setting gon variables'
else
it_behaves_like 'not setting gon variables'
end
end
end
......
......@@ -426,3 +426,13 @@ describe('newDate', () => {
expect(initialDate instanceof Date).toBe(true);
});
});
describe('getDateInPast', () => {
it('returns the correct date in the past', () => {
const date = new Date(1563235200000); // 2019-07-16T00:00:00.00Z
const daysInPast = 90;
const dateInPast = datetimeUtility.getDateInPast(date, daysInPast);
expect(dateInPast).toBe('2019-04-17T00:00:00.000Z');
});
});
......@@ -6,6 +6,7 @@ import {
numberToHumanSize,
sum,
isOdd,
median,
} from '~/lib/utils/number_utils';
describe('Number Utils', () => {
......@@ -109,4 +110,16 @@ describe('Number Utils', () => {
expect(isOdd(1)).toEqual(1);
});
});
describe('median', () => {
it('computes the median for a given array with odd length', () => {
const items = [10, 27, 20, 5, 19];
expect(median(items)).toBe(19);
});
it('computes the median for a given array with even length', () => {
const items = [10, 27, 20, 5, 19, 4];
expect(median(items)).toBe(14.5);
});
});
});
......@@ -410,6 +410,7 @@ project:
- designs
- project_aliases
- external_pull_requests
- pages_metadatum
award_emoji:
- awardable
- user
......
......@@ -191,6 +191,16 @@
end
end
describe '.find_by_pages_host' do
it 'finds namespace by GitLab Pages host and is case-insensitive' do
namespace = create(:namespace, name: 'topnamespace')
create(:namespace, name: 'annother_namespace')
host = "TopNamespace.#{Settings.pages.host.upcase}"
expect(described_class.find_by_pages_host(host)).to eq(namespace)
end
end
describe '#ancestors_upto' do
let(:parent) { create(:group) }
let(:child) { create(:group, parent: parent) }
......@@ -913,4 +923,18 @@ def project_rugged(project)
end
end
end
describe '#pages_virtual_domain' do
let(:project) { create(:project, namespace: namespace) }
context 'when there are pages deployed for the project' do
before do
project.mark_pages_as_deployed
end
it 'returns the virual domain' do
expect(namespace.pages_virtual_domain).to be_an_instance_of(Pages::VirtualDomain)
end
end
end
end
......@@ -57,8 +57,18 @@
end
describe '#prefix' do
it 'returns "/"' do
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')
expect(lookup_path.prefix).to eq('/')
end
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
end
end
......@@ -25,19 +25,33 @@
end
describe '#lookup_paths' do
let(:domain) { instance_double(PagesDomain) }
let(:project_a) { instance_double(Project) }
let(:project_z) { instance_double(Project) }
let(:pages_lookup_path_a) { instance_double(Pages::LookupPath, prefix: 'aaa') }
let(:pages_lookup_path_z) { instance_double(Pages::LookupPath, prefix: 'zzz') }
subject(:virtual_domain) { described_class.new([project_a, project_z], domain: domain) }
context 'when there is pages domain provided' do
let(:domain) { instance_double(PagesDomain) }
it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do
expect(project_a).to receive(:pages_lookup_path).with(domain: domain).and_return(pages_lookup_path_a)
expect(project_z).to receive(:pages_lookup_path).with(domain: domain).and_return(pages_lookup_path_z)
subject(:virtual_domain) { described_class.new([project_a, project_z], domain: domain) }
expect(virtual_domain.lookup_paths).to eq([pages_lookup_path_z, pages_lookup_path_a])
it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do
expect(project_a).to receive(:pages_lookup_path).with(domain: domain, trim_prefix: nil).and_return(pages_lookup_path_a)
expect(project_z).to receive(:pages_lookup_path).with(domain: domain, trim_prefix: nil).and_return(pages_lookup_path_z)
expect(virtual_domain.lookup_paths).to eq([pages_lookup_path_z, pages_lookup_path_a])
end
end
context 'when there is trim_prefix provided' do
subject(:virtual_domain) { described_class.new([project_a, project_z], trim_prefix: 'group/') }
it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do
expect(project_a).to receive(:pages_lookup_path).with(trim_prefix: 'group/', domain: nil).and_return(pages_lookup_path_a)
expect(project_z).to receive(:pages_lookup_path).with(trim_prefix: 'group/', domain: nil).and_return(pages_lookup_path_z)
expect(virtual_domain.lookup_paths).to eq([pages_lookup_path_z, pages_lookup_path_a])
end
end
end
end
......@@ -557,15 +557,27 @@
end
end
describe '.pages_virtual_domain' do
let(:project) { build(:project) }
describe '#pages_virtual_domain' do
let(:project) { create(:project) }
let(:pages_domain) { create(:pages_domain, project: project) }
subject(:pages_domain) { build(:pages_domain, project: project) }
context 'when there are no pages deployed for the project' do
it 'returns nil' do
expect(pages_domain.pages_virtual_domain).to be_nil
end
end
it 'returns instance of Pages::VirtualDomain' do
expect(Pages::VirtualDomain).to receive(:new).with([project], domain: pages_domain).and_call_original
context 'when there are pages deployed for the project' do
before do
project.mark_pages_as_deployed
project.reload
end
it 'returns the virual domain' do
expect(Pages::VirtualDomain).to receive(:new).with([project], domain: pages_domain).and_call_original
expect(pages_domain.pages_virtual_domain).to be_a(Pages::VirtualDomain)
expect(pages_domain.pages_virtual_domain).to be_an_instance_of(Pages::VirtualDomain)
end
end
end
end
......@@ -132,6 +132,13 @@
expect(project.ci_cd_settings).to be_an_instance_of(ProjectCiCdSetting)
expect(project.ci_cd_settings).to be_persisted
end
it 'automatically creates a Pages metadata row' do
project = create(:project)
expect(project.pages_metadatum).to be_an_instance_of(ProjectPagesMetadatum)
expect(project.pages_metadatum).to be_persisted
end
end
context 'updating cd_cd_settings' do
......@@ -3526,7 +3533,8 @@ def enable_lfs
end
describe '#remove_pages' do
let(:project) { create(:project) }
let(:project) { create(:project).tap { |project| project.mark_pages_as_deployed } }
let(:pages_metadatum) { project.pages_metadatum }
let(:namespace) { project.namespace }
let(:pages_path) { project.pages_path }
......@@ -3539,12 +3547,12 @@ def enable_lfs
end
end
it 'removes the pages directory' do
it 'removes the pages directory and marks the project as not having pages deployed' do
expect_any_instance_of(Projects::UpdatePagesConfigurationService).to receive(:execute)
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project).and_return(true)
expect(PagesWorker).to receive(:perform_in).with(5.minutes, :remove, namespace.full_path, anything)
project.remove_pages
expect { project.remove_pages }.to change { pages_metadatum.reload.deployed }.from(true).to(false)
end
it 'is a no-op when there is no namespace' do
......@@ -3554,13 +3562,13 @@ def enable_lfs
expect_any_instance_of(Projects::UpdatePagesConfigurationService).not_to receive(:execute)
expect_any_instance_of(Gitlab::PagesTransfer).not_to receive(:rename_project)
project.remove_pages
expect { project.remove_pages }.not_to change { pages_metadatum.reload.deployed }
end
it 'is run when the project is destroyed' do
expect(project).to receive(:remove_pages).and_call_original
project.destroy
expect { project.destroy }.not_to raise_error
end
end
......@@ -5014,6 +5022,35 @@ def enable_lfs
end
end
context 'pages deployed' do
let(:project) { create(:project) }
{
mark_pages_as_deployed: true,
mark_pages_as_not_deployed: false
}.each do |method_name, flag|
describe method_name do
it "creates new record and sets deployed to #{flag} if none exists yet" do
project.pages_metadatum.destroy!
project.reload
project.send(method_name)
expect(project.pages_metadatum.reload.deployed).to eq(flag)
end
it "updates the existing record and sets deployed to #{flag}" do
pages_metadatum = project.pages_metadatum
pages_metadatum.update!(deployed: !flag)
expect { project.send(method_name) }.to change {
pages_metadatum.reload.deployed
}.from(!flag).to(flag)
end
end
end
end
describe '#has_pool_repsitory?' do
it 'returns false when it does not have a pool repository' do
subject = create(:project, :repository)
......@@ -5054,9 +5091,34 @@ def enable_lfs
let(:project) { build(:project) }
it 'returns instance of Pages::LookupPath' do
expect(Pages::LookupPath).to receive(:new).with(project, domain: pages_domain).and_call_original
expect(Pages::LookupPath).to receive(:new).with(project, domain: pages_domain, trim_prefix: 'mygroup').and_call_original
expect(project.pages_lookup_path(domain: pages_domain, trim_prefix: 'mygroup')).to be_a(Pages::LookupPath)
end
end
describe '.with_pages_deployed' do
it 'returns only projects that have pages deployed' do
_project_without_pages = create(:project)
project_with_pages = create(:project)
project_with_pages.mark_pages_as_deployed
expect(described_class.with_pages_deployed).to contain_exactly(project_with_pages)
end
end
describe '#pages_group_root?' do
it 'returns returns true if pages_url is same as pages_group_url' do
project = build(:project)
expect(project).to receive(:pages_url).and_return(project.pages_group_url)
expect(project.pages_group_root?).to eq(true)
end
it 'returns returns false if pages_url is different than pages_group_url' do
project = build(:project)
expect(project.pages_lookup_path(domain: pages_domain)).to be_a(Pages::LookupPath)
expect(project.pages_group_root?).to eq(false)
end
end
......
......@@ -43,6 +43,10 @@ def query_host(host)
super(host, headers)
end
def deploy_pages(project)
project.mark_pages_as_deployed
end
context 'not existing host' do
it 'responds with 404 Not Found' do
query_host('pages.gitlab.io')
......@@ -56,18 +60,104 @@ def query_host(host)
let(:project) { create(:project, namespace: namespace, name: 'gitlab-ce') }
let!(:pages_domain) { create(:pages_domain, domain: 'pages.gitlab.io', project: project) }
it 'responds with the correct domain configuration' do
query_host('pages.gitlab.io')
context 'when there are no pages deployed for the related project' do
it 'responds with 204 No Content' do
query_host('pages.gitlab.io')
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('internal/pages/virtual_domain')
expect(response).to have_gitlab_http_status(204)
end
end
expect(json_response['certificate']).to eq(pages_domain.certificate)
expect(json_response['key']).to eq(pages_domain.key)
context 'when there are pages deployed for the related project' do
it 'responds with the correct domain configuration' do
deploy_pages(project)
query_host('pages.gitlab.io')
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('internal/pages/virtual_domain')
expect(json_response['certificate']).to eq(pages_domain.certificate)
expect(json_response['key']).to eq(pages_domain.key)
expect(json_response['lookup_paths']).to eq(
[
{
'project_id' => project.id,
'access_control' => false,
'https_only' => false,
'prefix' => '/',
'source' => {
'type' => 'file',
'path' => 'gitlab-org/gitlab-ce/public/'
}
}
]
)
end
end
end
context 'namespaced domain' do
let(:group) { create(:group, name: 'mygroup') }
before do
allow(Settings.pages).to receive(:host).and_return('gitlab-pages.io')
allow(Gitlab.config.pages).to receive(:url).and_return("http://gitlab-pages.io")
end
context 'regular project' do
it 'responds with the correct domain configuration' do
project = create(:project, group: group, name: 'myproject')
deploy_pages(project)
query_host('mygroup.gitlab-pages.io')
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('internal/pages/virtual_domain')
expect(json_response['lookup_paths']).to eq(
[
{
'project_id' => project.id,
'access_control' => false,
'https_only' => false,
'prefix' => '/myproject/',
'source' => {
'type' => 'file',
'path' => 'mygroup/myproject/public/'
}
}
]
)
end
end
lookup_path = json_response['lookup_paths'][0]
expect(lookup_path['prefix']).to eq('/')
expect(lookup_path['source']['path']).to eq('gitlab-org/gitlab-ce/public/')
context 'group root project' do
it 'responds with the correct domain configuration' do
project = create(:project, group: group, name: 'mygroup.gitlab-pages.io')
deploy_pages(project)
query_host('mygroup.gitlab-pages.io')
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('internal/pages/virtual_domain')
expect(json_response['lookup_paths']).to eq(
[
{
'project_id' => project.id,
'access_control' => false,
'https_only' => false,
'prefix' => '/',
'source' => {
'type' => 'file',
'path' => 'mygroup/mygroup.gitlab-pages.io/public/'
}
}
]
)
end
end
end
end
......
......@@ -40,6 +40,7 @@
it "doesn't delete artifacts after deploying" do
expect(execute).to eq(:success)
expect(project.pages_metadatum).to be_deployed
expect(build.artifacts?).to eq(true)
end
end
......@@ -47,6 +48,7 @@
it 'succeeds' do
expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success)
expect(project.pages_metadatum).to be_deployed
expect(project.pages_deployed?).to be_truthy
# Check that all expected files are extracted
......@@ -63,16 +65,23 @@
it 'removes pages after destroy' do
expect(PagesWorker).to receive(:perform_in)
expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success)
expect(project.pages_metadatum).to be_deployed
expect(project.pages_deployed?).to be_truthy
project.destroy
expect(project.pages_deployed?).to be_falsey