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
c467392a
Commit
c467392a
authored
Jan 21, 2021
by
Mathieu Parent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tidy up Debian repository specs
parent
bfe3044a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
147 additions
and
250 deletions
+147
-250
spec/requests/api/debian_group_packages_spec.rb
spec/requests/api/debian_group_packages_spec.rb
+11
-11
spec/requests/api/debian_project_packages_spec.rb
spec/requests/api/debian_project_packages_spec.rb
+15
-15
spec/support/shared_examples/requests/api/debian_packages_shared_examples.rb
..._examples/requests/api/debian_packages_shared_examples.rb
+121
-224
No files found.
spec/requests/api/debian_group_packages_spec.rb
View file @
c467392a
...
@@ -5,35 +5,35 @@ RSpec.describe API::DebianGroupPackages do
...
@@ -5,35 +5,35 @@ RSpec.describe API::DebianGroupPackages do
include
HttpBasicAuthHelpers
include
HttpBasicAuthHelpers
include
WorkhorseHelpers
include
WorkhorseHelpers
include_context
'Debian repository shared context'
,
:group
do
include_context
'Debian repository shared context'
,
:group
,
false
do
describe
'GET groups/:id/-/packages/debian/dists/*distribution/Release.gpg'
do
describe
'GET groups/:id/-/packages/debian/dists/*distribution/Release.gpg'
do
let
(
:url
)
{
"/groups/
#{
group
.
id
}
/-/packages/debian/dists/
#{
distribution
}
/Release.gpg"
}
let
(
:url
)
{
"/groups/
#{
container
.
id
}
/-/packages/debian/dists/
#{
distribution
}
/Release.gpg"
}
it_behaves_like
'Debian
group repository GET endpoint'
,
:not_found
,
nil
it_behaves_like
'Debian
repository read endpoint'
,
'GET request'
,
:not_found
end
end
describe
'GET groups/:id/-/packages/debian/dists/*distribution/Release'
do
describe
'GET groups/:id/-/packages/debian/dists/*distribution/Release'
do
let
(
:url
)
{
"/groups/
#{
group
.
id
}
/-/packages/debian/dists/
#{
distribution
}
/Release"
}
let
(
:url
)
{
"/groups/
#{
container
.
id
}
/-/packages/debian/dists/
#{
distribution
}
/Release"
}
it_behaves_like
'Debian
group repository GET endpoin
t'
,
:success
,
'TODO Release'
it_behaves_like
'Debian
repository read endpoint'
,
'GET reques
t'
,
:success
,
'TODO Release'
end
end
describe
'GET groups/:id/-/packages/debian/dists/*distribution/InRelease'
do
describe
'GET groups/:id/-/packages/debian/dists/*distribution/InRelease'
do
let
(
:url
)
{
"/groups/
#{
group
.
id
}
/-/packages/debian/dists/
#{
distribution
}
/InRelease"
}
let
(
:url
)
{
"/groups/
#{
container
.
id
}
/-/packages/debian/dists/
#{
distribution
}
/InRelease"
}
it_behaves_like
'Debian
group repository GET endpoint'
,
:not_found
,
nil
it_behaves_like
'Debian
repository read endpoint'
,
'GET request'
,
:not_found
end
end
describe
'GET groups/:id/-/packages/debian/dists/*distribution/:component/binary-:architecture/Packages'
do
describe
'GET groups/:id/-/packages/debian/dists/*distribution/:component/binary-:architecture/Packages'
do
let
(
:url
)
{
"/groups/
#{
group
.
id
}
/-/packages/debian/dists/
#{
distribution
}
/
#{
component
}
/binary-
#{
architecture
}
/Packages"
}
let
(
:url
)
{
"/groups/
#{
container
.
id
}
/-/packages/debian/dists/
#{
distribution
}
/
#{
component
}
/binary-
#{
architecture
}
/Packages"
}
it_behaves_like
'Debian
group repository GET endpoin
t'
,
:success
,
'TODO Packages'
it_behaves_like
'Debian
repository read endpoint'
,
'GET reques
t'
,
:success
,
'TODO Packages'
end
end
describe
'GET groups/:id/-/packages/debian/pool/:component/:letter/:source_package/:file_name'
do
describe
'GET groups/:id/-/packages/debian/pool/:component/:letter/:source_package/:file_name'
do
let
(
:url
)
{
"/groups/
#{
group
.
id
}
/-/packages/debian/pool/
#{
component
}
/
#{
letter
}
/
#{
source_package
}
/
#{
package_name
}
_
#{
package_version
}
_
#{
architecture
}
.deb"
}
let
(
:url
)
{
"/groups/
#{
container
.
id
}
/-/packages/debian/pool/
#{
component
}
/
#{
letter
}
/
#{
source_package
}
/
#{
package_name
}
_
#{
package_version
}
_
#{
architecture
}
.deb"
}
it_behaves_like
'Debian
group repository GET endpoin
t'
,
:success
,
'TODO File'
it_behaves_like
'Debian
repository read endpoint'
,
'GET reques
t'
,
:success
,
'TODO File'
end
end
end
end
end
end
spec/requests/api/debian_project_packages_spec.rb
View file @
c467392a
...
@@ -5,49 +5,49 @@ RSpec.describe API::DebianProjectPackages do
...
@@ -5,49 +5,49 @@ RSpec.describe API::DebianProjectPackages do
include
HttpBasicAuthHelpers
include
HttpBasicAuthHelpers
include
WorkhorseHelpers
include
WorkhorseHelpers
include_context
'Debian repository shared context'
,
:project
do
include_context
'Debian repository shared context'
,
:project
,
true
do
describe
'GET projects/:id/packages/debian/dists/*distribution/Release.gpg'
do
describe
'GET projects/:id/packages/debian/dists/*distribution/Release.gpg'
do
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/debian/dists/
#{
distribution
}
/Release.gpg"
}
let
(
:url
)
{
"/projects/
#{
container
.
id
}
/packages/debian/dists/
#{
distribution
}
/Release.gpg"
}
it_behaves_like
'Debian
project repository GET endpoint'
,
:not_found
,
nil
it_behaves_like
'Debian
repository read endpoint'
,
'GET request'
,
:not_found
end
end
describe
'GET projects/:id/packages/debian/dists/*distribution/Release'
do
describe
'GET projects/:id/packages/debian/dists/*distribution/Release'
do
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/debian/dists/
#{
distribution
}
/Release"
}
let
(
:url
)
{
"/projects/
#{
container
.
id
}
/packages/debian/dists/
#{
distribution
}
/Release"
}
it_behaves_like
'Debian
project repository GET endpoin
t'
,
:success
,
'TODO Release'
it_behaves_like
'Debian
repository read endpoint'
,
'GET reques
t'
,
:success
,
'TODO Release'
end
end
describe
'GET projects/:id/packages/debian/dists/*distribution/InRelease'
do
describe
'GET projects/:id/packages/debian/dists/*distribution/InRelease'
do
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/debian/dists/
#{
distribution
}
/InRelease"
}
let
(
:url
)
{
"/projects/
#{
container
.
id
}
/packages/debian/dists/
#{
distribution
}
/InRelease"
}
it_behaves_like
'Debian
project repository GET endpoint'
,
:not_found
,
nil
it_behaves_like
'Debian
repository read endpoint'
,
'GET request'
,
:not_found
end
end
describe
'GET projects/:id/packages/debian/dists/*distribution/:component/binary-:architecture/Packages'
do
describe
'GET projects/:id/packages/debian/dists/*distribution/:component/binary-:architecture/Packages'
do
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/debian/dists/
#{
distribution
}
/
#{
component
}
/binary-
#{
architecture
}
/Packages"
}
let
(
:url
)
{
"/projects/
#{
container
.
id
}
/packages/debian/dists/
#{
distribution
}
/
#{
component
}
/binary-
#{
architecture
}
/Packages"
}
it_behaves_like
'Debian
project repository GET endpoin
t'
,
:success
,
'TODO Packages'
it_behaves_like
'Debian
repository read endpoint'
,
'GET reques
t'
,
:success
,
'TODO Packages'
end
end
describe
'GET projects/:id/packages/debian/pool/:component/:letter/:source_package/:file_name'
do
describe
'GET projects/:id/packages/debian/pool/:component/:letter/:source_package/:file_name'
do
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/debian/pool/
#{
component
}
/
#{
letter
}
/
#{
source_package
}
/
#{
package_name
}
_
#{
package_version
}
_
#{
architecture
}
.deb"
}
let
(
:url
)
{
"/projects/
#{
container
.
id
}
/packages/debian/pool/
#{
component
}
/
#{
letter
}
/
#{
source_package
}
/
#{
package_name
}
_
#{
package_version
}
_
#{
architecture
}
.deb"
}
it_behaves_like
'Debian
project repository GET endpoin
t'
,
:success
,
'TODO File'
it_behaves_like
'Debian
repository read endpoint'
,
'GET reques
t'
,
:success
,
'TODO File'
end
end
describe
'PUT projects/:id/packages/debian/:file_name'
do
describe
'PUT projects/:id/packages/debian/:file_name'
do
let
(
:method
)
{
:put
}
let
(
:method
)
{
:put
}
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/debian/
#{
file_name
}
"
}
let
(
:url
)
{
"/projects/
#{
container
.
id
}
/packages/debian/
#{
file_name
}
"
}
it_behaves_like
'Debian
project repository PUT endpoint'
,
:created
,
nil
it_behaves_like
'Debian
repository write endpoint'
,
'upload request'
,
:created
end
end
describe
'PUT projects/:id/packages/debian/:file_name/authorize'
do
describe
'PUT projects/:id/packages/debian/:file_name/authorize'
do
let
(
:method
)
{
:put
}
let
(
:method
)
{
:put
}
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/debian/
#{
file_name
}
/authorize"
}
let
(
:url
)
{
"/projects/
#{
container
.
id
}
/packages/debian/
#{
file_name
}
/authorize"
}
it_behaves_like
'Debian
project repository PUT endpoint'
,
:created
,
nil
,
is_authorize:
true
it_behaves_like
'Debian
repository write endpoint'
,
'upload authorize request'
,
:created
end
end
end
end
end
end
spec/support/shared_examples/requests/api/debian_packages_shared_examples.rb
View file @
c467392a
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_context
'Debian repository shared context'
do
|
object_typ
e
|
RSpec
.
shared_context
'Debian repository shared context'
do
|
container_type
,
can_freez
e
|
include_context
'workhorse headers'
include_context
'workhorse headers'
before
do
before
do
stub_feature_flags
(
debian_packages:
true
)
stub_feature_flags
(
debian_packages:
true
)
end
end
if
object_type
==
:project
let_it_be
(
:private_container
,
freeze:
can_freeze
)
{
create
(
container_type
,
:private
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
let_it_be
(
:public_container
,
freeze:
can_freeze
)
{
create
(
container_type
,
:public
)
}
elsif
object_type
==
:group
let_it_be
(
:user
,
freeze:
true
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
,
:public
)
}
let_it_be
(
:personal_access_token
,
freeze:
true
)
{
create
(
:personal_access_token
,
user:
user
)
}
end
let
(
:user
)
{
create
(
:user
)
}
let
(
:personal_access_token
)
{
create
(
:personal_access_token
,
user:
user
)
}
let
(
:distribution
)
{
'bullseye'
}
let
(
:distribution
)
{
'bullseye'
}
let
(
:component
)
{
'main'
}
let
(
:component
)
{
'main'
}
...
@@ -36,7 +32,7 @@ RSpec.shared_context 'Debian repository shared context' do |object_type|
...
@@ -36,7 +32,7 @@ RSpec.shared_context 'Debian repository shared context' do |object_type|
end
end
end
end
let
(
:params
)
{
workhorse_params
}
let
(
:
api_
params
)
{
workhorse_params
}
let
(
:auth_headers
)
{
{}
}
let
(
:auth_headers
)
{
{}
}
let
(
:wh_headers
)
do
let
(
:wh_headers
)
do
...
@@ -57,12 +53,12 @@ RSpec.shared_context 'Debian repository shared context' do |object_type|
...
@@ -57,12 +53,12 @@ RSpec.shared_context 'Debian repository shared context' do |object_type|
api
(
url
),
api
(
url
),
method:
method
,
method:
method
,
file_key: :file
,
file_key: :file
,
params:
params
,
params:
api_
params
,
headers:
headers
,
headers:
headers
,
send_rewritten_field:
send_rewritten_field
send_rewritten_field:
send_rewritten_field
)
)
else
else
send
method
,
api
(
url
),
headers:
headers
,
params:
params
send
method
,
api
(
url
),
headers:
headers
,
params:
api_
params
end
end
end
end
end
end
...
@@ -81,20 +77,18 @@ RSpec.shared_context 'Debian repository auth headers' do |user_role, user_token,
...
@@ -81,20 +77,18 @@ RSpec.shared_context 'Debian repository auth headers' do |user_role, user_token,
end
end
end
end
RSpec
.
shared_context
'Debian repository
project access'
do
|
project_visibility_level
,
user_role
,
user_token
,
auth_method
|
RSpec
.
shared_context
'Debian repository
access'
do
|
visibility_level
,
user_role
,
add_member
,
user_token
,
auth_method
|
include_context
'Debian repository auth headers'
,
user_role
,
user_token
,
auth_method
do
include_context
'Debian repository auth headers'
,
user_role
,
user_token
,
auth_method
do
let
(
:containers
)
{
{
private:
private_container
,
public:
public_container
}
}
let
(
:container
)
{
containers
[
visibility_level
]
}
before
do
before
do
project
.
update_column
(
:visibility_level
,
Gitlab
::
VisibilityLevel
.
const_get
(
project_visibility_level
,
false
))
container
.
send
(
"add_
#{
user_role
}
"
,
user
)
if
add_member
&&
user_role
!=
:anonymous
end
end
end
end
end
end
RSpec
.
shared_examples
'Debian project repository GET request'
do
|
user_role
,
add_member
,
status
,
body
|
RSpec
.
shared_examples
'Debian repository GET request'
do
|
status
,
body
=
nil
|
context
"for user type
#{
user_role
}
"
do
before
do
project
.
send
(
"add_
#{
user_role
}
"
,
user
)
if
add_member
&&
user_role
!=
:anonymous
end
and_body
=
body
.
nil?
?
''
:
' and expected body'
and_body
=
body
.
nil?
?
''
:
' and expected body'
it
"returns
#{
status
}#{
and_body
}
"
do
it
"returns
#{
status
}#{
and_body
}
"
do
...
@@ -106,22 +100,17 @@ RSpec.shared_examples 'Debian project repository GET request' do |user_role, add
...
@@ -106,22 +100,17 @@ RSpec.shared_examples 'Debian project repository GET request' do |user_role, add
expect
(
response
.
body
).
to
eq
(
body
)
expect
(
response
.
body
).
to
eq
(
body
)
end
end
end
end
end
end
end
RSpec
.
shared_examples
'Debian project repository PUT request'
do
|
user_role
,
add_member
,
status
,
body
|
RSpec
.
shared_examples
'Debian repository upload request'
do
|
status
,
body
=
nil
|
context
"for user type
#{
user_role
}
"
do
before
do
project
.
send
(
"add_
#{
user_role
}
"
,
user
)
if
add_member
&&
user_role
!=
:anonymous
end
and_body
=
body
.
nil?
?
''
:
' and expected body'
and_body
=
body
.
nil?
?
''
:
' and expected body'
if
status
==
:created
if
status
==
:created
it
'creates package files'
,
:aggregate_failures
do
it
'creates package files'
,
:aggregate_failures
do
pending
"Debian package creation not implemented"
pending
"Debian package creation not implemented"
expect
{
subject
}
expect
{
subject
}
.
to
change
{
project
.
packages
.
debian
.
count
}.
by
(
1
)
.
to
change
{
container
.
packages
.
debian
.
count
}.
by
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
status
)
expect
(
response
).
to
have_gitlab_http_status
(
status
)
expect
(
response
.
media_type
).
to
eq
(
'text/plain'
)
expect
(
response
.
media_type
).
to
eq
(
'text/plain'
)
...
@@ -142,15 +131,9 @@ RSpec.shared_examples 'Debian project repository PUT request' do |user_role, add
...
@@ -142,15 +131,9 @@ RSpec.shared_examples 'Debian project repository PUT request' do |user_role, add
end
end
end
end
end
end
end
end
end
RSpec
.
shared_examples
'Debian project repository PUT authorize request'
do
|
user_role
,
add_member
,
status
,
body
,
is_authorize
|
RSpec
.
shared_examples
'Debian repository upload authorize request'
do
|
status
,
body
=
nil
|
context
"for user type
#{
user_role
}
"
do
before
do
project
.
send
(
"add_
#{
user_role
}
"
,
user
)
if
add_member
&&
user_role
!=
:anonymous
end
and_body
=
body
.
nil?
?
''
:
' and expected body'
and_body
=
body
.
nil?
?
''
:
' and expected body'
if
status
==
:created
if
status
==
:created
...
@@ -194,176 +177,90 @@ RSpec.shared_examples 'Debian project repository PUT authorize request' do |user
...
@@ -194,176 +177,90 @@ RSpec.shared_examples 'Debian project repository PUT authorize request' do |user
end
end
end
end
end
end
end
end
end
RSpec
.
shared_examples
'rejects Debian access with unknown
project
id'
do
RSpec
.
shared_examples
'rejects Debian access with unknown
container
id'
do
context
'with an unknown
project
'
do
context
'with an unknown
container
'
do
let
(
:
project
)
{
double
(
id:
non_existing_record_id
)
}
let
(
:
container
)
{
double
(
id:
non_existing_record_id
)
}
context
'as anonymous'
do
context
'as anonymous'
do
it_behaves_like
'Debian
project repository GET request'
,
:anonymous
,
true
,
:unauthorized
,
nil
it_behaves_like
'Debian
repository GET request'
,
:unauthorized
,
nil
end
end
context
'as authenticated user'
do
context
'as authenticated user'
do
subject
{
get
api
(
url
),
headers:
basic_auth_header
(
user
.
username
,
personal_access_token
.
token
)
}
subject
{
get
api
(
url
),
headers:
basic_auth_header
(
user
.
username
,
personal_access_token
.
token
)
}
it_behaves_like
'Debian
project repository GET request'
,
:anonymous
,
true
,
:not_found
,
nil
it_behaves_like
'Debian
repository GET request'
,
:not_found
,
nil
end
end
end
end
end
end
RSpec
.
shared_examples
'Debian
project repository GET endpoint'
do
|
success_status
,
success_body
|
RSpec
.
shared_examples
'Debian
repository read endpoint'
do
|
desired_behavior
,
success_status
,
success_body
|
context
'with valid
project
'
do
context
'with valid
container
'
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:
project_
visibility_level
,
:user_role
,
:member
,
:user_token
,
:expected_status
,
:expected_body
)
do
where
(
:visibility_level
,
:user_role
,
:member
,
:user_token
,
:expected_status
,
:expected_body
)
do
'PUBLIC'
|
:developer
|
true
|
true
|
success_status
|
success_body
:public
|
:developer
|
true
|
true
|
success_status
|
success_body
'PUBLIC'
|
:guest
|
true
|
true
|
success_status
|
success_body
:public
|
:guest
|
true
|
true
|
success_status
|
success_body
'PUBLIC'
|
:developer
|
true
|
false
|
success_status
|
success_body
:public
|
:developer
|
true
|
false
|
success_status
|
success_body
'PUBLIC'
|
:guest
|
true
|
false
|
success_status
|
success_body
:public
|
:guest
|
true
|
false
|
success_status
|
success_body
'PUBLIC'
|
:developer
|
false
|
true
|
success_status
|
success_body
:public
|
:developer
|
false
|
true
|
success_status
|
success_body
'PUBLIC'
|
:guest
|
false
|
true
|
success_status
|
success_body
:public
|
:guest
|
false
|
true
|
success_status
|
success_body
'PUBLIC'
|
:developer
|
false
|
false
|
success_status
|
success_body
:public
|
:developer
|
false
|
false
|
success_status
|
success_body
'PUBLIC'
|
:guest
|
false
|
false
|
success_status
|
success_body
:public
|
:guest
|
false
|
false
|
success_status
|
success_body
'PUBLIC'
|
:anonymous
|
false
|
true
|
success_status
|
success_body
:public
|
:anonymous
|
false
|
true
|
success_status
|
success_body
'PRIVATE'
|
:developer
|
true
|
true
|
success_status
|
success_body
:private
|
:developer
|
true
|
true
|
success_status
|
success_body
'PRIVATE'
|
:guest
|
true
|
true
|
:forbidden
|
nil
:private
|
:guest
|
true
|
true
|
:forbidden
|
nil
'PRIVATE'
|
:developer
|
true
|
false
|
:unauthorized
|
nil
:private
|
:developer
|
true
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:guest
|
true
|
false
|
:unauthorized
|
nil
:private
|
:guest
|
true
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:developer
|
false
|
true
|
:not_found
|
nil
:private
|
:developer
|
false
|
true
|
:not_found
|
nil
'PRIVATE'
|
:guest
|
false
|
true
|
:not_found
|
nil
:private
|
:guest
|
false
|
true
|
:not_found
|
nil
'PRIVATE'
|
:developer
|
false
|
false
|
:unauthorized
|
nil
:private
|
:developer
|
false
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:guest
|
false
|
false
|
:unauthorized
|
nil
:private
|
:guest
|
false
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:anonymous
|
false
|
true
|
:unauthorized
|
nil
:private
|
:anonymous
|
false
|
true
|
:unauthorized
|
nil
end
end
with_them
do
with_them
do
include_context
'Debian repository project access'
,
params
[
:project_visibility_level
],
params
[
:user_role
],
params
[
:user_token
],
:basic
do
include_context
'Debian repository access'
,
params
[
:visibility_level
],
params
[
:user_role
],
params
[
:member
],
params
[
:user_token
],
:basic
do
it_behaves_like
'Debian project repository GET request'
,
params
[
:user_role
],
params
[
:member
],
params
[
:expected_status
],
params
[
:expected_body
]
it_behaves_like
"Debian repository
#{
desired_behavior
}
"
,
params
[
:expected_status
],
params
[
:expected_body
]
end
end
end
it_behaves_like
'rejects Debian access with unknown project id'
end
RSpec
.
shared_examples
'Debian project repository PUT endpoint'
do
|
success_status
,
success_body
,
is_authorize
=
false
|
context
'with valid project'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:project_visibility_level
,
:user_role
,
:member
,
:user_token
,
:expected_status
,
:expected_body
)
do
'PUBLIC'
|
:developer
|
true
|
true
|
success_status
|
nil
'PUBLIC'
|
:guest
|
true
|
true
|
:forbidden
|
nil
'PUBLIC'
|
:developer
|
true
|
false
|
:unauthorized
|
nil
'PUBLIC'
|
:guest
|
true
|
false
|
:unauthorized
|
nil
'PUBLIC'
|
:developer
|
false
|
true
|
:forbidden
|
nil
'PUBLIC'
|
:guest
|
false
|
true
|
:forbidden
|
nil
'PUBLIC'
|
:developer
|
false
|
false
|
:unauthorized
|
nil
'PUBLIC'
|
:guest
|
false
|
false
|
:unauthorized
|
nil
'PUBLIC'
|
:anonymous
|
false
|
true
|
:unauthorized
|
nil
'PRIVATE'
|
:developer
|
true
|
true
|
success_status
|
nil
'PRIVATE'
|
:guest
|
true
|
true
|
:forbidden
|
nil
'PRIVATE'
|
:developer
|
true
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:guest
|
true
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:developer
|
false
|
true
|
:not_found
|
nil
'PRIVATE'
|
:guest
|
false
|
true
|
:not_found
|
nil
'PRIVATE'
|
:developer
|
false
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:guest
|
false
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:anonymous
|
false
|
true
|
:unauthorized
|
nil
end
with_them
do
include_context
'Debian repository project access'
,
params
[
:project_visibility_level
],
params
[
:user_role
],
params
[
:user_token
],
:basic
do
desired_behavior
=
if
is_authorize
'Debian project repository PUT authorize request'
else
'Debian project repository PUT request'
end
it_behaves_like
desired_behavior
,
params
[
:user_role
],
params
[
:member
],
params
[
:expected_status
],
params
[
:expected_body
]
end
end
end
it_behaves_like
'rejects Debian access with unknown project id'
end
RSpec
.
shared_context
'Debian repository group access'
do
|
group_visibility_level
,
user_role
,
user_token
,
auth_method
|
include_context
'Debian repository auth headers'
,
user_role
,
user_token
,
auth_method
do
before
do
group
.
update_column
(
:visibility_level
,
Gitlab
::
VisibilityLevel
.
const_get
(
group_visibility_level
,
false
))
end
end
end
RSpec
.
shared_examples
'Debian group repository GET request'
do
|
user_role
,
add_member
,
status
,
body
|
context
"for user type
#{
user_role
}
"
do
before
do
group
.
send
(
"add_
#{
user_role
}
"
,
user
)
if
add_member
&&
user_role
!=
:anonymous
end
and_body
=
body
.
nil?
?
''
:
' and expected body'
it
"returns
#{
status
}#{
and_body
}
"
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
status
)
unless
body
.
nil?
expect
(
response
.
body
).
to
eq
(
body
)
end
end
end
end
end
end
end
RSpec
.
shared_examples
'rejects Debian access with unknown group id'
do
context
'with an unknown group'
do
let
(
:group
)
{
double
(
id:
non_existing_record_id
)
}
context
'as anonymous'
do
it_behaves_like
'Debian group repository GET request'
,
:anonymous
,
true
,
:unauthorized
,
nil
end
context
'as authenticated user'
do
subject
{
get
api
(
url
),
headers:
basic_auth_header
(
user
.
username
,
personal_access_token
.
token
)
}
it_behaves_like
'Debian group repository GET request'
,
:anonymous
,
true
,
:not_found
,
nil
it_behaves_like
'rejects Debian access with unknown container id'
end
end
end
end
RSpec
.
shared_examples
'Debian
group repository GET endpoint'
do
|
success_status
,
success_body
|
RSpec
.
shared_examples
'Debian
repository write endpoint'
do
|
desired_behavior
,
success_status
,
success_body
|
context
'with valid
group
'
do
context
'with valid
container
'
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:
group_
visibility_level
,
:user_role
,
:member
,
:user_token
,
:expected_status
,
:expected_body
)
do
where
(
:visibility_level
,
:user_role
,
:member
,
:user_token
,
:expected_status
,
:expected_body
)
do
'PUBLIC'
|
:developer
|
true
|
true
|
success_status
|
success_body
:public
|
:developer
|
true
|
true
|
success_status
|
success_body
'PUBLIC'
|
:guest
|
true
|
true
|
success_status
|
success_body
:public
|
:guest
|
true
|
true
|
:forbidden
|
nil
'PUBLIC'
|
:developer
|
true
|
false
|
success_status
|
success_body
:public
|
:developer
|
true
|
false
|
:unauthorized
|
nil
'PUBLIC'
|
:guest
|
true
|
false
|
success_status
|
success_body
:public
|
:guest
|
true
|
false
|
:unauthorized
|
nil
'PUBLIC'
|
:developer
|
false
|
true
|
success_status
|
success_body
:public
|
:developer
|
false
|
true
|
:forbidden
|
nil
'PUBLIC'
|
:guest
|
false
|
true
|
success_status
|
success_body
:public
|
:guest
|
false
|
true
|
:forbidden
|
nil
'PUBLIC'
|
:developer
|
false
|
false
|
success_status
|
success_body
:public
|
:developer
|
false
|
false
|
:unauthorized
|
nil
'PUBLIC'
|
:guest
|
false
|
false
|
success_status
|
success_body
:public
|
:guest
|
false
|
false
|
:unauthorized
|
nil
'PUBLIC'
|
:anonymous
|
false
|
true
|
success_status
|
success_body
:public
|
:anonymous
|
false
|
true
|
:unauthorized
|
nil
'PRIVATE'
|
:developer
|
true
|
true
|
success_status
|
success_body
:private
|
:developer
|
true
|
true
|
success_status
|
success_body
'PRIVATE'
|
:guest
|
true
|
true
|
:forbidden
|
nil
:private
|
:guest
|
true
|
true
|
:forbidden
|
nil
'PRIVATE'
|
:developer
|
true
|
false
|
:unauthorized
|
nil
:private
|
:developer
|
true
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:guest
|
true
|
false
|
:unauthorized
|
nil
:private
|
:guest
|
true
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:developer
|
false
|
true
|
:not_found
|
nil
:private
|
:developer
|
false
|
true
|
:not_found
|
nil
'PRIVATE'
|
:guest
|
false
|
true
|
:not_found
|
nil
:private
|
:guest
|
false
|
true
|
:not_found
|
nil
'PRIVATE'
|
:developer
|
false
|
false
|
:unauthorized
|
nil
:private
|
:developer
|
false
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:guest
|
false
|
false
|
:unauthorized
|
nil
:private
|
:guest
|
false
|
false
|
:unauthorized
|
nil
'PRIVATE'
|
:anonymous
|
false
|
true
|
:unauthorized
|
nil
:private
|
:anonymous
|
false
|
true
|
:unauthorized
|
nil
end
end
with_them
do
with_them
do
include_context
'Debian repository
group access'
,
params
[
:group_visibility_level
],
params
[
:user_role
],
params
[
:user_token
],
:basic
do
include_context
'Debian repository
access'
,
params
[
:visibility_level
],
params
[
:user_role
],
params
[
:member
],
params
[
:user_token
],
:basic
do
it_behaves_like
'Debian group repository GET request'
,
params
[
:user_role
],
params
[
:member
]
,
params
[
:expected_status
],
params
[
:expected_body
]
it_behaves_like
"Debian repository
#{
desired_behavior
}
"
,
params
[
:expected_status
],
params
[
:expected_body
]
end
end
end
end
end
end
it_behaves_like
'rejects Debian access with unknown
group
id'
it_behaves_like
'rejects Debian access with unknown
container
id'
end
end
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