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
30aaf004
Commit
30aaf004
authored
Jun 18, 2019
by
Patrick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor specs to be a bit DRYer
parent
91f92fa7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
126 deletions
+56
-126
ee/spec/requests/api/internal_spec.rb
ee/spec/requests/api/internal_spec.rb
+17
-34
ee/spec/requests/api/project_aliases_spec.rb
ee/spec/requests/api/project_aliases_spec.rb
+39
-92
No files found.
ee/spec/requests/api/internal_spec.rb
View file @
30aaf004
...
...
@@ -27,22 +27,25 @@ describe API::Internal do
context
"project alias"
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:project_alias
)
{
create
(
:project_alias
,
project:
project
)
}
def
check_access_by_alias
(
alias_name
)
post
(
api
(
"/internal/allowed"
),
params:
{
action:
"git-upload-pack"
,
key_id:
key
.
id
,
project:
alias_name
,
protocol:
'ssh'
,
secret_token:
secret_token
}
)
end
context
"without premium license"
do
context
"project matches a project alias"
do
let
(
:project_alias
)
{
create
(
:project_alias
,
project:
project
)
}
before
do
post
(
api
(
"/internal/allowed"
),
params:
{
action:
"git-upload-pack"
,
key_id:
key
.
id
,
project:
project_alias
.
name
,
protocol:
'ssh'
,
secret_token:
secret_token
}
)
check_access_by_alias
(
project_alias
.
name
)
end
it
"does not allow access because project can't be found"
do
...
...
@@ -57,19 +60,8 @@ describe API::Internal do
end
context
"project matches a project alias"
do
let
(
:project_alias
)
{
create
(
:project_alias
,
project:
project
)
}
before
do
post
(
api
(
"/internal/allowed"
),
params:
{
action:
"git-upload-pack"
,
key_id:
key
.
id
,
project:
project_alias
.
name
,
protocol:
'ssh'
,
secret_token:
secret_token
}
)
check_access_by_alias
(
project_alias
.
name
)
end
it
"allows access"
do
...
...
@@ -79,16 +71,7 @@ describe API::Internal do
context
"project doesn't match a project alias"
do
before
do
post
(
api
(
"/internal/allowed"
),
params:
{
action:
"git-upload-pack"
,
key_id:
key
.
id
,
project:
"some-project"
,
protocol:
'ssh'
,
secret_token:
secret_token
}
)
check_access_by_alias
(
'some-project'
)
end
it
"does not allow access because project can't be found"
do
...
...
ee/spec/requests/api/project_aliases_spec.rb
View file @
30aaf004
...
...
@@ -3,8 +3,8 @@
require
'spec_helper'
describe
API
::
ProjectAliases
,
api:
true
do
s
et
(
:user
)
{
create
(
:user
)
}
s
et
(
:admin
)
{
create
(
:admin
)
}
l
et
(
:user
)
{
create
(
:user
)
}
l
et
(
:admin
)
{
create
(
:admin
)
}
context
'without premium license'
do
describe
'GET /project_aliases'
do
...
...
@@ -55,15 +55,9 @@ describe API::ProjectAliases, api: true do
end
context
'with premium license'
do
before
do
create
(
:license
,
plan:
License
::
PREMIUM_PLAN
)
end
describe
'GET /project_aliases'
do
shared_examples_for
'GitLab administrator only API endpoint'
do
context
'anonymous user'
do
before
do
get
api
(
'/project_aliases'
)
end
let
(
:user
)
{
nil
}
it
'returns 401'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
...
...
@@ -71,23 +65,28 @@ describe API::ProjectAliases, api: true do
end
context
'regular user'
do
before
do
get
api
(
'/project_aliases'
,
user
)
end
it
'returns 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
end
before
do
create
(
:license
,
plan:
License
::
PREMIUM_PLAN
)
end
describe
'GET /project_aliases'
do
before
do
get
api
(
'/project_aliases'
,
user
)
end
it_behaves_like
'GitLab administrator only API endpoint'
context
'admin'
do
let
(
:user
)
{
admin
}
let!
(
:project_alias_1
)
{
create
(
:project_alias
)
}
let!
(
:project_alias_2
)
{
create
(
:project_alias
)
}
before
do
get
api
(
'/project_aliases'
,
admin
)
end
it
'returns the project aliases list'
do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project_aliases'
,
dir:
'ee'
)
...
...
@@ -97,33 +96,18 @@ describe API::ProjectAliases, api: true do
describe
'GET /project_aliases/:name'
do
let
(
:project_alias
)
{
create
(
:project_alias
)
}
let
(
:alias_name
)
{
project_alias
.
name
}
context
'anonymous user'
do
before
do
get
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
)
end
it
'returns 401'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
before
do
get
api
(
"/project_aliases/
#{
alias_name
}
"
,
user
)
end
context
'regular user'
do
before
do
get
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
,
user
)
end
it
'returns 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
it_behaves_like
'GitLab administrator only API endpoint'
context
'admin'
do
context
'existing project alias'
do
before
do
get
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
,
admin
)
end
let
(
:user
)
{
admin
}
context
'existing project alias'
do
it
'returns the project alias'
do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project_alias'
,
dir:
'ee'
)
...
...
@@ -131,9 +115,7 @@ describe API::ProjectAliases, api: true do
end
context
'non-existent project alias'
do
before
do
get
api
(
"/project_aliases/some-project"
,
admin
)
end
let
(
:alias_name
)
{
'some-project'
}
it
'returns 404'
do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
...
...
@@ -144,44 +126,26 @@ describe API::ProjectAliases, api: true do
describe
'POST /project_aliases'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project_alias
)
{
create
(
:project_alias
)
}
let
(
:alias_name
)
{
project_alias
.
name
}
context
'anonymous user'
do
before
do
post
api
(
"/project_aliases"
)
end
it
'returns 401'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
before
do
post
api
(
"/project_aliases"
,
user
),
params:
{
project_id:
project
.
id
,
name:
alias_name
}
end
context
'regular user'
do
before
do
post
api
(
"/project_aliases"
,
user
)
end
it
'returns 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
it_behaves_like
'GitLab administrator only API endpoint'
context
'admin'
do
context
'existing project alias'
do
let
(
:project_alias
)
{
create
(
:project_alias
)
}
before
do
post
api
(
"/project_aliases"
,
admin
),
params:
{
project_id:
project
.
id
,
name:
project_alias
.
name
}
end
let
(
:user
)
{
admin
}
context
'existing project alias'
do
it
'returns 400'
do
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
context
'non-existent project alias'
do
before
do
post
api
(
"/project_aliases"
,
admin
),
params:
{
project_id:
project
.
id
,
name:
'some-project'
}
end
let
(
:alias_name
)
{
'some-project'
}
it
'returns 200'
do
expect
(
response
).
to
have_gitlab_http_status
(
201
)
...
...
@@ -193,42 +157,25 @@ describe API::ProjectAliases, api: true do
describe
'DELETE /project_aliases/:name'
do
let
(
:project_alias
)
{
create
(
:project_alias
)
}
let
(
:alias_name
)
{
project_alias
.
name
}
context
'anonymous user'
do
before
do
delete
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
)
end
it
'returns 401'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
before
do
delete
api
(
"/project_aliases/
#{
alias_name
}
"
,
user
)
end
context
'regular user'
do
before
do
delete
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
,
user
)
end
it
'returns 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
it_behaves_like
'GitLab administrator only API endpoint'
context
'admin'
do
context
'existing project alias'
do
before
do
delete
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
,
admin
)
end
let
(
:user
)
{
admin
}
context
'existing project alias'
do
it
'returns 204'
do
expect
(
response
).
to
have_gitlab_http_status
(
204
)
end
end
context
'non-existent project alias'
do
before
do
delete
api
(
"/project_aliases/some-project"
,
admin
)
end
let
(
:alias_name
)
{
'some-project'
}
it
'returns 404'
do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
...
...
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