Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
7a6c7bd6
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,发现更多精彩内容 >>
提交
7a6c7bd6
编写于
2月 23, 2018
作者:
D
Douwe Maan
提交者:
Nick Thomas
2月 23, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow token authentication on go-get request
上级
981b5905
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
97 addition
and
17 deletion
+97
-17
changelogs/unreleased/dm-go-get-api-token.yml
changelogs/unreleased/dm-go-get-api-token.yml
+5
-0
lib/gitlab/auth/request_authenticator.rb
lib/gitlab/auth/request_authenticator.rb
+8
-0
lib/gitlab/middleware/go.rb
lib/gitlab/middleware/go.rb
+9
-1
spec/lib/gitlab/middleware/go_spec.rb
spec/lib/gitlab/middleware/go_spec.rb
+75
-16
未找到文件。
changelogs/unreleased/dm-go-get-api-token.yml
0 → 100644
浏览文件 @
7a6c7bd6
---
title
:
Allow token authentication on go-get request
merge_request
:
author
:
type
:
changed
lib/gitlab/auth/request_authenticator.rb
浏览文件 @
7a6c7bd6
...
...
@@ -20,6 +20,14 @@ module Gitlab
rescue
Gitlab
::
Auth
::
AuthenticationError
nil
end
def
valid_access_token?
(
scopes:
[])
validate_access_token!
(
scopes:
scopes
)
true
rescue
Gitlab
::
Auth
::
AuthenticationError
false
end
end
end
end
lib/gitlab/middleware/go.rb
浏览文件 @
7a6c7bd6
...
...
@@ -114,7 +114,15 @@ module Gitlab
end
def
current_user
(
request
)
request
.
env
[
'warden'
]
&
.
authenticate
authenticator
=
Gitlab
::
Auth
::
RequestAuthenticator
.
new
(
request
)
user
=
authenticator
.
find_user_from_access_token
||
authenticator
.
find_user_from_warden
return
unless
user
&
.
can?
(
:access_api
)
# Right now, the `api` scope is the only one that should be able to determine private project existence.
return
unless
authenticator
.
valid_access_token?
(
scopes:
[
:api
])
user
end
end
end
...
...
spec/lib/gitlab/middleware/go_spec.rb
浏览文件 @
7a6c7bd6
...
...
@@ -3,19 +3,30 @@ require 'spec_helper'
describe
Gitlab
::
Middleware
::
Go
do
let
(
:app
)
{
double
(
:app
)
}
let
(
:middleware
)
{
described_class
.
new
(
app
)
}
let
(
:env
)
do
{
'rack.input'
=>
''
,
'REQUEST_METHOD'
=>
'GET'
}
end
describe
'#call'
do
describe
'when go-get=0'
do
before
do
env
[
'QUERY_STRING'
]
=
'go-get=0'
end
it
'skips go-import generation'
do
env
=
{
'rack.input'
=>
''
,
'QUERY_STRING'
=>
'go-get=0'
}
expect
(
app
).
to
receive
(
:call
).
with
(
env
).
and_return
(
'no-go'
)
middleware
.
call
(
env
)
end
end
describe
'when go-get=1'
do
let
(
:current_user
)
{
nil
}
before
do
env
[
'QUERY_STRING'
]
=
'go-get=1'
env
[
'PATH_INFO'
]
=
"/
#{
path
}
"
end
shared_examples
'go-get=1'
do
|
enabled_protocol
:|
context
'with simple 2-segment project path'
do
...
...
@@ -54,21 +65,75 @@ describe Gitlab::Middleware::Go do
project
.
update_attribute
(
:visibility_level
,
Project
::
PRIVATE
)
end
context
'with access to the project'
do
shared_examples
'unauthorized'
do
it
'returns the 2-segment group path'
do
expect_response_with_path
(
go
,
enabled_protocol
,
group
.
full_path
)
end
end
context
'when not authenticated'
do
it_behaves_like
'unauthorized'
end
context
'when authenticated'
do
let
(
:current_user
)
{
project
.
creator
}
before
do
project
.
team
.
add_master
(
current_user
)
end
it
'returns the full project path'
do
expect_response_with_path
(
go
,
enabled_protocol
,
project
.
full_path
)
shared_examples
'authenticated'
do
context
'with access to the project'
do
it
'returns the full project path'
do
expect_response_with_path
(
go
,
enabled_protocol
,
project
.
full_path
)
end
end
context
'without access to the project'
do
before
do
project
.
team
.
find_member
(
current_user
).
destroy
end
it_behaves_like
'unauthorized'
end
end
end
context
'without access to the project'
do
it
'returns the 2-segment group path'
do
expect_response_with_path
(
go
,
enabled_protocol
,
group
.
full_path
)
context
'using warden'
do
before
do
env
[
'warden'
]
=
double
(
authenticate:
current_user
)
end
context
'when active'
do
it_behaves_like
'authenticated'
end
context
'when blocked'
do
before
do
current_user
.
block!
end
it_behaves_like
'unauthorized'
end
end
context
'using a personal access token'
do
let
(
:personal_access_token
)
{
create
(
:personal_access_token
,
user:
current_user
)
}
before
do
env
[
'HTTP_PRIVATE_TOKEN'
]
=
personal_access_token
.
token
end
context
'with api scope'
do
it_behaves_like
'authenticated'
end
context
'with read_user scope'
do
before
do
personal_access_token
.
update_attribute
(
:scopes
,
[
:read_user
])
end
it_behaves_like
'unauthorized'
end
end
end
end
...
...
@@ -138,12 +203,6 @@ describe Gitlab::Middleware::Go do
end
def
go
env
=
{
'rack.input'
=>
''
,
'QUERY_STRING'
=>
'go-get=1'
,
'PATH_INFO'
=>
"/
#{
path
}
"
,
'warden'
=>
double
(
authenticate:
current_user
)
}
middleware
.
call
(
env
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录