Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
Kazuhiko Shiozaki
gitlab-shell
Commits
acf1209a
Commit
acf1209a
authored
Jul 04, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:gitlabhq/gitlab-shell
parents
456ba294
80422c66
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
265 additions
and
16 deletions
+265
-16
lib/gitlab_net.rb
lib/gitlab_net.rb
+19
-16
spec/gitlab_config_spec.rb
spec/gitlab_config_spec.rb
+65
-0
spec/gitlab_keys_spec.rb
spec/gitlab_keys_spec.rb
+20
-0
spec/gitlab_logger_spec.rb
spec/gitlab_logger_spec.rb
+11
-0
spec/gitlab_net_spec.rb
spec/gitlab_net_spec.rb
+75
-0
spec/gitlab_projects_spec.rb
spec/gitlab_projects_spec.rb
+6
-0
spec/gitlab_shell_spec.rb
spec/gitlab_shell_spec.rb
+25
-0
spec/vcr_cassettes/denied-push-with-user.yml
spec/vcr_cassettes/denied-push-with-user.yml
+44
-0
No files found.
lib/gitlab_net.rb
View file @
acf1209a
...
...
@@ -53,27 +53,30 @@ class GitlabNet
"
#{
config
.
gitlab_url
}
/api/v3/internal"
end
def
get
(
url
)
$logger
.
debug
"Performing GET
#{
url
}
"
url
=
URI
.
parse
(
url
)
http
=
Net
::
HTTP
.
new
(
url
.
host
,
url
.
port
)
def
http_client_for
(
url
)
Net
::
HTTP
.
new
(
url
.
host
,
url
.
port
).
tap
do
|
http
|
if
URI
::
HTTPS
===
url
http
.
use_ssl
=
true
http
.
cert_store
=
cert_store
if
config
.
http_settings
[
'self_signed_cert'
]
http
.
verify_mode
=
OpenSSL
::
SSL
::
VERIFY_NONE
http
.
verify_mode
=
OpenSSL
::
SSL
::
VERIFY_NONE
if
config
.
http_settings
[
'self_signed_cert'
]
end
end
end
request
=
Net
::
HTTP
::
Get
.
new
(
url
.
request_uri
)
if
config
.
http_settings
[
'user'
]
&&
config
.
http_settings
[
'password'
]
request
.
basic_auth
config
.
http_settings
[
'user'
],
config
.
http_settings
[
'password'
]
def
http_request_for
(
url
)
user
=
config
.
http_settings
[
'user'
]
password
=
config
.
http_settings
[
'password'
]
Net
::
HTTP
::
Get
.
new
(
url
.
request_uri
).
tap
{
|
r
|
r
.
basic_auth
(
user
,
password
)
if
user
&&
password
}
end
http
.
start
{
|
http
|
http
.
request
(
request
)
}.
tap
do
|
resp
|
def
get
(
url
)
$logger
.
debug
"Performing GET
#{
url
}
"
url
=
URI
.
parse
(
url
)
http
=
http_client_for
url
request
=
http_request_for
url
http
.
start
{
|
http
|
http
.
request
(
request
)
}.
tap
do
|
resp
|
if
resp
.
code
==
"200"
$logger
.
debug
{
"Received response
#{
resp
.
code
}
=> <
#{
resp
.
body
}
>."
}
else
...
...
spec/gitlab_config_spec.rb
0 → 100644
View file @
acf1209a
require_relative
'spec_helper'
require_relative
'../lib/gitlab_config'
describe
GitlabConfig
do
let
(
:config
)
{
GitlabConfig
.
new
}
describe
:redis
do
subject
{
config
.
redis
}
it
{
should
be_a
(
Hash
)
}
it
{
should
have_key
(
'bin'
)
}
it
{
should
have_key
(
'host'
)
}
it
{
should
have_key
(
'port'
)
}
it
{
should
have_key
(
'namespace'
)
}
end
describe
:redis_namespace
do
subject
{
config
.
redis_namespace
}
it
{
should
eq
(
'resque:gitlab'
)
}
end
describe
:gitlab_url
do
subject
{
config
.
gitlab_url
}
it
{
should_not
be_empty
}
it
{
should
eq
(
'http://localhost/'
)
}
end
describe
:audit_usernames
do
subject
{
config
.
audit_usernames
}
it
(
"returns false by default"
)
{
should
eq
(
false
)
}
end
describe
:redis_command
do
subject
{
config
.
redis_command
}
it
{
should
be_an
(
Array
)
}
it
{
should
include
(
config
.
redis
[
'host'
])
}
it
{
should
include
(
config
.
redis
[
'bin'
])
}
it
{
should
include
(
config
.
redis
[
'port'
].
to_s
)
}
context
"with empty redis config"
do
before
do
config
.
stub
(
:redis
)
{
{}
}
end
it
{
should
be_an
(
Array
)
}
it
{
should
include
(
'redis-cli'
)
}
end
context
"with redis socket"
do
let
(
:socket
)
{
'/tmp/redis.socket'
}
before
do
config
.
stub
(
:redis
)
{
{
'bin'
=>
''
,
'socket'
=>
socket
}
}
end
it
{
should
be_an
(
Array
)
}
it
{
should
include
(
socket
)
}
it
{
should_not
include
(
'-p'
)
}
it
{
should_not
include
(
'-h'
)
}
end
end
end
spec/gitlab_keys_spec.rb
View file @
acf1209a
...
...
@@ -82,6 +82,14 @@ describe GitlabKeys do
end
end
describe
:stdin
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
}
subject
{
gitlab_keys
.
send
:stdin
}
before
{
$stdin
=
1
}
it
{
should
equal
(
1
)
}
end
describe
:rm_key
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'rm-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
...
...
@@ -129,12 +137,24 @@ describe GitlabKeys do
gitlab_keys
.
exec
end
it
'batch-add-keys arg should execute batch_add_keys method'
do
gitlab_keys
=
build_gitlab_keys
(
'batch-add-keys'
)
gitlab_keys
.
should_receive
(
:batch_add_keys
)
gitlab_keys
.
exec
end
it
'rm-key arg should execute rm_key method'
do
gitlab_keys
=
build_gitlab_keys
(
'rm-key'
)
gitlab_keys
.
should_receive
(
:rm_key
)
gitlab_keys
.
exec
end
it
'clear arg should execute clear method'
do
gitlab_keys
=
build_gitlab_keys
(
'clear'
)
gitlab_keys
.
should_receive
(
:clear
)
gitlab_keys
.
exec
end
it
'should puts message if unknown command arg'
do
gitlab_keys
=
build_gitlab_keys
(
'change-key'
)
gitlab_keys
.
should_receive
(
:puts
).
with
(
'not allowed'
)
...
...
spec/gitlab_logger_spec.rb
0 → 100644
View file @
acf1209a
require_relative
'spec_helper'
require_relative
'../lib/gitlab_logger'
describe
:convert_log_level
do
subject
{
convert_log_level
:extreme
}
it
"converts invalid log level to Logger::INFO"
do
$stderr
.
should_receive
(
:puts
).
at_least
(
:once
)
should
eq
(
Logger
::
INFO
)
end
end
spec/gitlab_net_spec.rb
View file @
acf1209a
...
...
@@ -58,6 +58,81 @@ describe GitlabNet, vcr: true do
access
.
should
be_false
end
end
it
'should deny push access for dev.gitlab.org (with user)'
do
VCR
.
use_cassette
(
"denied-push-with-user"
)
do
access
=
gitlab_net
.
allowed?
(
'git-upload-pack'
,
'gitlab/gitlabhq.git'
,
'user-1'
,
'master'
)
access
.
should
be_false
end
end
end
end
describe
:host
do
let
(
:net
)
{
GitlabNet
.
new
}
subject
{
net
.
send
:host
}
it
{
should
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
(
"uses API version 3"
)
{
should
include
(
"api/v3"
)
}
end
describe
:http_client_for
do
subject
{
gitlab_net
.
send
:http_client_for
,
URI
(
'https://localhost/'
)
}
before
do
gitlab_net
.
stub!
:cert_store
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'self_signed_cert'
)
{
true
}
end
its
(
:verify_mode
)
{
should
eq
(
OpenSSL
::
SSL
::
VERIFY_NONE
)
}
end
describe
:http_request_for
do
let
(
:get
)
do
double
(
Net
::
HTTP
::
Get
).
tap
do
|
get
|
Net
::
HTTP
::
Get
.
stub
(
:new
)
{
get
}
end
end
let
(
:user
)
{
'user'
}
let
(
:password
)
{
'password'
}
let
(
:url
)
{
URI
'http://localhost/'
}
subject
{
gitlab_net
.
send
:http_request_for
,
url
}
before
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'user'
)
{
user
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'password'
)
{
password
}
get
.
should_receive
(
:basic_auth
).
with
(
user
,
password
).
once
end
it
{
should_not
be_nil
}
end
describe
:cert_store
do
let
(
:store
)
do
double
(
OpenSSL
::
X509
::
Store
).
tap
do
|
store
|
OpenSSL
::
X509
::
Store
.
stub
(
:new
)
{
store
}
end
end
before
:each
do
store
.
should_receive
(
:set_default_paths
).
once
end
after
do
gitlab_net
.
send
:cert_store
end
it
"calls add_file with http_settings['ca_file']"
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'ca_file'
)
{
'test_file'
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'ca_path'
)
{
nil
}
store
.
should_receive
(
:add_file
).
with
(
'test_file'
)
store
.
should_not_receive
(
:add_path
)
end
it
"calls add_path with http_settings['ca_path']"
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'ca_file'
)
{
nil
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'ca_path'
)
{
'test_path'
}
store
.
should_not_receive
(
:add_file
)
store
.
should_receive
(
:add_path
).
with
(
'test_path'
)
end
end
end
spec/gitlab_projects_spec.rb
View file @
acf1209a
...
...
@@ -176,6 +176,7 @@ describe GitlabProjects do
describe
:update_head
do
let
(
:gl_projects
)
{
build_gitlab_projects
(
'update-head'
,
repo_name
,
'stable'
)
}
let
(
:gl_projects_fail
)
{
build_gitlab_projects
'update-head'
,
repo_name
}
before
do
FileUtils
.
mkdir_p
(
tmp_repo_path
)
...
...
@@ -193,6 +194,11 @@ describe GitlabProjects do
$logger
.
should_receive
(
:info
).
with
(
"Update head in project
#{
repo_name
}
to <stable>."
)
gl_projects
.
exec
end
it
"should failed and log an error"
do
$logger
.
should_receive
(
:error
).
with
(
"update-head failed: no branch provided."
)
gl_projects_fail
.
exec
.
should
be_false
end
end
describe
:import_project
do
...
...
spec/gitlab_shell_spec.rb
View file @
acf1209a
...
...
@@ -145,6 +145,31 @@ describe GitlabShell do
end
end
describe
:exec_cmd
do
let
(
:shell
)
{
GitlabShell
.
new
}
before
{
Kernel
.
stub!
(
:exec
)
}
it
"uses Kernel::exec method"
do
Kernel
.
should_receive
(
:exec
).
with
(
kind_of
(
Hash
),
1
,
unsetenv_others:
true
).
once
shell
.
send
:exec_cmd
,
1
end
end
describe
:api
do
let
(
:shell
)
{
GitlabShell
.
new
}
subject
{
shell
.
send
:api
}
it
{
should
be_a
(
GitlabNet
)
}
end
describe
:escape_path
do
let
(
:shell
)
{
GitlabShell
.
new
}
before
{
File
.
stub
(
:absolute_path
)
{
'y'
}
}
subject
{
->
{
shell
.
send
(
:escape_path
,
'z'
)
}
}
it
{
should
raise_error
(
RuntimeError
,
"Wrong repository path"
)
}
end
def
ssh_cmd
(
cmd
)
ENV
[
'SSH_ORIGINAL_COMMAND'
]
=
cmd
end
...
...
spec/vcr_cassettes/denied-push-with-user.yml
0 → 100644
View file @
acf1209a
---
http_interactions
:
-
request
:
method
:
get
uri
:
https://dev.gitlab.org/api/v3/internal/allowed?action=git-upload-pack&forced_push=false&project=gitlab/gitlabhq&ref=master&user_id=1
body
:
encoding
:
US-ASCII
string
:
'
'
headers
:
Accept-Encoding
:
-
gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept
:
-
"
*/*"
User-Agent
:
-
Ruby
response
:
status
:
code
:
404
message
:
Not Found
headers
:
Server
:
-
nginx/1.1.19
Date
:
-
Mon, 14 Apr 2014 18:25:54 GMT
Content-Type
:
-
application/json
Content-Length
:
-
'
27'
Connection
:
-
keep-alive
Status
:
-
404 Not Found
Cache-Control
:
-
no-cache
X-Request-Id
:
-
2a2a3ef9-aaf1-4ffb-8b18-475d52ec5e09
X-Runtime
:
-
'
0.013223'
body
:
encoding
:
UTF-8
string
:
'
{"message":"404
Not
found"}'
http_version
:
recorded_at
:
Mon, 14 Apr 2014 18:25:54 GMT
recorded_with
:
VCR 2.4.0
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