Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-31 17:35:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-31 17:35:48 +0300
commit62ed09f455ec625a058169e71663a1b751bedaca (patch)
treec7f863091c733da4b57bb9d63455305f909e3c26 /spec/models
parentd7fe9575a00f0e734977cc15a5af92e8674bb379 (diff)
Add latest changes from gitlab-org/security/gitlab@16-1-stable-ee
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/project_setting_spec.rb26
-rw-r--r--spec/models/project_spec.rb58
2 files changed, 83 insertions, 1 deletions
diff --git a/spec/models/project_setting_spec.rb b/spec/models/project_setting_spec.rb
index 4b2760d7699..c020609c26f 100644
--- a/spec/models/project_setting_spec.rb
+++ b/spec/models/project_setting_spec.rb
@@ -77,12 +77,36 @@ RSpec.describe ProjectSetting, type: :model, feature_category: :groups_and_proje
expect(project_setting).not_to be_valid
expect(project_setting.errors.full_messages).to include("Pages unique domain has already been taken")
end
+
+ it "validates if the pages_unique_domain already exist as a project path" do
+ stub_pages_setting(host: 'example.com')
+
+ create(:project, path: "random-unique-domain.example.com")
+ project_setting = build(:project_setting, pages_unique_domain: "random-unique-domain")
+
+ expect(project_setting).not_to be_valid
+ expect(project_setting.errors.full_messages_for(:pages_unique_domain))
+ .to match(["Pages unique domain already in use"])
+ end
+
+ context "when updating" do
+ it "validates if the pages_unique_domain already exist as a project path" do
+ stub_pages_setting(host: 'example.com')
+ project_setting = create(:project_setting)
+
+ create(:project, path: "random-unique-domain.example.com")
+
+ expect(project_setting.update(pages_unique_domain: "random-unique-domain")).to eq(false)
+ expect(project_setting.errors.full_messages_for(:pages_unique_domain))
+ .to match(["Pages unique domain already in use"])
+ end
+ end
end
describe 'target_platforms=' do
it 'stringifies and sorts' do
project_setting = build(:project_setting, target_platforms: [:watchos, :ios])
- expect(project_setting.target_platforms).to eq %w(ios watchos)
+ expect(project_setting.target_platforms).to eq %w[ios watchos]
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index f44331521e9..6bf86558f1f 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -827,6 +827,37 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr
expect(project).to be_valid
end
+ context 'when validating if path already exist as pages unique domain' do
+ before do
+ stub_pages_setting(host: 'example.com')
+ end
+
+ it 'rejects paths that match pages unique domain' do
+ create(:project_setting, pages_unique_domain: 'some-unique-domain')
+
+ project = build(:project, path: 'some-unique-domain.example.com')
+
+ expect(project).not_to be_valid
+ expect(project.errors.full_messages_for(:path)).to match(['Path already in use'])
+ end
+
+ it 'accepts path when the host does not match' do
+ create(:project_setting, pages_unique_domain: 'some-unique-domain')
+
+ project = build(:project, path: 'some-unique-domain.another-example.com')
+
+ expect(project).to be_valid
+ end
+
+ it 'accepts path when the domain does not match' do
+ create(:project_setting, pages_unique_domain: 'another-unique-domain')
+
+ project = build(:project, path: 'some-unique-domain.example.com')
+
+ expect(project).to be_valid
+ end
+ end
+
context 'path is unchanged' do
let_it_be(:invalid_path_project) do
project = create(:project, :repository, :public)
@@ -4921,6 +4952,33 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr
project.update!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
end
+ context 'when validating if path already exist as pages unique domain' do
+ before do
+ stub_pages_setting(host: 'example.com')
+ end
+
+ it 'rejects paths that match pages unique domain' do
+ stub_pages_setting(host: 'example.com')
+ create(:project_setting, pages_unique_domain: 'some-unique-domain')
+
+ expect(project.update(path: 'some-unique-domain.example.com')).to eq(false)
+ expect(project.errors.full_messages_for(:path)).to match(['Path already in use'])
+ end
+
+ it 'accepts path when the host does not match' do
+ create(:project_setting, pages_unique_domain: 'some-unique-domain')
+
+ expect(project.update(path: 'some-unique-domain.another-example.com')).to eq(true)
+ end
+
+ it 'accepts path when the domain does not match' do
+ stub_pages_setting(host: 'example.com')
+ create(:project_setting, pages_unique_domain: 'another-unique-domain')
+
+ expect(project.update(path: 'some-unique-domain.example.com')).to eq(true)
+ end
+ end
+
it 'does not validate the visibility' do
expect(project).not_to receive(:visibility_level_allowed_as_fork).and_call_original
expect(project).not_to receive(:visibility_level_allowed_by_group).and_call_original