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
a5bf6fa9
Commit
a5bf6fa9
authored
May 12, 2020
by
Giorgenes Gelatti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor composer specs
Refactor composer API specs to be more DRY
parent
24c9ac0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
37 deletions
+33
-37
ee/spec/requests/api/composer_packages_spec.rb
ee/spec/requests/api/composer_packages_spec.rb
+12
-37
ee/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb
...xamples/requests/api/composer_packages_shared_examples.rb
+21
-0
No files found.
ee/spec/requests/api/composer_packages_spec.rb
View file @
a5bf6fa9
...
...
@@ -8,11 +8,12 @@ describe API::ComposerPackages do
let_it_be
(
:group
,
reload:
true
)
{
create
(
:group
,
:public
)
}
let_it_be
(
:personal_access_token
)
{
create
(
:personal_access_token
,
user:
user
)
}
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:repository
,
path:
'my.project'
)
}
let
(
:headers
)
{
{}
}
describe
'GET /api/v4/group/:id/-/packages/composer/packages'
do
let
(
:url
)
{
"/group/
#{
group
.
id
}
/-/packages/composer/packages.json"
}
subject
{
get
api
(
url
)
}
subject
{
get
api
(
url
)
,
headers:
headers
}
context
'with packages features enabled'
do
before
do
...
...
@@ -44,16 +45,9 @@ describe API::ComposerPackages do
end
with_them
do
let
(
:token
)
{
user_token
?
personal_access_token
.
token
:
'wrong'
}
let
(
:headers
)
{
user_role
==
:anonymous
?
{}
:
build_basic_auth_header
(
user
.
username
,
token
)
}
subject
{
get
api
(
url
),
headers:
headers
}
before
do
group
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
.
const_get
(
project_visibility_level
,
false
))
include_context
'Composer api group access'
,
params
[
:project_visibility_level
],
params
[
:user_role
],
params
[
:user_token
]
do
it_behaves_like
params
[
:shared_examples_name
],
params
[
:user_role
],
params
[
:expected_status
],
params
[
:member
]
end
it_behaves_like
params
[
:shared_examples_name
],
params
[
:user_role
],
params
[
:expected_status
],
params
[
:member
]
end
end
...
...
@@ -67,7 +61,7 @@ describe API::ComposerPackages do
let
(
:sha
)
{
'123'
}
let
(
:url
)
{
"/group/
#{
group
.
id
}
/-/packages/composer/p/
#{
sha
}
.json"
}
subject
{
get
api
(
url
)
}
subject
{
get
api
(
url
)
,
headers:
headers
}
context
'with packages features enabled'
do
before
do
...
...
@@ -99,16 +93,9 @@ describe API::ComposerPackages do
end
with_them
do
let
(
:token
)
{
user_token
?
personal_access_token
.
token
:
'wrong'
}
let
(
:headers
)
{
user_role
==
:anonymous
?
{}
:
build_basic_auth_header
(
user
.
username
,
token
)
}
subject
{
get
api
(
url
),
headers:
headers
}
before
do
group
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
.
const_get
(
project_visibility_level
,
false
))
include_context
'Composer api group access'
,
params
[
:project_visibility_level
],
params
[
:user_role
],
params
[
:user_token
]
do
it_behaves_like
params
[
:shared_examples_name
],
params
[
:user_role
],
params
[
:expected_status
],
params
[
:member
]
end
it_behaves_like
params
[
:shared_examples_name
],
params
[
:user_role
],
params
[
:expected_status
],
params
[
:member
]
end
end
...
...
@@ -122,7 +109,7 @@ describe API::ComposerPackages do
let
(
:package_name
)
{
'foobar'
}
let
(
:url
)
{
"/group/
#{
group
.
id
}
/-/packages/composer/
#{
package_name
}
.json"
}
subject
{
get
api
(
url
)
}
subject
{
get
api
(
url
)
,
headers:
headers
}
context
'with packages features enabled'
do
before
do
...
...
@@ -154,16 +141,9 @@ describe API::ComposerPackages do
end
with_them
do
let
(
:token
)
{
user_token
?
personal_access_token
.
token
:
'wrong'
}
let
(
:headers
)
{
user_role
==
:anonymous
?
{}
:
build_basic_auth_header
(
user
.
username
,
token
)
}
subject
{
get
api
(
url
),
headers:
headers
}
before
do
group
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
.
const_get
(
project_visibility_level
,
false
))
include_context
'Composer api group access'
,
params
[
:project_visibility_level
],
params
[
:user_role
],
params
[
:user_token
]
do
it_behaves_like
params
[
:shared_examples_name
],
params
[
:user_role
],
params
[
:expected_status
],
params
[
:member
]
end
it_behaves_like
params
[
:shared_examples_name
],
params
[
:user_role
],
params
[
:expected_status
],
params
[
:member
]
end
end
...
...
@@ -210,14 +190,9 @@ describe API::ComposerPackages do
end
with_them
do
let
(
:token
)
{
user_token
?
personal_access_token
.
token
:
'wrong'
}
let
(
:headers
)
{
user_role
==
:anonymous
?
{}
:
build_basic_auth_header
(
user
.
username
,
token
)
}
before
do
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
.
const_get
(
project_visibility_level
,
false
))
include_context
'Composer api project access'
,
params
[
:project_visibility_level
],
params
[
:user_role
],
params
[
:user_token
]
do
it_behaves_like
params
[
:shared_examples_name
],
params
[
:user_role
],
params
[
:expected_status
],
params
[
:member
]
end
it_behaves_like
params
[
:shared_examples_name
],
params
[
:user_role
],
params
[
:expected_status
],
params
[
:member
]
end
end
...
...
ee/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb
View file @
a5bf6fa9
...
...
@@ -11,6 +11,27 @@ RSpec.shared_examples 'process Composer api request' do |user_type, status, add_
end
end
RSpec
.
shared_context
'Composer auth headers'
do
|
user_role
,
user_token
|
let
(
:token
)
{
user_token
?
personal_access_token
.
token
:
'wrong'
}
let
(
:headers
)
{
user_role
==
:anonymous
?
{}
:
build_basic_auth_header
(
user
.
username
,
token
)
}
end
RSpec
.
shared_context
'Composer api project access'
do
|
project_visibility_level
,
user_role
,
user_token
|
include_context
'Composer auth headers'
,
user_role
,
user_token
do
before
do
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
.
const_get
(
project_visibility_level
,
false
))
end
end
end
RSpec
.
shared_context
'Composer api group access'
do
|
project_visibility_level
,
user_role
,
user_token
|
include_context
'Composer auth headers'
,
user_role
,
user_token
do
before
do
group
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
.
const_get
(
project_visibility_level
,
false
))
end
end
end
RSpec
.
shared_examples
'rejects Composer access with unknown group id'
do
context
'with an unknown group'
do
let
(
:group
)
{
double
(
id:
non_existing_record_id
)
}
...
...
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