diff options
author | Rémy Coutable <remy@rymai.me> | 2017-10-27 12:04:22 +0000 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2017-10-28 11:34:06 +0000 |
commit | f7f54e0663ad9019585a9b2065d6dcb5ebe347fc (patch) | |
tree | f5705c250378865fd50d125e711d4679d13bed18 /spec | |
parent | 60653ce6d8d929f15a244150864d0cf9f94177a3 (diff) | |
download | gitlab-ce-f7f54e0663ad9019585a9b2065d6dcb5ebe347fc.tar.gz |
Merge branch 'ac-k8s-namespace-validator' into 'master'
Sanitize k8s default_namespace
Closes #38692
See merge request gitlab-org/gitlab-ce!15053
(cherry picked from commit 172ebcb8bb9c0b4d3c565560880fc604cae02b5e)
a1b3cd40 namespace should be lowercased in kubernetes. This is also true for the scenario…
6798bab1 Remove duped tests
3aafcc16 Add KubernetesService#default_namespace tests
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/project_services/kubernetes_service_spec.rb | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb index 2298dcab55f..00de536a18b 100644 --- a/spec/models/project_services/kubernetes_service_spec.rb +++ b/spec/models/project_services/kubernetes_service_spec.rb @@ -99,45 +99,34 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do describe '#actual_namespace' do subject { service.actual_namespace } - it "returns the default namespace" do - is_expected.to eq(service.send(:default_namespace)) - end - - context 'when namespace is specified' do - before do - service.namespace = 'my-namespace' + shared_examples 'a correctly formatted namespace' do + it 'returns a valid Kubernetes namespace name' do + expect(subject).to match(Gitlab::Regex.kubernetes_namespace_regex) + expect(subject).to eq(expected_namespace) end + end - it "returns the user-namespace" do - is_expected.to eq('my-namespace') - end + it_behaves_like 'a correctly formatted namespace' do + let(:expected_namespace) { service.send(:default_namespace) } end - context 'when service is not assigned to project' do + context 'when the project path contains forbidden characters' do before do - service.project = nil + project.path = '-a_Strange.Path--forSure' end - it "does not return namespace" do - is_expected.to be_nil + it_behaves_like 'a correctly formatted namespace' do + let(:expected_namespace) { "a-strange-path--forsure-#{project.id}" } end end - end - - describe '#actual_namespace' do - subject { service.actual_namespace } - - it "returns the default namespace" do - is_expected.to eq(service.send(:default_namespace)) - end context 'when namespace is specified' do before do service.namespace = 'my-namespace' end - it "returns the user-namespace" do - is_expected.to eq('my-namespace') + it_behaves_like 'a correctly formatted namespace' do + let(:expected_namespace) { 'my-namespace' } end end @@ -146,7 +135,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do service.project = nil end - it "does not return namespace" do + it 'does not return namespace' do is_expected.to be_nil end end |