Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
9f6dc8b2
Commit
9f6dc8b2
authored
May 25, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests and also pass protected vars to protected tags
parent
96956d47
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
5 deletions
+74
-5
app/models/ci/build.rb
app/models/ci/build.rb
+3
-1
spec/factories/ci/variables.rb
spec/factories/ci/variables.rb
+4
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+37
-4
spec/models/project_spec.rb
spec/models/project_spec.rb
+30
-0
No files found.
app/models/ci/build.rb
View file @
9f6dc8b2
...
@@ -186,7 +186,9 @@ module Ci
...
@@ -186,7 +186,9 @@ module Ci
variables
+=
yaml_variables
variables
+=
yaml_variables
variables
+=
user_variables
variables
+=
user_variables
variables
+=
project
.
secret_variables
variables
+=
project
.
secret_variables
variables
+=
project
.
protected_variables
if
ProtectedBranch
.
protected?
(
project
,
ref
)
variables
+=
project
.
protected_variables
if
ProtectedBranch
.
protected?
(
project
,
ref
)
||
ProtectedTag
.
protected?
(
project
,
ref
)
variables
+=
trigger_request
.
user_variables
if
trigger_request
variables
+=
trigger_request
.
user_variables
if
trigger_request
variables
variables
end
end
...
...
spec/factories/ci/variables.rb
View file @
9f6dc8b2
...
@@ -3,6 +3,10 @@ FactoryGirl.define do
...
@@ -3,6 +3,10 @@ FactoryGirl.define do
sequence
(
:key
)
{
|
n
|
"VARIABLE_
#{
n
}
"
}
sequence
(
:key
)
{
|
n
|
"VARIABLE_
#{
n
}
"
}
value
'VARIABLE_VALUE'
value
'VARIABLE_VALUE'
trait
(
:protected
)
do
protected
true
end
project
factory: :empty_project
project
factory: :empty_project
end
end
end
end
spec/models/ci/build_spec.rb
View file @
9f6dc8b2
...
@@ -1215,16 +1215,49 @@ describe Ci::Build, :models do
...
@@ -1215,16 +1215,49 @@ describe Ci::Build, :models do
it
{
is_expected
.
to
include
(
tag_variable
)
}
it
{
is_expected
.
to
include
(
tag_variable
)
}
end
end
context
'when sec
ure
variable is defined'
do
context
'when sec
ret
variable is defined'
do
let
(
:sec
ure
_variable
)
do
let
(
:sec
ret
_variable
)
do
{
key:
'SECRET_KEY'
,
value:
'secret_value'
,
public:
false
}
{
key:
'SECRET_KEY'
,
value:
'secret_value'
,
public:
false
}
end
end
before
do
before
do
build
.
project
.
variables
<<
Ci
::
Variable
.
new
(
key:
'SECRET_KEY'
,
value:
'secret_value'
)
create
(
:ci_variable
,
secret_variable
.
slice
(
:key
,
:value
).
merge
(
project:
project
))
end
end
it
{
is_expected
.
to
include
(
secure_variable
)
}
it
{
is_expected
.
to
include
(
secret_variable
)
}
end
context
'when protected variable is defined'
do
let
(
:protected_variable
)
do
{
key:
'PROTECTED_KEY'
,
value:
'protected_value'
,
public:
false
}
end
before
do
create
(
:ci_variable
,
:protected
,
protected_variable
.
slice
(
:key
,
:value
).
merge
(
project:
project
))
end
context
'when the branch is protected'
do
before
do
create
(
:protected_branch
,
project:
build
.
project
,
name:
build
.
ref
)
end
it
{
is_expected
.
to
include
(
protected_variable
)
}
end
context
'when the tag is protected'
do
before
do
create
(
:protected_tag
,
project:
build
.
project
,
name:
build
.
ref
)
end
it
{
is_expected
.
to
include
(
protected_variable
)
}
end
context
'when the ref is not protected'
do
it
{
is_expected
.
not_to
include
(
protected_variable
)
}
end
end
end
context
'when build is for triggers'
do
context
'when build is for triggers'
do
...
...
spec/models/project_spec.rb
View file @
9f6dc8b2
...
@@ -1710,6 +1710,36 @@ describe Project, models: true do
...
@@ -1710,6 +1710,36 @@ describe Project, models: true do
end
end
end
end
describe
'variables'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:secret_variable
)
do
create
(
:ci_variable
,
value:
'secret'
,
project:
project
)
end
let!
(
:protected_variable
)
do
create
(
:ci_variable
,
:protected
,
value:
'protected'
,
project:
project
)
end
describe
'#secret_variables'
do
it
'contains only the secret variables'
do
expect
(
project
.
secret_variables
).
to
eq
(
[{
key:
secret_variable
.
key
,
value:
secret_variable
.
value
,
public:
false
}
])
end
end
describe
'#protected_variables'
do
it
'contains only the protected variables'
do
expect
(
project
.
protected_variables
).
to
eq
(
[{
key:
protected_variable
.
key
,
value:
protected_variable
.
value
,
public:
false
}
])
end
end
end
describe
'#update_project_statistics'
do
describe
'#update_project_statistics'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment