Commit 453cc7d4 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'check-environment-regex' into 'master'

Fix environment scope regex

See merge request gitlab-org/gitlab-ee!3641
parents 95f8d4e9 7b33aff4
---
title: Fix validation of environment scope for Ci::Variable
merge_request: 3641
author:
type: fixed
......@@ -38,7 +38,7 @@ module Gitlab
end
def environment_name_regex_chars
'a-zA-Z0-9_/\\$\\{\\}\\. -'
'a-zA-Z0-9_/\\$\\{\\}\\. \\-'
end
def environment_name_regex
......
# coding: utf-8
require 'spec_helper'
describe Gitlab::Regex do
describe '.environment_scope_regex' do
subject { described_class.environment_scope_regex }
it { is_expected.to match('foo') }
it { is_expected.to match('foo*Z') }
it { is_expected.not_to match('!!()()') }
end
end
......@@ -6,7 +6,7 @@ describe HasEnvironmentScope do
it { is_expected.to allow_value('*').for(:environment_scope) }
it { is_expected.to allow_value('review/*').for(:environment_scope) }
it { is_expected.not_to allow_value('').for(:environment_scope) }
it { is_expected.not_to allow_value('<>').for(:environment_scope) }
it { is_expected.not_to allow_value('!!()()').for(:environment_scope) }
it do
is_expected.to validate_uniqueness_of(:key)
......
......@@ -759,7 +759,7 @@ describe Project do
context 'when environment scope is exactly matched' do
before do
cluster.update(environment_scope: 'review/name')
cluster.update!(environment_scope: 'review/name')
end
it_behaves_like 'matching environment scope'
......@@ -767,7 +767,7 @@ describe Project do
context 'when environment scope is matched by wildcard' do
before do
cluster.update(environment_scope: 'review/*')
cluster.update!(environment_scope: 'review/*')
end
it_behaves_like 'matching environment scope'
......@@ -775,7 +775,7 @@ describe Project do
context 'when environment scope does not match' do
before do
cluster.update(environment_scope: 'review/*/special')
cluster.update!(environment_scope: 'review/*/special')
end
it_behaves_like 'not matching environment scope'
......@@ -789,14 +789,14 @@ describe Project do
end
it 'does not treat it as wildcard' do
cluster.update(environment_scope: 'foo_bar/*')
cluster.update!(environment_scope: 'foo_bar/*')
is_expected.to eq(default_cluster.platform_kubernetes)
end
it 'matches literally for _' do
cluster.update(environment_scope: 'foo_bar/*')
environment.update(name: 'foo_bar/test')
cluster.update!(environment_scope: 'foo_bar/*')
environment.update!(name: 'foo_bar/test')
is_expected.to eq(cluster.platform_kubernetes)
end
......@@ -819,8 +819,8 @@ describe Project do
is_expected.to eq(default_cluster.platform_kubernetes)
end
it 'matches literally for _' do
cluster.update(environment_scope: 'foo%bar/*')
it 'matches literally for %' do
cluster.update_attribute(:environment_scope, 'foo%bar/*')
environment.update_attribute(:name, 'foo%bar/test')
is_expected.to eq(cluster.platform_kubernetes)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment