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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
1cc92dae
Commit
1cc92dae
authored
Oct 22, 2017
by
Guilherme Vieira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Returns a ssh url for go-get=1
parent
e1122c9f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
55 deletions
+103
-55
changelogs/unreleased/go-get-ssh.yml
changelogs/unreleased/go-get-ssh.yml
+5
-0
lib/gitlab/middleware/go.rb
lib/gitlab/middleware/go.rb
+13
-2
spec/lib/gitlab/middleware/go_spec.rb
spec/lib/gitlab/middleware/go_spec.rb
+85
-53
No files found.
changelogs/unreleased/go-get-ssh.yml
0 → 100644
View file @
1cc92dae
---
title
:
Returns a ssh url for go-get=1
merge_request
:
14990
author
:
gvieira37
type
:
fixed
lib/gitlab/middleware/go.rb
View file @
1cc92dae
...
@@ -4,6 +4,7 @@ module Gitlab
...
@@ -4,6 +4,7 @@ module Gitlab
module
Middleware
module
Middleware
class
Go
class
Go
include
ActionView
::
Helpers
::
TagHelper
include
ActionView
::
Helpers
::
TagHelper
include
Gitlab
::
CurrentSettings
PROJECT_PATH_REGEX
=
%r{
\A
(
#{
Gitlab
::
PathRegex
.
full_namespace_route_regex
}
/
#{
Gitlab
::
PathRegex
.
project_route_regex
}
)/}
.
freeze
PROJECT_PATH_REGEX
=
%r{
\A
(
#{
Gitlab
::
PathRegex
.
full_namespace_route_regex
}
/
#{
Gitlab
::
PathRegex
.
project_route_regex
}
)/}
.
freeze
...
@@ -37,10 +38,20 @@ module Gitlab
...
@@ -37,10 +38,20 @@ module Gitlab
end
end
def
go_body
(
path
)
def
go_body
(
path
)
project_url
=
URI
.
join
(
Gitlab
.
config
.
gitlab
.
url
,
path
)
config
=
Gitlab
.
config
project_url
=
URI
.
join
(
config
.
gitlab
.
url
,
path
)
import_prefix
=
strip_url
(
project_url
.
to_s
)
import_prefix
=
strip_url
(
project_url
.
to_s
)
meta_tag
=
tag
:meta
,
name:
'go-import'
,
content:
"
#{
import_prefix
}
git
#{
project_url
}
.git"
repository_url
=
case
current_application_settings
.
enabled_git_access_protocol
when
'ssh'
shell
=
config
.
gitlab_shell
port
=
":
#{
shell
.
ssh_port
}
"
unless
shell
.
ssh_port
==
22
"ssh://
#{
shell
.
ssh_user
}
@
#{
shell
.
ssh_host
}#{
port
}
/
#{
path
}
.git"
when
'http'
,
nil
"
#{
project_url
}
.git"
end
meta_tag
=
tag
:meta
,
name:
'go-import'
,
content:
"
#{
import_prefix
}
git
#{
repository_url
}
"
head_tag
=
content_tag
:head
,
meta_tag
head_tag
=
content_tag
:head
,
meta_tag
content_tag
:html
,
head_tag
content_tag
:html
,
head_tag
end
end
...
...
spec/lib/gitlab/middleware/go_spec.rb
View file @
1cc92dae
...
@@ -17,89 +17,115 @@ describe Gitlab::Middleware::Go do
...
@@ -17,89 +17,115 @@ describe Gitlab::Middleware::Go do
describe
'when go-get=1'
do
describe
'when go-get=1'
do
let
(
:current_user
)
{
nil
}
let
(
:current_user
)
{
nil
}
context
'with simple 2-segment project path'
do
shared_examples
'go-get=1'
do
|
enabled_protocol
:|
let!
(
:project
)
{
create
(
:project
,
:private
)
}
context
'with simple 2-segment project path'
do
let!
(
:project
)
{
create
(
:project
,
:private
)
}
context
'with subpackages'
do
context
'with subpackages'
do
let
(
:path
)
{
"
#{
project
.
full_path
}
/subpackage"
}
let
(
:path
)
{
"
#{
project
.
full_path
}
/subpackage"
}
it
'returns the full project path'
do
it
'returns the full project path'
do
expect_response_with_path
(
go
,
project
.
full_path
)
expect_response_with_path
(
go
,
enabled_protocol
,
project
.
full_path
)
end
end
end
context
'without subpackages'
do
let
(
:path
)
{
project
.
full_path
}
it
'returns the full project path'
do
expect_response_with_path
(
go
,
project
.
full_path
)
end
end
end
end
context
'with a nested project path'
do
context
'without subpackages'
do
let
(
:group
)
{
create
(
:group
,
:nested
)
}
let
(
:path
)
{
project
.
full_path
}
let!
(
:project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
shared_examples
'a nested project'
do
context
'when the project is public'
do
it
'returns the full project path'
do
it
'returns the full project path'
do
expect_response_with_path
(
go
,
project
.
full_path
)
expect_response_with_path
(
go
,
enabled_protocol
,
project
.
full_path
)
end
end
end
end
end
context
'when the project is private'
do
context
'with a nested project path'
do
before
do
let
(
:group
)
{
create
(
:group
,
:nested
)
}
project
.
update_attribute
(
:visibility_level
,
Project
::
PRIVATE
)
let!
(
:project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
end
context
'with access to the project'
do
shared_examples
'a nested project'
do
let
(
:current_user
)
{
project
.
creator
}
context
'when the project is public'
do
it
'returns the full project path'
do
expect_response_with_path
(
go
,
enabled_protocol
,
project
.
full_path
)
end
end
context
'when the project is private'
do
before
do
before
do
project
.
team
.
add_master
(
current_user
)
project
.
update_attribute
(
:visibility_level
,
Project
::
PRIVATE
)
end
end
it
'returns the full project path'
do
context
'with access to the project'
do
expect_response_with_path
(
go
,
project
.
full_path
)
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
)
end
end
end
end
context
'without access to the project'
do
context
'without access to the project'
do
it
'returns the 2-segment group path'
do
it
'returns the 2-segment group path'
do
expect_response_with_path
(
go
,
group
.
full_path
)
expect_response_with_path
(
go
,
enabled_protocol
,
group
.
full_path
)
end
end
end
end
end
end
end
end
context
'with subpackages'
do
context
'with subpackages'
do
let
(
:path
)
{
"
#{
project
.
full_path
}
/subpackage"
}
let
(
:path
)
{
"
#{
project
.
full_path
}
/subpackage"
}
it_behaves_like
'a nested project'
it_behaves_like
'a nested project'
end
end
context
'with a subpackage that is not a valid project path'
do
let
(
:path
)
{
"
#{
project
.
full_path
}
/---subpackage"
}
context
'with a subpackage that is not a valid project path'
do
it_behaves_like
'a nested project'
let
(
:path
)
{
"
#{
project
.
full_path
}
/---subpackage"
}
end
context
'without subpackages'
do
let
(
:path
)
{
project
.
full_path
}
it_behaves_like
'a nested project'
it_behaves_like
'a nested project'
end
end
end
context
'without subpackages'
do
context
'with a bogus path'
do
let
(
:path
)
{
project
.
full_path
}
let
(
:path
)
{
"http:;url=http://www.example.com'http-equiv='refresh'x='?go-get=1"
}
it
'skips go-import generation'
do
expect
(
app
).
to
receive
(
:call
).
and_return
(
'no-go'
)
it_behaves_like
'a nested project'
go
end
end
end
context
'with SSH disabled'
do
before
do
stub_application_setting
(
enabled_git_access_protocol:
'http'
)
end
end
include_examples
'go-get=1'
,
enabled_protocol: :http
end
end
context
'with a bogus path'
do
context
'with HTTP disabled'
do
let
(
:path
)
{
"http:;url=http://www.example.com'http-equiv='refresh'x='?go-get=1"
}
before
do
stub_application_setting
(
enabled_git_access_protocol:
'ssh'
)
end
i
t
'skips go-import generation'
do
i
nclude_examples
'go-get=1'
,
enabled_protocol: :ssh
expect
(
app
).
to
receive
(
:call
).
and_return
(
'no-go'
)
end
go
context
'with nothing disabled'
do
before
do
stub_application_setting
(
enabled_git_access_protocol:
nil
)
end
end
include_examples
'go-get=1'
,
enabled_protocol:
nil
end
end
end
end
...
@@ -113,10 +139,16 @@ describe Gitlab::Middleware::Go do
...
@@ -113,10 +139,16 @@ describe Gitlab::Middleware::Go do
middleware
.
call
(
env
)
middleware
.
call
(
env
)
end
end
def
expect_response_with_path
(
response
,
path
)
def
expect_response_with_path
(
response
,
protocol
,
path
)
repository_url
=
case
protocol
when
:ssh
"ssh://git@
#{
Gitlab
.
config
.
gitlab
.
host
}
/
#{
path
}
.git"
when
:http
,
nil
"http://
#{
Gitlab
.
config
.
gitlab
.
host
}
/
#{
path
}
.git"
end
expect
(
response
[
0
]).
to
eq
(
200
)
expect
(
response
[
0
]).
to
eq
(
200
)
expect
(
response
[
1
][
'Content-Type'
]).
to
eq
(
'text/html'
)
expect
(
response
[
1
][
'Content-Type'
]).
to
eq
(
'text/html'
)
expected_body
=
%{<html><head><meta name="go-import" content="#{Gitlab.config.gitlab.host}/#{path} git
http://#{Gitlab.config.gitlab.host}/#{path}.git
" /></head></html>}
expected_body
=
%{<html><head><meta name="go-import" content="#{Gitlab.config.gitlab.host}/#{path} git
#{repository_url}
" /></head></html>}
expect
(
response
[
2
].
body
).
to
eq
([
expected_body
])
expect
(
response
[
2
].
body
).
to
eq
([
expected_body
])
end
end
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