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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a8f4eadb
Commit
a8f4eadb
authored
Mar 09, 2019
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract EE specific specs into ee/ directory
parent
b2c69c59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
96 deletions
+106
-96
ee/spec/requests/api/triggers_spec.rb
ee/spec/requests/api/triggers_spec.rb
+106
-0
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+0
-96
No files found.
ee/spec/requests/api/triggers_spec.rb
0 → 100644
View file @
a8f4eadb
# frozen_string_literal: true
require
'spec_helper'
describe
API
::
Triggers
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
creator:
user
)
}
describe
'POST /projects/:project_id/trigger/pipeline'
do
context
'when triggering a pipeline from a job token'
do
let
(
:other_job
)
{
create
(
:ci_build
,
:running
,
user:
other_user
)
}
let
(
:params
)
{
{
ref:
'refs/heads/other-branch'
}
}
subject
do
post
api
(
"/projects/
#{
project
.
id
}
/ref/master/trigger/pipeline?token=
#{
other_job
.
token
}
"
),
params:
params
end
context
'without user'
do
let
(
:other_user
)
{
nil
}
it
'does not leak the presence of project when using valid token'
do
subject
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'for unreleated user'
do
let
(
:other_user
)
{
create
(
:user
)
}
it
'does not leak the presence of project when using valid token'
do
subject
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'for related user'
do
let
(
:other_user
)
{
create
(
:user
)
}
context
'with reporter permissions'
do
before
do
project
.
add_reporter
(
other_user
)
end
it
'forbids to create a pipeline'
do
subject
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
"base"
=>
[
"Insufficient permissions to create a new pipeline"
])
end
end
context
'with developer permissions'
do
before
do
project
.
add_developer
(
other_user
)
end
it
'creates a new pipeline'
do
expect
{
subject
}.
to
change
(
Ci
::
Pipeline
,
:count
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
Ci
::
Pipeline
.
last
.
source
).
to
eq
(
'pipeline'
)
expect
(
Ci
::
Pipeline
.
last
.
triggered_by_pipeline
).
not_to
be_nil
expect
(
Ci
::
Sources
::
Pipeline
.
last
).
to
have_attributes
(
pipeline_id:
(
a_value
>
0
),
source_pipeline_id:
(
a_value
>
0
),
source_job_id:
(
a_value
>
0
),
source_project_id:
(
a_value
>
0
)
)
end
context
'when build is complete'
do
before
do
other_job
.
success
end
it
'does not create a pipeline'
do
subject
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 Job has to be running'
)
end
end
context
'when variables are defined'
do
let
(
:params
)
do
{
ref:
'refs/heads/other-branch'
,
variables:
{
'KEY'
=>
'VALUE'
}
}
end
it
'creates a new pipeline with a variable'
do
expect
{
subject
}.
to
change
(
Ci
::
Pipeline
,
:count
)
.
and
change
(
Ci
::
PipelineVariable
,
:count
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
Ci
::
Pipeline
.
last
.
source
).
to
eq
(
'pipeline'
)
expect
(
Ci
::
Pipeline
.
last
.
triggered_by_pipeline
).
not_to
be_nil
expect
(
Ci
::
Pipeline
.
last
.
variables
.
map
{
|
v
|
{
v
.
key
=>
v
.
value
}
}.
last
).
to
eq
(
params
[
:variables
])
end
end
end
end
end
end
end
spec/requests/api/triggers_spec.rb
View file @
a8f4eadb
...
...
@@ -130,102 +130,6 @@ describe API::Triggers do
end
end
end
context
'when triggering a pipeline from a job token'
do
let
(
:other_job
)
{
create
(
:ci_build
,
:running
,
user:
other_user
)
}
let
(
:params
)
{
{
ref:
'refs/heads/other-branch'
}
}
subject
do
post
api
(
"/projects/
#{
project
.
id
}
/ref/master/trigger/pipeline?token=
#{
other_job
.
token
}
"
),
params:
params
end
context
'without user'
do
let
(
:other_user
)
{
nil
}
it
'does not leak the presence of project when using valid token'
do
subject
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'for unreleated user'
do
let
(
:other_user
)
{
create
(
:user
)
}
it
'does not leak the presence of project when using valid token'
do
subject
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'for related user'
do
let
(
:other_user
)
{
create
(
:user
)
}
context
'with reporter permissions'
do
before
do
project
.
add_reporter
(
other_user
)
end
it
'forbids to create a pipeline'
do
subject
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
"base"
=>
[
"Insufficient permissions to create a new pipeline"
])
end
end
context
'with developer permissions'
do
before
do
project
.
add_developer
(
other_user
)
end
it
'creates a new pipeline'
do
expect
{
subject
}.
to
change
(
Ci
::
Pipeline
,
:count
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
Ci
::
Pipeline
.
last
.
source
).
to
eq
(
'pipeline'
)
expect
(
Ci
::
Pipeline
.
last
.
triggered_by_pipeline
).
not_to
be_nil
expect
(
Ci
::
Sources
::
Pipeline
.
last
).
to
have_attributes
(
pipeline_id:
(
a_value
>
0
),
source_pipeline_id:
(
a_value
>
0
),
source_job_id:
(
a_value
>
0
),
source_project_id:
(
a_value
>
0
)
)
end
context
'when build is complete'
do
before
do
other_job
.
success
end
it
'does not create a pipeline'
do
subject
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 Job has to be running'
)
end
end
context
'when variables are defined'
do
let
(
:params
)
do
{
ref:
'refs/heads/other-branch'
,
variables:
{
'KEY'
=>
'VALUE'
}
}
end
it
'creates a new pipeline with a variable'
do
expect
{
subject
}.
to
change
(
Ci
::
Pipeline
,
:count
)
.
and
change
(
Ci
::
PipelineVariable
,
:count
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
Ci
::
Pipeline
.
last
.
source
).
to
eq
(
'pipeline'
)
expect
(
Ci
::
Pipeline
.
last
.
triggered_by_pipeline
).
not_to
be_nil
expect
(
Ci
::
Pipeline
.
last
.
variables
.
map
{
|
v
|
{
v
.
key
=>
v
.
value
}
}.
last
).
to
eq
(
params
[
:variables
])
end
end
end
end
end
end
describe
'GET /projects/:id/triggers'
do
...
...
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