Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
df45623b
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
df45623b
编写于
6月 13, 2018
作者:
F
Francisco Javier López
提交者:
Douwe Maan
6月 13, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Restoring user v3 endpoint
上级
504f3620
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
49 deletion
+65
-49
changelogs/unreleased/fj-restore-users-v3-endpoint.yml
changelogs/unreleased/fj-restore-users-v3-endpoint.yml
+5
-0
lib/api/users.rb
lib/api/users.rb
+15
-11
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+39
-34
spec/support/api/scopes/read_user_shared_examples.rb
spec/support/api/scopes/read_user_shared_examples.rb
+6
-4
未找到文件。
changelogs/unreleased/fj-restore-users-v3-endpoint.yml
0 → 100644
浏览文件 @
df45623b
---
title
:
Restore API v3 user endpoint
merge_request
:
author
:
type
:
changed
lib/api/users.rb
浏览文件 @
df45623b
...
...
@@ -531,18 +531,22 @@ module API
authenticate!
end
desc
'Get the currently authenticated user'
do
success
Entities
::
UserPublic
end
get
do
entity
=
if
current_user
.
admin?
Entities
::
UserWithAdmin
else
Entities
::
UserPublic
end
# Enabling /user endpoint for the v3 version to allow oauth
# authentication through this endpoint.
version
%w(v3 v4)
,
using: :path
do
desc
'Get the currently authenticated user'
do
success
Entities
::
UserPublic
end
get
do
entity
=
if
current_user
.
admin?
Entities
::
UserWithAdmin
else
Entities
::
UserPublic
end
present
current_user
,
with:
entity
present
current_user
,
with:
entity
end
end
desc
"Get the currently authenticated user's SSH keys"
do
...
...
spec/requests/api/users_spec.rb
浏览文件 @
df45623b
...
...
@@ -1123,58 +1123,63 @@ describe API::Users do
describe
"GET /user"
do
let
(
:personal_access_token
)
{
create
(
:personal_access_token
,
user:
user
).
token
}
context
'with regular user'
do
context
'with personal access token'
do
it
'returns 403 without private token when sudo is defined'
do
get
api
(
"/user?private_token=
#{
personal_access_token
}
&sudo=123"
)
shared_examples
'get user info'
do
|
version
|
context
'with regular user'
do
context
'with personal access token'
do
it
'returns 403 without private token when sudo is defined'
do
get
api
(
"/user?private_token=
#{
personal_access_token
}
&sudo=123"
,
version:
version
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
end
it
'returns current user without private token when sudo not defined'
do
get
api
(
"/user"
,
user
)
it
'returns current user without private token when sudo not defined'
do
get
api
(
"/user"
,
user
,
version:
version
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/user/public'
)
expect
(
json_response
[
'id'
]).
to
eq
(
user
.
id
)
end
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/user/public'
)
expect
(
json_response
[
'id'
]).
to
eq
(
user
.
id
)
end
context
"scopes"
do
let
(
:path
)
{
"/user"
}
let
(
:api_call
)
{
method
(
:api
)
}
context
"scopes"
do
let
(
:path
)
{
"/user"
}
let
(
:api_call
)
{
method
(
:api
)
}
include_examples
'allows the "read_user" scope'
include_examples
'allows the "read_user" scope'
,
version
end
end
end
context
'with admin'
do
let
(
:admin_personal_access_token
)
{
create
(
:personal_access_token
,
user:
admin
).
token
}
context
'with admin'
do
let
(
:admin_personal_access_token
)
{
create
(
:personal_access_token
,
user:
admin
).
token
}
context
'with personal access token'
do
it
'returns 403 without private token when sudo defined'
do
get
api
(
"/user?private_token=
#{
admin_personal_access_token
}
&sudo=
#{
user
.
id
}
"
)
context
'with personal access token'
do
it
'returns 403 without private token when sudo defined'
do
get
api
(
"/user?private_token=
#{
admin_personal_access_token
}
&sudo=
#{
user
.
id
}
"
,
version:
version
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
it
'returns initial current user without private token but with is_admin when sudo not defined'
do
get
api
(
"/user?private_token=
#{
admin_personal_access_token
}
"
)
it
'returns initial current user without private token but with is_admin when sudo not defined'
do
get
api
(
"/user?private_token=
#{
admin_personal_access_token
}
"
,
version:
version
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/user/admin'
)
expect
(
json_response
[
'id'
]).
to
eq
(
admin
.
id
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/user/admin'
)
expect
(
json_response
[
'id'
]).
to
eq
(
admin
.
id
)
end
end
end
end
context
'with unauthenticated user'
do
it
"returns 401 error if user is unauthenticated"
do
get
api
(
"/user"
)
context
'with unauthenticated user'
do
it
"returns 401 error if user is unauthenticated"
do
get
api
(
"/user"
,
version:
version
)
expect
(
response
).
to
have_gitlab_http_status
(
401
)
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
end
it_behaves_like
'get user info'
,
'v3'
it_behaves_like
'get user info'
,
'v4'
end
describe
"GET /user/keys"
do
...
...
spec/support/api/scopes/read_user_shared_examples.rb
浏览文件 @
df45623b
shared_examples_for
'allows the "read_user" scope'
do
shared_examples_for
'allows the "read_user" scope'
do
|
api_version
|
let
(
:version
)
{
api_version
||
'v4'
}
context
'for personal access tokens'
do
context
'when the requesting token has the "api" scope'
do
let
(
:token
)
{
create
(
:personal_access_token
,
scopes:
[
'api'
],
user:
user
)
}
it
'returns a "200" response'
do
get
api_call
.
call
(
path
,
user
,
personal_access_token:
token
)
get
api_call
.
call
(
path
,
user
,
personal_access_token:
token
,
version:
version
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
...
...
@@ -14,7 +16,7 @@ shared_examples_for 'allows the "read_user" scope' do
let
(
:token
)
{
create
(
:personal_access_token
,
scopes:
[
'read_user'
],
user:
user
)
}
it
'returns a "200" response'
do
get
api_call
.
call
(
path
,
user
,
personal_access_token:
token
)
get
api_call
.
call
(
path
,
user
,
personal_access_token:
token
,
version:
version
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
...
...
@@ -28,7 +30,7 @@ shared_examples_for 'allows the "read_user" scope' do
end
it
'returns a "403" response'
do
get
api_call
.
call
(
path
,
user
,
personal_access_token:
token
)
get
api_call
.
call
(
path
,
user
,
personal_access_token:
token
,
version:
version
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录