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
nexedi
gitlab-shell
Commits
cfec435a
Commit
cfec435a
authored
Aug 14, 2018
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Autocorrect specs via `transpec -k its -v stub_with_hash`
parent
c5c97dd3
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
195 additions
and
195 deletions
+195
-195
spec/gitlab_access_spec.rb
spec/gitlab_access_spec.rb
+9
-9
spec/gitlab_config_spec.rb
spec/gitlab_config_spec.rb
+5
-5
spec/gitlab_keys_spec.rb
spec/gitlab_keys_spec.rb
+36
-36
spec/gitlab_lfs_authentication_spec.rb
spec/gitlab_lfs_authentication_spec.rb
+6
-6
spec/gitlab_logger_spec.rb
spec/gitlab_logger_spec.rb
+2
-2
spec/gitlab_net_spec.rb
spec/gitlab_net_spec.rb
+77
-77
spec/gitlab_post_receive_spec.rb
spec/gitlab_post_receive_spec.rb
+1
-1
spec/gitlab_shell_spec.rb
spec/gitlab_shell_spec.rb
+55
-55
spec/httpunix_spec.rb
spec/httpunix_spec.rb
+1
-1
spec/names_helper_spec.rb
spec/names_helper_spec.rb
+3
-3
No files found.
spec/gitlab_access_spec.rb
View file @
cfec435a
...
@@ -7,7 +7,7 @@ describe GitlabAccess do
...
@@ -7,7 +7,7 @@ describe GitlabAccess do
let
(
:repo_path
)
{
File
.
join
(
repository_path
,
repo_name
)
+
".git"
}
let
(
:repo_path
)
{
File
.
join
(
repository_path
,
repo_name
)
+
".git"
}
let
(
:api
)
do
let
(
:api
)
do
double
(
GitlabNet
).
tap
do
|
api
|
double
(
GitlabNet
).
tap
do
|
api
|
a
pi
.
stub
(
check_access:
GitAccessStatus
.
new
(
true
,
a
llow
(
api
).
to
receive
(
:check_access
).
and_return
(
GitAccessStatus
.
new
(
true
,
'ok'
,
'ok'
,
gl_repository:
'project-1'
,
gl_repository:
'project-1'
,
gl_id:
'user-123'
,
gl_id:
'user-123'
,
...
@@ -20,19 +20,19 @@ describe GitlabAccess do
...
@@ -20,19 +20,19 @@ describe GitlabAccess do
end
end
subject
do
subject
do
GitlabAccess
.
new
(
nil
,
repo_path
,
'key-123'
,
'wow'
,
'ssh'
).
tap
do
|
access
|
GitlabAccess
.
new
(
nil
,
repo_path
,
'key-123'
,
'wow'
,
'ssh'
).
tap
do
|
access
|
a
ccess
.
stub
(
exec_cmd:
:exec_called
)
a
llow
(
access
).
to
receive
(
:exec_cmd
).
and_return
(
:exec_called
)
a
ccess
.
stub
(
api:
api
)
a
llow
(
access
).
to
receive
(
:api
).
and_return
(
api
)
end
end
end
end
before
do
before
do
GitlabConfig
.
any_instance
.
stub
(
repos_path:
repository_path
)
allow_any_instance_of
(
GitlabConfig
).
to
receive
(
:repos_path
).
and_return
(
repository_path
)
end
end
describe
:initialize
do
describe
:initialize
do
it
{
subject
.
repo_path
.
should
==
repo_path
}
it
{
expect
(
subject
.
repo_path
).
to
eq
(
repo_path
)
}
it
{
subject
.
changes
.
should
==
[
'wow'
]
}
it
{
expect
(
subject
.
changes
).
to
eq
([
'wow'
])
}
it
{
subject
.
protocol
.
should
==
'ssh'
}
it
{
expect
(
subject
.
protocol
).
to
eq
(
'ssh'
)
}
end
end
describe
"#exec"
do
describe
"#exec"
do
...
@@ -44,7 +44,7 @@ describe GitlabAccess do
...
@@ -44,7 +44,7 @@ describe GitlabAccess do
context
"access is denied"
do
context
"access is denied"
do
before
do
before
do
a
pi
.
stub
(
check_access:
GitAccessStatus
.
new
(
a
llow
(
api
).
to
receive
(
:check_access
).
and_return
(
GitAccessStatus
.
new
(
false
,
false
,
'denied'
,
'denied'
,
gl_repository:
nil
,
gl_repository:
nil
,
...
@@ -64,7 +64,7 @@ describe GitlabAccess do
...
@@ -64,7 +64,7 @@ describe GitlabAccess do
context
"API connection fails"
do
context
"API connection fails"
do
before
do
before
do
a
pi
.
stub
(
:check_access
).
and_raise
(
GitlabNet
::
ApiUnreachableError
)
a
llow
(
api
).
to
receive
(
:check_access
).
and_raise
(
GitlabNet
::
ApiUnreachableError
)
end
end
it
"returns false"
do
it
"returns false"
do
...
...
spec/gitlab_config_spec.rb
View file @
cfec435a
...
@@ -9,27 +9,27 @@ describe GitlabConfig do
...
@@ -9,27 +9,27 @@ describe GitlabConfig do
subject
{
config
.
gitlab_url
}
subject
{
config
.
gitlab_url
}
before
{
config
.
send
(
:config
)[
'gitlab_url'
]
=
url
}
before
{
config
.
send
(
:config
)[
'gitlab_url'
]
=
url
}
it
{
should_not
be_empty
}
it
{
is_expected
.
not_to
be_empty
}
it
{
should
eq
(
url
)
}
it
{
is_expected
.
to
eq
(
url
)
}
context
'remove trailing slashes'
do
context
'remove trailing slashes'
do
before
{
config
.
send
(
:config
)[
'gitlab_url'
]
=
url
+
'//'
}
before
{
config
.
send
(
:config
)[
'gitlab_url'
]
=
url
+
'//'
}
it
{
should
eq
(
url
)
}
it
{
is_expected
.
to
eq
(
url
)
}
end
end
end
end
describe
:audit_usernames
do
describe
:audit_usernames
do
subject
{
config
.
audit_usernames
}
subject
{
config
.
audit_usernames
}
it
(
"returns false by default"
)
{
should
eq
(
false
)
}
it
(
"returns false by default"
)
{
is_expected
.
to
eq
(
false
)
}
end
end
describe
:log_format
do
describe
:log_format
do
subject
{
config
.
log_format
}
subject
{
config
.
log_format
}
it
'returns "text" by default'
do
it
'returns "text" by default'
do
should
eq
(
'text'
)
is_expected
.
to
eq
(
'text'
)
end
end
end
end
end
end
spec/gitlab_keys_spec.rb
View file @
cfec435a
...
@@ -65,9 +65,9 @@ describe GitlabKeys do
...
@@ -65,9 +65,9 @@ describe GitlabKeys do
describe
:initialize
do
describe
:initialize
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
it
{
gitlab_keys
.
key
.
should
==
'ssh-rsa AAAAB3NzaDAxx2E'
}
it
{
expect
(
gitlab_keys
.
key
).
to
eq
(
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
it
{
gitlab_keys
.
instance_variable_get
(
:@command
).
should
==
'add-key'
}
it
{
expect
(
gitlab_keys
.
instance_variable_get
(
:@command
)).
to
eq
(
'add-key'
)
}
it
{
gitlab_keys
.
instance_variable_get
(
:@key_id
).
should
==
'key-741'
}
it
{
expect
(
gitlab_keys
.
instance_variable_get
(
:@key_id
)).
to
eq
(
'key-741'
)
}
end
end
describe
:add_key
do
describe
:add_key
do
...
@@ -77,7 +77,7 @@ describe GitlabKeys do
...
@@ -77,7 +77,7 @@ describe GitlabKeys do
create_authorized_keys_fixture
create_authorized_keys_fixture
gitlab_keys
.
send
:add_key
gitlab_keys
.
send
:add_key
auth_line
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-741
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaDAxx2E"
auth_line
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-741
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaDAxx2E"
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
auth_line
}
\n
"
expect
(
File
.
read
(
tmp_authorized_keys_path
)).
to
eq
(
"existing content
\n
#{
auth_line
}
\n
"
)
end
end
context
"without file writing"
do
context
"without file writing"
do
...
@@ -85,12 +85,12 @@ describe GitlabKeys do
...
@@ -85,12 +85,12 @@ describe GitlabKeys do
before
{
create_authorized_keys_fixture
}
before
{
create_authorized_keys_fixture
}
it
"should log an add-key event"
do
it
"should log an add-key event"
do
$logger
.
should_
receive
(
:info
).
with
(
"Adding key"
,
{
:key_id
=>
"key-741"
,
:public_key
=>
"ssh-rsa AAAAB3NzaDAxx2E"
})
expect
(
$logger
).
to
receive
(
:info
).
with
(
"Adding key"
,
{
:key_id
=>
"key-741"
,
:public_key
=>
"ssh-rsa AAAAB3NzaDAxx2E"
})
gitlab_keys
.
send
:add_key
gitlab_keys
.
send
:add_key
end
end
it
"should return true"
do
it
"should return true"
do
gitlab_keys
.
send
(
:add_key
).
should
be_truthy
expect
(
gitlab_keys
.
send
(
:add_key
)).
to
be_truthy
end
end
end
end
end
end
...
@@ -104,7 +104,7 @@ describe GitlabKeys do
...
@@ -104,7 +104,7 @@ describe GitlabKeys do
create_authorized_keys_fixture
create_authorized_keys_fixture
gitlab_keys
.
send
:add_key
gitlab_keys
.
send
:add_key
auth_line1
=
'key-741 AAAAB3NzaDAxx2E'
auth_line1
=
'key-741 AAAAB3NzaDAxx2E'
gitlab_keys
.
send
(
:list_keys
).
should
==
"
#{
auth_line1
}
\n
"
expect
(
gitlab_keys
.
send
(
:list_keys
)).
to
eq
(
"
#{
auth_line1
}
\n
"
)
end
end
end
end
...
@@ -121,7 +121,7 @@ describe GitlabKeys do
...
@@ -121,7 +121,7 @@ describe GitlabKeys do
output
=
capture_stdout
do
output
=
capture_stdout
do
gitlab_keys
.
send
(
:list_key_ids
)
gitlab_keys
.
send
(
:list_key_ids
)
end
end
output
.
should
match
"1
\n
2
\n
3
\n
9000"
expect
(
output
).
to
match
"1
\n
2
\n
3
\n
9000"
end
end
end
end
...
@@ -130,38 +130,38 @@ describe GitlabKeys do
...
@@ -130,38 +130,38 @@ describe GitlabKeys do
let
(
:fake_stdin
)
{
StringIO
.
new
(
"key-12
\t
ssh-dsa ASDFASGADG
\n
key-123
\t
ssh-rsa GFDGDFSGSDFG
\n
"
,
'r'
)
}
let
(
:fake_stdin
)
{
StringIO
.
new
(
"key-12
\t
ssh-dsa ASDFASGADG
\n
key-123
\t
ssh-rsa GFDGDFSGSDFG
\n
"
,
'r'
)
}
before
do
before
do
create_authorized_keys_fixture
create_authorized_keys_fixture
gitlab_keys
.
stub
(
stdin:
fake_stdin
)
allow
(
gitlab_keys
).
to
receive
(
:stdin
).
and_return
(
fake_stdin
)
end
end
it
"adds lines at the end of the file"
do
it
"adds lines at the end of the file"
do
gitlab_keys
.
send
:batch_add_keys
gitlab_keys
.
send
:batch_add_keys
auth_line1
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-12
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-dsa ASDFASGADG"
auth_line1
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-12
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-dsa ASDFASGADG"
auth_line2
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-123
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa GFDGDFSGSDFG"
auth_line2
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-123
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa GFDGDFSGSDFG"
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
auth_line1
}
\n
#{
auth_line2
}
\n
"
expect
(
File
.
read
(
tmp_authorized_keys_path
)).
to
eq
(
"existing content
\n
#{
auth_line1
}
\n
#{
auth_line2
}
\n
"
)
end
end
context
"with invalid input"
do
context
"with invalid input"
do
let
(
:fake_stdin
)
{
StringIO
.
new
(
"key-12
\t
ssh-dsa ASDFASGADG
\n
key-123
\t
ssh-rsa GFDGDFSGSDFG
\n
foo
\t
bar
\t
baz
\n
"
,
'r'
)
}
let
(
:fake_stdin
)
{
StringIO
.
new
(
"key-12
\t
ssh-dsa ASDFASGADG
\n
key-123
\t
ssh-rsa GFDGDFSGSDFG
\n
foo
\t
bar
\t
baz
\n
"
,
'r'
)
}
it
"aborts"
do
it
"aborts"
do
gitlab_keys
.
should_
receive
(
:abort
)
expect
(
gitlab_keys
).
to
receive
(
:abort
)
gitlab_keys
.
send
:batch_add_keys
gitlab_keys
.
send
:batch_add_keys
end
end
end
end
context
"without file writing"
do
context
"without file writing"
do
before
do
before
do
gitlab_keys
.
should_
receive
(
:open
).
and_yield
(
double
(
:file
,
puts:
nil
,
chmod:
nil
))
expect
(
gitlab_keys
).
to
receive
(
:open
).
and_yield
(
double
(
:file
,
puts:
nil
,
chmod:
nil
))
end
end
it
"should log an add-key event"
do
it
"should log an add-key event"
do
$logger
.
should_
receive
(
:info
).
with
(
"Adding key"
,
key_id:
'key-12'
,
public_key:
"ssh-dsa ASDFASGADG"
)
expect
(
$logger
).
to
receive
(
:info
).
with
(
"Adding key"
,
key_id:
'key-12'
,
public_key:
"ssh-dsa ASDFASGADG"
)
$logger
.
should_
receive
(
:info
).
with
(
"Adding key"
,
key_id:
'key-123'
,
public_key:
"ssh-rsa GFDGDFSGSDFG"
)
expect
(
$logger
).
to
receive
(
:info
).
with
(
"Adding key"
,
key_id:
'key-123'
,
public_key:
"ssh-rsa GFDGDFSGSDFG"
)
gitlab_keys
.
send
:batch_add_keys
gitlab_keys
.
send
:batch_add_keys
end
end
it
"should return true"
do
it
"should return true"
do
gitlab_keys
.
send
(
:batch_add_keys
).
should
be_truthy
expect
(
gitlab_keys
.
send
(
:batch_add_keys
)).
to
be_truthy
end
end
end
end
end
end
...
@@ -171,7 +171,7 @@ describe GitlabKeys do
...
@@ -171,7 +171,7 @@ describe GitlabKeys do
subject
{
gitlab_keys
.
send
:stdin
}
subject
{
gitlab_keys
.
send
:stdin
}
before
{
$stdin
=
1
}
before
{
$stdin
=
1
}
it
{
should
equal
(
1
)
}
it
{
is_expected
.
to
equal
(
1
)
}
end
end
describe
:rm_key
do
describe
:rm_key
do
...
@@ -187,22 +187,22 @@ describe GitlabKeys do
...
@@ -187,22 +187,22 @@ describe GitlabKeys do
end
end
gitlab_keys
.
send
:rm_key
gitlab_keys
.
send
:rm_key
erased_line
=
delete_line
.
gsub
(
/./
,
'#'
)
erased_line
=
delete_line
.
gsub
(
/./
,
'#'
)
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
erased_line
}
\n
#{
other_line
}
\n
"
expect
(
File
.
read
(
tmp_authorized_keys_path
)).
to
eq
(
"existing content
\n
#{
erased_line
}
\n
#{
other_line
}
\n
"
)
end
end
context
"without file writing"
do
context
"without file writing"
do
before
do
before
do
gitlab_keys
.
stub
(
:open
)
allow
(
gitlab_keys
).
to
receive
(
:open
)
gitlab_keys
.
stub
(
:lock
).
and_yield
allow
(
gitlab_keys
).
to
receive
(
:lock
).
and_yield
end
end
it
"should log an rm-key event"
do
it
"should log an rm-key event"
do
$logger
.
should_
receive
(
:info
).
with
(
"Removing key"
,
key_id:
"key-741"
)
expect
(
$logger
).
to
receive
(
:info
).
with
(
"Removing key"
,
key_id:
"key-741"
)
gitlab_keys
.
send
:rm_key
gitlab_keys
.
send
:rm_key
end
end
it
"should return true"
do
it
"should return true"
do
gitlab_keys
.
send
(
:rm_key
).
should
be_truthy
expect
(
gitlab_keys
.
send
(
:rm_key
)).
to
be_truthy
end
end
end
end
...
@@ -219,7 +219,7 @@ describe GitlabKeys do
...
@@ -219,7 +219,7 @@ describe GitlabKeys do
end
end
gitlab_keys
.
send
:rm_key
gitlab_keys
.
send
:rm_key
erased_line
=
delete_line
.
gsub
(
/./
,
'#'
)
erased_line
=
delete_line
.
gsub
(
/./
,
'#'
)
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
erased_line
}
\n
#{
other_line
}
\n
"
expect
(
File
.
read
(
tmp_authorized_keys_path
)).
to
eq
(
"existing content
\n
#{
erased_line
}
\n
#{
other_line
}
\n
"
)
end
end
end
end
end
end
...
@@ -228,8 +228,8 @@ describe GitlabKeys do
...
@@ -228,8 +228,8 @@ describe GitlabKeys do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'clear'
)
}
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'clear'
)
}
it
"should return true"
do
it
"should return true"
do
gitlab_keys
.
stub
(
:open
)
allow
(
gitlab_keys
).
to
receive
(
:open
)
gitlab_keys
.
send
(
:clear
).
should
be_truthy
expect
(
gitlab_keys
.
send
(
:clear
)).
to
be_truthy
end
end
end
end
...
@@ -242,7 +242,7 @@ describe GitlabKeys do
...
@@ -242,7 +242,7 @@ describe GitlabKeys do
end
end
it
'returns false if opening raises an exception'
do
it
'returns false if opening raises an exception'
do
gitlab_keys
.
should_
receive
(
:open_auth_file
).
and_raise
(
"imaginary error"
)
expect
(
gitlab_keys
).
to
receive
(
:open_auth_file
).
and_raise
(
"imaginary error"
)
expect
(
gitlab_keys
.
exec
).
to
eq
(
false
)
expect
(
gitlab_keys
.
exec
).
to
eq
(
false
)
end
end
...
@@ -257,51 +257,51 @@ describe GitlabKeys do
...
@@ -257,51 +257,51 @@ describe GitlabKeys do
describe
:exec
do
describe
:exec
do
it
'add-key arg should execute add_key method'
do
it
'add-key arg should execute add_key method'
do
gitlab_keys
=
build_gitlab_keys
(
'add-key'
)
gitlab_keys
=
build_gitlab_keys
(
'add-key'
)
gitlab_keys
.
should_
receive
(
:add_key
)
expect
(
gitlab_keys
).
to
receive
(
:add_key
)
gitlab_keys
.
exec
gitlab_keys
.
exec
end
end
it
'batch-add-keys arg should execute batch_add_keys method'
do
it
'batch-add-keys arg should execute batch_add_keys method'
do
gitlab_keys
=
build_gitlab_keys
(
'batch-add-keys'
)
gitlab_keys
=
build_gitlab_keys
(
'batch-add-keys'
)
gitlab_keys
.
should_
receive
(
:batch_add_keys
)
expect
(
gitlab_keys
).
to
receive
(
:batch_add_keys
)
gitlab_keys
.
exec
gitlab_keys
.
exec
end
end
it
'rm-key arg should execute rm_key method'
do
it
'rm-key arg should execute rm_key method'
do
gitlab_keys
=
build_gitlab_keys
(
'rm-key'
)
gitlab_keys
=
build_gitlab_keys
(
'rm-key'
)
gitlab_keys
.
should_
receive
(
:rm_key
)
expect
(
gitlab_keys
).
to
receive
(
:rm_key
)
gitlab_keys
.
exec
gitlab_keys
.
exec
end
end
it
'clear arg should execute clear method'
do
it
'clear arg should execute clear method'
do
gitlab_keys
=
build_gitlab_keys
(
'clear'
)
gitlab_keys
=
build_gitlab_keys
(
'clear'
)
gitlab_keys
.
should_
receive
(
:clear
)
expect
(
gitlab_keys
).
to
receive
(
:clear
)
gitlab_keys
.
exec
gitlab_keys
.
exec
end
end
it
'check-permissions arg should execute check_permissions method'
do
it
'check-permissions arg should execute check_permissions method'
do
gitlab_keys
=
build_gitlab_keys
(
'check-permissions'
)
gitlab_keys
=
build_gitlab_keys
(
'check-permissions'
)
gitlab_keys
.
should_
receive
(
:check_permissions
)
expect
(
gitlab_keys
).
to
receive
(
:check_permissions
)
gitlab_keys
.
exec
gitlab_keys
.
exec
end
end
it
'should puts message if unknown command arg'
do
it
'should puts message if unknown command arg'
do
gitlab_keys
=
build_gitlab_keys
(
'change-key'
)
gitlab_keys
=
build_gitlab_keys
(
'change-key'
)
gitlab_keys
.
should_
receive
(
:puts
).
with
(
'not allowed'
)
expect
(
gitlab_keys
).
to
receive
(
:puts
).
with
(
'not allowed'
)
gitlab_keys
.
exec
gitlab_keys
.
exec
end
end
it
'should log a warning on unknown commands'
do
it
'should log a warning on unknown commands'
do
gitlab_keys
=
build_gitlab_keys
(
'nooope'
)
gitlab_keys
=
build_gitlab_keys
(
'nooope'
)
gitlab_keys
.
stub
(
puts:
nil
)
allow
(
gitlab_keys
).
to
receive
(
:puts
).
and_return
(
nil
)
$logger
.
should_
receive
(
:warn
).
with
(
"Attempt to execute invalid gitlab-keys command"
,
command:
'"nooope"'
)
expect
(
$logger
).
to
receive
(
:warn
).
with
(
"Attempt to execute invalid gitlab-keys command"
,
command:
'"nooope"'
)
gitlab_keys
.
exec
gitlab_keys
.
exec
end
end
end
end
describe
:lock
do
describe
:lock
do
before
do
before
do
GitlabKeys
.
any_instance
.
stub
(
lock_file:
tmp_lock_file_path
)
allow_any_instance_of
(
GitlabKeys
).
to
receive
(
:lock_file
).
and_return
(
tmp_lock_file_path
)
end
end
it
"should raise exception if operation lasts more then timeout"
do
it
"should raise exception if operation lasts more then timeout"
do
...
@@ -335,7 +335,7 @@ describe GitlabKeys do
...
@@ -335,7 +335,7 @@ describe GitlabKeys do
end
end
thr1
.
join
thr1
.
join
$global
.
should
==
"foobar"
expect
(
$global
).
to
eq
(
"foobar"
)
end
end
end
end
...
@@ -353,7 +353,7 @@ describe GitlabKeys do
...
@@ -353,7 +353,7 @@ describe GitlabKeys do
def
create_authorized_keys_fixture
(
existing_content:
'existing content'
)
def
create_authorized_keys_fixture
(
existing_content:
'existing content'
)
FileUtils
.
mkdir_p
(
File
.
dirname
(
tmp_authorized_keys_path
))
FileUtils
.
mkdir_p
(
File
.
dirname
(
tmp_authorized_keys_path
))
open
(
tmp_authorized_keys_path
,
'w'
)
{
|
file
|
file
.
puts
(
existing_content
)
}
open
(
tmp_authorized_keys_path
,
'w'
)
{
|
file
|
file
.
puts
(
existing_content
)
}
gitlab_keys
.
stub
(
auth_file:
tmp_authorized_keys_path
)
allow
(
gitlab_keys
).
to
receive
(
:auth_file
).
and_return
(
tmp_authorized_keys_path
)
end
end
def
tmp_authorized_keys_path
def
tmp_authorized_keys_path
...
...
spec/gitlab_lfs_authentication_spec.rb
View file @
cfec435a
...
@@ -16,22 +16,22 @@ describe GitlabLfsAuthentication do
...
@@ -16,22 +16,22 @@ describe GitlabLfsAuthentication do
end
end
describe
'#build_from_json'
do
describe
'#build_from_json'
do
it
{
subject
.
username
.
should
==
'dzaporozhets'
}
it
{
expect
(
subject
.
username
).
to
eq
(
'dzaporozhets'
)
}
it
{
subject
.
lfs_token
.
should
==
'wsnys8Zm8Jn7zyhHTAAK'
}
it
{
expect
(
subject
.
lfs_token
).
to
eq
(
'wsnys8Zm8Jn7zyhHTAAK'
)
}
it
{
subject
.
repository_http_path
.
should
==
'http://gitlab.dev/repo'
}
it
{
expect
(
subject
.
repository_http_path
).
to
eq
(
'http://gitlab.dev/repo'
)
}
end
end
describe
'#authentication_payload'
do
describe
'#authentication_payload'
do
result
=
"{
\"
header
\"
:{
\"
Authorization
\"
:
\"
Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL
\"
},
\"
href
\"
:
\"
http://gitlab.dev/repo/info/lfs/
\"
}"
result
=
"{
\"
header
\"
:{
\"
Authorization
\"
:
\"
Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL
\"
},
\"
href
\"
:
\"
http://gitlab.dev/repo/info/lfs/
\"
}"
it
{
subject
.
authentication_payload
.
should
eq
(
result
)
}
it
{
expect
(
subject
.
authentication_payload
).
to
eq
(
result
)
}
it
'should be a proper JSON'
do
it
'should be a proper JSON'
do
payload
=
subject
.
authentication_payload
payload
=
subject
.
authentication_payload
json_payload
=
JSON
.
parse
(
payload
)
json_payload
=
JSON
.
parse
(
payload
)
json_payload
[
'header'
][
'Authorization'
].
should
eq
(
'Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL'
)
expect
(
json_payload
[
'header'
][
'Authorization'
]).
to
eq
(
'Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL'
)
json_payload
[
'href'
].
should
eq
(
'http://gitlab.dev/repo/info/lfs/'
)
expect
(
json_payload
[
'href'
]).
to
eq
(
'http://gitlab.dev/repo/info/lfs/'
)
end
end
end
end
end
end
spec/gitlab_logger_spec.rb
View file @
cfec435a
...
@@ -6,8 +6,8 @@ describe :convert_log_level do
...
@@ -6,8 +6,8 @@ describe :convert_log_level do
subject
{
convert_log_level
:extreme
}
subject
{
convert_log_level
:extreme
}
it
"converts invalid log level to Logger::INFO"
do
it
"converts invalid log level to Logger::INFO"
do
$stderr
.
should_
receive
(
:puts
).
at_least
(
:once
)
expect
(
$stderr
).
to
receive
(
:puts
).
at_least
(
:once
)
should
eq
(
Logger
::
INFO
)
is_expected
.
to
eq
(
Logger
::
INFO
)
end
end
end
end
...
...
spec/gitlab_net_spec.rb
View file @
cfec435a
...
@@ -14,27 +14,27 @@ describe GitlabNet, vcr: true do
...
@@ -14,27 +14,27 @@ describe GitlabNet, vcr: true do
before
do
before
do
$logger
=
double
(
'logger'
).
as_null_object
$logger
=
double
(
'logger'
).
as_null_object
gitlab_net
.
stub
(
:base_api_endpoint
).
and_return
(
base_api_endpoint
)
allow
(
gitlab_net
).
to
receive
(
:base_api_endpoint
).
and_return
(
base_api_endpoint
)
gitlab_net
.
stub
(
:secret_token
).
and_return
(
secret
)
allow
(
gitlab_net
).
to
receive
(
:secret_token
).
and_return
(
secret
)
end
end
describe
'#check'
do
describe
'#check'
do
it
'should return 200 code for gitlab check'
do
it
'should return 200 code for gitlab check'
do
VCR
.
use_cassette
(
"check-ok"
)
do
VCR
.
use_cassette
(
"check-ok"
)
do
result
=
gitlab_net
.
check
result
=
gitlab_net
.
check
result
.
code
.
should
==
'200'
expect
(
result
.
code
).
to
eq
(
'200'
)
end
end
end
end
it
'adds the secret_token to request'
do
it
'adds the secret_token to request'
do
VCR
.
use_cassette
(
"check-ok"
)
do
VCR
.
use_cassette
(
"check-ok"
)
do
Net
::
HTTP
::
Get
.
any_instance
.
should_
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
))
expect_any_instance_of
(
Net
::
HTTP
::
Get
).
to
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
))
gitlab_net
.
check
gitlab_net
.
check
end
end
end
end
it
"raises an exception if the connection fails"
do
it
"raises an exception if the connection fails"
do
Net
::
HTTP
.
any_instance
.
stub
(
:request
).
and_raise
(
StandardError
)
allow_any_instance_of
(
Net
::
HTTP
).
to
receive
(
:request
).
and_raise
(
StandardError
)
expect
{
gitlab_net
.
check
}.
to
raise_error
(
GitlabNet
::
ApiUnreachableError
)
expect
{
gitlab_net
.
check
}.
to
raise_error
(
GitlabNet
::
ApiUnreachableError
)
end
end
end
end
...
@@ -43,21 +43,21 @@ describe GitlabNet, vcr: true do
...
@@ -43,21 +43,21 @@ describe GitlabNet, vcr: true do
it
'should return user has based on key id'
do
it
'should return user has based on key id'
do
VCR
.
use_cassette
(
"discover-ok"
)
do
VCR
.
use_cassette
(
"discover-ok"
)
do
user
=
gitlab_net
.
discover
(
key
)
user
=
gitlab_net
.
discover
(
key
)
user
[
'name'
].
should
==
'Administrator'
expect
(
user
[
'name'
]).
to
eq
(
'Administrator'
)
user
[
'username'
].
should
==
'root'
expect
(
user
[
'username'
]).
to
eq
(
'root'
)
end
end
end
end
it
'adds the secret_token to request'
do
it
'adds the secret_token to request'
do
VCR
.
use_cassette
(
"discover-ok"
)
do
VCR
.
use_cassette
(
"discover-ok"
)
do
Net
::
HTTP
::
Get
.
any_instance
.
should_
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
))
expect_any_instance_of
(
Net
::
HTTP
::
Get
).
to
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
))
gitlab_net
.
discover
(
key
)
gitlab_net
.
discover
(
key
)
end
end
end
end
it
"raises an exception if the connection fails"
do
it
"raises an exception if the connection fails"
do
VCR
.
use_cassette
(
"discover-ok"
)
do
VCR
.
use_cassette
(
"discover-ok"
)
do
Net
::
HTTP
.
any_instance
.
stub
(
:request
).
and_raise
(
StandardError
)
allow_any_instance_of
(
Net
::
HTTP
).
to
receive
(
:request
).
and_raise
(
StandardError
)
expect
{
gitlab_net
.
discover
(
key
)
}.
to
raise_error
(
GitlabNet
::
ApiUnreachableError
)
expect
{
gitlab_net
.
discover
(
key
)
}.
to
raise_error
(
GitlabNet
::
ApiUnreachableError
)
end
end
end
end
...
@@ -68,9 +68,9 @@ describe GitlabNet, vcr: true do
...
@@ -68,9 +68,9 @@ describe GitlabNet, vcr: true do
it
'should return the correct data'
do
it
'should return the correct data'
do
VCR
.
use_cassette
(
'lfs-authenticate-ok'
)
do
VCR
.
use_cassette
(
'lfs-authenticate-ok'
)
do
lfs_access
=
gitlab_net
.
lfs_authenticate
(
key
,
project
)
lfs_access
=
gitlab_net
.
lfs_authenticate
(
key
,
project
)
lfs_access
.
username
.
should
==
'root'
expect
(
lfs_access
.
username
).
to
eq
(
'root'
)
lfs_access
.
lfs_token
.
should
==
'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
expect
(
lfs_access
.
lfs_token
).
to
eq
(
'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
)
lfs_access
.
repository_http_path
.
should
==
URI
.
join
(
internal_api_endpoint
.
sub
(
'api/v4'
,
''
),
project
).
to_s
expect
(
lfs_access
.
repository_http_path
).
to
eq
(
URI
.
join
(
internal_api_endpoint
.
sub
(
'api/v4'
,
''
),
project
).
to_s
)
end
end
end
end
end
end
...
@@ -81,7 +81,7 @@ describe GitlabNet, vcr: true do
...
@@ -81,7 +81,7 @@ describe GitlabNet, vcr: true do
it
'should return message'
do
it
'should return message'
do
VCR
.
use_cassette
(
"broadcast_message-ok"
)
do
VCR
.
use_cassette
(
"broadcast_message-ok"
)
do
result
=
gitlab_net
.
broadcast_message
result
=
gitlab_net
.
broadcast_message
result
[
"message"
].
should
==
"Message"
expect
(
result
[
"message"
]).
to
eq
(
"Message"
)
end
end
end
end
end
end
...
@@ -90,7 +90,7 @@ describe GitlabNet, vcr: true do
...
@@ -90,7 +90,7 @@ describe GitlabNet, vcr: true do
it
'should return nil'
do
it
'should return nil'
do
VCR
.
use_cassette
(
"broadcast_message-none"
)
do
VCR
.
use_cassette
(
"broadcast_message-none"
)
do
result
=
gitlab_net
.
broadcast_message
result
=
gitlab_net
.
broadcast_message
result
.
should
==
{}
expect
(
result
).
to
eq
({})
end
end
end
end
end
end
...
@@ -102,13 +102,13 @@ describe GitlabNet, vcr: true do
...
@@ -102,13 +102,13 @@ describe GitlabNet, vcr: true do
let
(
:encoded_changes
)
{
"123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag"
}
let
(
:encoded_changes
)
{
"123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag"
}
it
"sends the given arguments as encoded URL parameters"
do
it
"sends the given arguments as encoded URL parameters"
do
gitlab_net
.
should_
receive
(
:get
).
with
(
"
#{
internal_api_endpoint
}
/merge_request_urls?project=
#{
project
}
&changes=
#{
encoded_changes
}
&gl_repository=
#{
gl_repository
}
"
)
expect
(
gitlab_net
).
to
receive
(
:get
).
with
(
"
#{
internal_api_endpoint
}
/merge_request_urls?project=
#{
project
}
&changes=
#{
encoded_changes
}
&gl_repository=
#{
gl_repository
}
"
)
gitlab_net
.
merge_request_urls
(
gl_repository
,
project
,
changes
)
gitlab_net
.
merge_request_urls
(
gl_repository
,
project
,
changes
)
end
end
it
"omits the gl_repository parameter if it's nil"
do
it
"omits the gl_repository parameter if it's nil"
do
gitlab_net
.
should_
receive
(
:get
).
with
(
"
#{
internal_api_endpoint
}
/merge_request_urls?project=
#{
project
}
&changes=
#{
encoded_changes
}
"
)
expect
(
gitlab_net
).
to
receive
(
:get
).
with
(
"
#{
internal_api_endpoint
}
/merge_request_urls?project=
#{
project
}
&changes=
#{
encoded_changes
}
"
)
gitlab_net
.
merge_request_urls
(
nil
,
project
,
changes
)
gitlab_net
.
merge_request_urls
(
nil
,
project
,
changes
)
end
end
...
@@ -135,7 +135,7 @@ describe GitlabNet, vcr: true do
...
@@ -135,7 +135,7 @@ describe GitlabNet, vcr: true do
subject
{
gitlab_net
.
pre_receive
(
gl_repository
)
}
subject
{
gitlab_net
.
pre_receive
(
gl_repository
)
}
it
'sends the correct parameters and returns the request body parsed'
do
it
'sends the correct parameters and returns the request body parsed'
do
Net
::
HTTP
::
Post
.
any_instance
.
should_
receive
(
:set_form_data
)
expect_any_instance_of
(
Net
::
HTTP
::
Post
).
to
receive
(
:set_form_data
)
.
with
(
hash_including
(
params
))
.
with
(
hash_including
(
params
))
VCR
.
use_cassette
(
"pre-receive"
)
{
subject
}
VCR
.
use_cassette
(
"pre-receive"
)
{
subject
}
...
@@ -171,7 +171,7 @@ describe GitlabNet, vcr: true do
...
@@ -171,7 +171,7 @@ describe GitlabNet, vcr: true do
subject
{
gitlab_net
.
post_receive
(
gl_repository
,
key
,
changes
)
}
subject
{
gitlab_net
.
post_receive
(
gl_repository
,
key
,
changes
)
}
it
'sends the correct parameters'
do
it
'sends the correct parameters'
do
Net
::
HTTP
::
Post
.
any_instance
.
should_
receive
(
:set_form_data
).
with
(
hash_including
(
params
))
expect_any_instance_of
(
Net
::
HTTP
::
Post
).
to
receive
(
:set_form_data
).
with
(
hash_including
(
params
))
VCR
.
use_cassette
(
"post-receive"
)
do
VCR
.
use_cassette
(
"post-receive"
)
do
...
@@ -200,21 +200,21 @@ describe GitlabNet, vcr: true do
...
@@ -200,21 +200,21 @@ describe GitlabNet, vcr: true do
it
"should return nil when the resource is not implemented"
do
it
"should return nil when the resource is not implemented"
do
VCR
.
use_cassette
(
"ssh-key-not-implemented"
)
do
VCR
.
use_cassette
(
"ssh-key-not-implemented"
)
do
result
=
gitlab_net
.
authorized_key
(
"whatever"
)
result
=
gitlab_net
.
authorized_key
(
"whatever"
)
result
.
should
be_nil
expect
(
result
).
to
be_nil
end
end
end
end
it
"should return nil when the fingerprint is not found"
do
it
"should return nil when the fingerprint is not found"
do
VCR
.
use_cassette
(
"ssh-key-not-found"
)
do
VCR
.
use_cassette
(
"ssh-key-not-found"
)
do
result
=
gitlab_net
.
authorized_key
(
"whatever"
)
result
=
gitlab_net
.
authorized_key
(
"whatever"
)
result
.
should
be_nil
expect
(
result
).
to
be_nil
end
end
end
end
it
"should return a ssh key with a valid fingerprint"
do
it
"should return a ssh key with a valid fingerprint"
do
VCR
.
use_cassette
(
"ssh-key-ok"
)
do
VCR
.
use_cassette
(
"ssh-key-ok"
)
do
result
=
gitlab_net
.
authorized_key
(
ssh_key
)
result
=
gitlab_net
.
authorized_key
(
ssh_key
)
result
.
should
eq
({
expect
(
result
).
to
eq
({
"can_push"
=>
false
,
"can_push"
=>
false
,
"created_at"
=>
"2017-06-21T09:50:07.150Z"
,
"created_at"
=>
"2017-06-21T09:50:07.150Z"
,
"id"
=>
99
,
"id"
=>
99
,
...
@@ -252,7 +252,7 @@ describe GitlabNet, vcr: true do
...
@@ -252,7 +252,7 @@ describe GitlabNet, vcr: true do
it
'sets the arguments as form parameters'
do
it
'sets the arguments as form parameters'
do
VCR
.
use_cassette
(
'notify-post-receive'
)
do
VCR
.
use_cassette
(
'notify-post-receive'
)
do
Net
::
HTTP
::
Post
.
any_instance
.
should_
receive
(
:set_form_data
).
with
(
hash_including
(
params
))
expect_any_instance_of
(
Net
::
HTTP
::
Post
).
to
receive
(
:set_form_data
).
with
(
hash_including
(
params
))
gitlab_net
.
notify_post_receive
(
gl_repository
,
repo_path
)
gitlab_net
.
notify_post_receive
(
gl_repository
,
repo_path
)
end
end
end
end
...
@@ -269,13 +269,13 @@ describe GitlabNet, vcr: true do
...
@@ -269,13 +269,13 @@ describe GitlabNet, vcr: true do
it
'should allow pull access for host'
do
it
'should allow pull access for host'
do
VCR
.
use_cassette
(
"allowed-pull"
)
do
VCR
.
use_cassette
(
"allowed-pull"
)
do
access
=
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
access
=
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
access
.
allowed?
.
should
be_truthy
expect
(
access
.
allowed?
).
to
be_truthy
end
end
end
end
it
'adds the secret_token to the request'
do
it
'adds the secret_token to the request'
do
VCR
.
use_cassette
(
"allowed-pull"
)
do
VCR
.
use_cassette
(
"allowed-pull"
)
do
Net
::
HTTP
::
Post
.
any_instance
.
should_
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
))
expect_any_instance_of
(
Net
::
HTTP
::
Post
).
to
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
))
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
end
end
end
end
...
@@ -283,7 +283,7 @@ describe GitlabNet, vcr: true do
...
@@ -283,7 +283,7 @@ describe GitlabNet, vcr: true do
it
'should allow push access for host'
do
it
'should allow push access for host'
do
VCR
.
use_cassette
(
"allowed-push"
)
do
VCR
.
use_cassette
(
"allowed-push"
)
do
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
access
.
allowed?
.
should
be_truthy
expect
(
access
.
allowed?
).
to
be_truthy
end
end
end
end
end
end
...
@@ -292,16 +292,16 @@ describe GitlabNet, vcr: true do
...
@@ -292,16 +292,16 @@ describe GitlabNet, vcr: true do
it
'should deny pull access for host'
do
it
'should deny pull access for host'
do
VCR
.
use_cassette
(
'ssh-pull-disabled'
)
do
VCR
.
use_cassette
(
'ssh-pull-disabled'
)
do
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
access
.
allowed?
.
should
be_falsey
expect
(
access
.
allowed?
).
to
be_falsey
access
.
message
.
should
eq
'Git access over SSH is not allowed'
expect
(
access
.
message
).
to
eq
'Git access over SSH is not allowed'
end
end
end
end
it
'should deny push access for host'
do
it
'should deny push access for host'
do
VCR
.
use_cassette
(
'ssh-push-disabled'
)
do
VCR
.
use_cassette
(
'ssh-push-disabled'
)
do
access
=
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
access
=
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key
,
changes
,
'ssh'
)
access
.
allowed?
.
should
be_falsey
expect
(
access
.
allowed?
).
to
be_falsey
access
.
message
.
should
eq
'Git access over SSH is not allowed'
expect
(
access
.
message
).
to
eq
'Git access over SSH is not allowed'
end
end
end
end
end
end
...
@@ -310,16 +310,16 @@ describe GitlabNet, vcr: true do
...
@@ -310,16 +310,16 @@ describe GitlabNet, vcr: true do
it
'should deny pull access for host'
do
it
'should deny pull access for host'
do
VCR
.
use_cassette
(
'http-pull-disabled'
)
do
VCR
.
use_cassette
(
'http-pull-disabled'
)
do
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
key
,
changes
,
'http'
)
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
key
,
changes
,
'http'
)
access
.
allowed?
.
should
be_falsey
expect
(
access
.
allowed?
).
to
be_falsey
access
.
message
.
should
eq
'Pulling over HTTP is not allowed.'
expect
(
access
.
message
).
to
eq
'Pulling over HTTP is not allowed.'
end
end
end
end
it
'should deny push access for host'
do
it
'should deny push access for host'
do
VCR
.
use_cassette
(
"http-push-disabled"
)
do
VCR
.
use_cassette
(
"http-push-disabled"
)
do
access
=
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key
,
changes
,
'http'
)
access
=
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key
,
changes
,
'http'
)
access
.
allowed?
.
should
be_falsey
expect
(
access
.
allowed?
).
to
be_falsey
access
.
message
.
should
eq
'Pushing over HTTP is not allowed.'
expect
(
access
.
message
).
to
eq
'Pushing over HTTP is not allowed.'
end
end
end
end
end
end
...
@@ -328,27 +328,27 @@ describe GitlabNet, vcr: true do
...
@@ -328,27 +328,27 @@ describe GitlabNet, vcr: true do
it
'should deny pull access for host'
do
it
'should deny pull access for host'
do
VCR
.
use_cassette
(
"ssh-pull-project-denied"
)
do
VCR
.
use_cassette
(
"ssh-pull-project-denied"
)
do
access
=
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key2
,
changes
,
'ssh'
)
access
=
gitlab_net
.
check_access
(
'git-receive-pack'
,
nil
,
project
,
key2
,
changes
,
'ssh'
)
access
.
allowed?
.
should
be_falsey
expect
(
access
.
allowed?
).
to
be_falsey
end
end
end
end
it
'should deny push access for host'
do
it
'should deny push access for host'
do
VCR
.
use_cassette
(
"ssh-push-project-denied"
)
do
VCR
.
use_cassette
(
"ssh-push-project-denied"
)
do
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
key2
,
changes
,
'ssh'
)
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
key2
,
changes
,
'ssh'
)
access
.
allowed?
.
should
be_falsey
expect
(
access
.
allowed?
).
to
be_falsey
end
end
end
end
it
'should deny push access for host (with user)'
do
it
'should deny push access for host (with user)'
do
VCR
.
use_cassette
(
"ssh-push-project-denied-with-user"
)
do
VCR
.
use_cassette
(
"ssh-push-project-denied-with-user"
)
do
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
'user-2'
,
changes
,
'ssh'
)
access
=
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
'user-2'
,
changes
,
'ssh'
)
access
.
allowed?
.
should
be_falsey
expect
(
access
.
allowed?
).
to
be_falsey
end
end
end
end
end
end
it
"raises an exception if the connection fails"
do
it
"raises an exception if the connection fails"
do
Net
::
HTTP
.
any_instance
.
stub
(
:request
).
and_raise
(
StandardError
)
allow_any_instance_of
(
Net
::
HTTP
).
to
receive
(
:request
).
and_raise
(
StandardError
)
expect
{
expect
{
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
'user-1'
,
changes
,
'ssh'
)
gitlab_net
.
check_access
(
'git-upload-pack'
,
nil
,
project
,
'user-1'
,
changes
,
'ssh'
)
}.
to
raise_error
(
GitlabNet
::
ApiUnreachableError
)
}.
to
raise_error
(
GitlabNet
::
ApiUnreachableError
)
...
@@ -361,7 +361,7 @@ describe GitlabNet, vcr: true do
...
@@ -361,7 +361,7 @@ describe GitlabNet, vcr: true do
subject
{
net
.
send
:base_api_endpoint
}
subject
{
net
.
send
:base_api_endpoint
}
it
{
is_expected
.
to
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
{
is_expected
.
to
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
(
"uses API version 4"
)
{
should
end_with
(
"api/v4"
)
}
it
(
"uses API version 4"
)
{
is_expected
.
to
end_with
(
"api/v4"
)
}
end
end
describe
'#internal_api_endpoint'
do
describe
'#internal_api_endpoint'
do
...
@@ -370,15 +370,15 @@ describe GitlabNet, vcr: true do
...
@@ -370,15 +370,15 @@ describe GitlabNet, vcr: true do
subject
{
net
.
send
:internal_api_endpoint
}
subject
{
net
.
send
:internal_api_endpoint
}
it
{
is_expected
.
to
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
{
is_expected
.
to
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
(
"uses API version 4"
)
{
should
end_with
(
"api/v4/internal"
)
}
it
(
"uses API version 4"
)
{
is_expected
.
to
end_with
(
"api/v4/internal"
)
}
end
end
describe
'#http_client_for'
do
describe
'#http_client_for'
do
subject
{
gitlab_net
.
send
:http_client_for
,
URI
(
'https://localhost/'
)
}
subject
{
gitlab_net
.
send
:http_client_for
,
URI
(
'https://localhost/'
)
}
before
do
before
do
gitlab_net
.
stub
:cert_store
allow
(
gitlab_net
).
to
receive
:cert_store
gitlab_net
.
send
(
:config
).
stub
(
:http_settings
)
{
{
'self_signed_cert'
=>
true
}
}
allow
(
gitlab_net
.
send
(
:config
)).
to
receive
(
:http_settings
)
{
{
'self_signed_cert'
=>
true
}
}
end
end
its
(
:verify_mode
)
{
should
eq
(
OpenSSL
::
SSL
::
VERIFY_NONE
)
}
its
(
:verify_mode
)
{
should
eq
(
OpenSSL
::
SSL
::
VERIFY_NONE
)
}
...
@@ -398,42 +398,42 @@ describe GitlabNet, vcr: true do
...
@@ -398,42 +398,42 @@ describe GitlabNet, vcr: true do
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
}
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
}
before
do
before
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'user'
)
{
user
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'user'
)
{
user
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'password'
)
{
password
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'password'
)
{
password
}
Net
::
HTTP
::
Get
.
should_
receive
(
:new
).
with
(
'/'
,
{}).
and_return
(
get
)
expect
(
Net
::
HTTP
::
Get
).
to
receive
(
:new
).
with
(
'/'
,
{}).
and_return
(
get
)
get
.
should_
receive
(
:basic_auth
).
with
(
user
,
password
).
once
expect
(
get
).
to
receive
(
:basic_auth
).
with
(
user
,
password
).
once
get
.
should_
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
)).
once
expect
(
get
).
to
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
)).
once
end
end
it
{
should_not
be_nil
}
it
{
is_expected
.
not_to
be_nil
}
end
end
context
'with params'
do
context
'with params'
do
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
,
params:
params
,
headers:
headers
}
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
,
params:
params
,
headers:
headers
}
before
do
before
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'user'
)
{
user
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'user'
)
{
user
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'password'
)
{
password
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'password'
)
{
password
}
Net
::
HTTP
::
Get
.
should_
receive
(
:new
).
with
(
'/'
,
headers
).
and_return
(
get
)
expect
(
Net
::
HTTP
::
Get
).
to
receive
(
:new
).
with
(
'/'
,
headers
).
and_return
(
get
)
get
.
should_
receive
(
:basic_auth
).
with
(
user
,
password
).
once
expect
(
get
).
to
receive
(
:basic_auth
).
with
(
user
,
password
).
once
get
.
should_
receive
(
:set_form_data
).
with
({
'key1'
=>
'value1'
,
secret_token:
secret
}).
once
expect
(
get
).
to
receive
(
:set_form_data
).
with
({
'key1'
=>
'value1'
,
secret_token:
secret
}).
once
end
end
it
{
should_not
be_nil
}
it
{
is_expected
.
not_to
be_nil
}
end
end
context
'with headers'
do
context
'with headers'
do
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
,
headers:
headers
}
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
,
headers:
headers
}
before
do
before
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'user'
)
{
user
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'user'
)
{
user
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'password'
)
{
password
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'password'
)
{
password
}
Net
::
HTTP
::
Get
.
should_
receive
(
:new
).
with
(
'/'
,
headers
).
and_return
(
get
)
expect
(
Net
::
HTTP
::
Get
).
to
receive
(
:new
).
with
(
'/'
,
headers
).
and_return
(
get
)
get
.
should_
receive
(
:basic_auth
).
with
(
user
,
password
).
once
expect
(
get
).
to
receive
(
:basic_auth
).
with
(
user
,
password
).
once
get
.
should_
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
)).
once
expect
(
get
).
to
receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
secret
)).
once
end
end
it
{
should_not
be_nil
}
it
{
is_expected
.
not_to
be_nil
}
end
end
context
'with options'
do
context
'with options'
do
...
@@ -441,15 +441,15 @@ describe GitlabNet, vcr: true do
...
@@ -441,15 +441,15 @@ describe GitlabNet, vcr: true do
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
,
options:
options
}
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
,
options:
options
}
before
do
before
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'user'
)
{
user
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'user'
)
{
user
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'password'
)
{
password
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'password'
)
{
password
}
Net
::
HTTP
::
Get
.
should_
receive
(
:new
).
with
(
'/'
,
{}).
and_return
(
get
)
expect
(
Net
::
HTTP
::
Get
).
to
receive
(
:new
).
with
(
'/'
,
{}).
and_return
(
get
)
get
.
should_
receive
(
:basic_auth
).
with
(
user
,
password
).
once
expect
(
get
).
to
receive
(
:basic_auth
).
with
(
user
,
password
).
once
get
.
should_
receive
(
:body
=
).
with
({
'key2'
=>
'value2'
,
secret_token:
secret
}.
to_json
).
once
expect
(
get
).
to
receive
(
:body
=
).
with
({
'key2'
=>
'value2'
,
secret_token:
secret
}.
to_json
).
once
get
.
should_not_
receive
(
:set_form_data
)
expect
(
get
).
not_to
receive
(
:set_form_data
)
end
end
it
{
should_not
be_nil
}
it
{
is_expected
.
not_to
be_nil
}
end
end
end
end
end
end
...
@@ -457,7 +457,7 @@ describe GitlabNet, vcr: true do
...
@@ -457,7 +457,7 @@ describe GitlabNet, vcr: true do
context
'Unix socket'
do
context
'Unix socket'
do
it
'sets the Host header to "localhost"'
do
it
'sets the Host header to "localhost"'
do
gitlab_net
=
described_class
.
new
gitlab_net
=
described_class
.
new
gitlab_net
.
should_
receive
(
:secret_token
).
and_return
(
secret
)
expect
(
gitlab_net
).
to
receive
(
:secret_token
).
and_return
(
secret
)
request
=
gitlab_net
.
send
(
:http_request_for
,
:get
,
URI
(
'http+unix://%2Ffoo'
))
request
=
gitlab_net
.
send
(
:http_request_for
,
:get
,
URI
(
'http+unix://%2Ffoo'
))
...
@@ -469,12 +469,12 @@ describe GitlabNet, vcr: true do
...
@@ -469,12 +469,12 @@ describe GitlabNet, vcr: true do
describe
'#cert_store'
do
describe
'#cert_store'
do
let
(
:store
)
do
let
(
:store
)
do
double
(
OpenSSL
::
X509
::
Store
).
tap
do
|
store
|
double
(
OpenSSL
::
X509
::
Store
).
tap
do
|
store
|
OpenSSL
::
X509
::
Store
.
stub
(
:new
)
{
store
}
allow
(
OpenSSL
::
X509
::
Store
).
to
receive
(
:new
)
{
store
}
end
end
end
end
before
:each
do
before
:each
do
store
.
should_
receive
(
:set_default_paths
).
once
expect
(
store
).
to
receive
(
:set_default_paths
).
once
end
end
after
do
after
do
...
@@ -482,17 +482,17 @@ describe GitlabNet, vcr: true do
...
@@ -482,17 +482,17 @@ describe GitlabNet, vcr: true do
end
end
it
"calls add_file with http_settings['ca_file']"
do
it
"calls add_file with http_settings['ca_file']"
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'ca_file'
)
{
'test_file'
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'ca_file'
)
{
'test_file'
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'ca_path'
)
{
nil
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'ca_path'
)
{
nil
}
store
.
should_
receive
(
:add_file
).
with
(
'test_file'
)
expect
(
store
).
to
receive
(
:add_file
).
with
(
'test_file'
)
store
.
should_not_
receive
(
:add_path
)
expect
(
store
).
not_to
receive
(
:add_path
)
end
end
it
"calls add_path with http_settings['ca_path']"
do
it
"calls add_path with http_settings['ca_path']"
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'ca_file'
)
{
nil
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'ca_file'
)
{
nil
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'ca_path'
)
{
'test_path'
}
allow
(
gitlab_net
.
send
(
:config
).
http_settings
).
to
receive
(
:[]
).
with
(
'ca_path'
)
{
'test_path'
}
store
.
should_not_
receive
(
:add_file
)
expect
(
store
).
not_to
receive
(
:add_file
)
store
.
should_
receive
(
:add_path
).
with
(
'test_path'
)
expect
(
store
).
to
receive
(
:add_path
).
with
(
'test_path'
)
end
end
end
end
end
end
spec/gitlab_post_receive_spec.rb
View file @
cfec435a
...
@@ -31,7 +31,7 @@ describe GitlabPostReceive do
...
@@ -31,7 +31,7 @@ describe GitlabPostReceive do
before
do
before
do
$logger
=
double
(
'logger'
).
as_null_object
# Global vars are bad
$logger
=
double
(
'logger'
).
as_null_object
# Global vars are bad
GitlabConfig
.
any_instance
.
stub
(
repos_path:
repository_path
)
allow_any_instance_of
(
GitlabConfig
).
to
receive
(
:repos_path
).
and_return
(
repository_path
)
end
end
describe
"#exec"
do
describe
"#exec"
do
...
...
spec/gitlab_shell_spec.rb
View file @
cfec435a
...
@@ -15,8 +15,8 @@ describe GitlabShell do
...
@@ -15,8 +15,8 @@ describe GitlabShell do
subject
do
subject
do
ARGV
[
0
]
=
gl_id
ARGV
[
0
]
=
gl_id
GitlabShell
.
new
(
gl_id
).
tap
do
|
shell
|
GitlabShell
.
new
(
gl_id
).
tap
do
|
shell
|
shell
.
stub
(
exec_cmd:
:exec_called
)
allow
(
shell
).
to
receive
(
:exec_cmd
).
and_return
(
:exec_called
)
shell
.
stub
(
api:
api
)
allow
(
shell
).
to
receive
(
:api
).
and_return
(
api
)
end
end
end
end
...
@@ -37,8 +37,8 @@ describe GitlabShell do
...
@@ -37,8 +37,8 @@ describe GitlabShell do
let
(
:api
)
do
let
(
:api
)
do
double
(
GitlabNet
).
tap
do
|
api
|
double
(
GitlabNet
).
tap
do
|
api
|
a
pi
.
stub
(
discover:
{
'name'
=>
'John Doe'
,
'username'
=>
'testuser'
})
a
llow
(
api
).
to
receive
(
:discover
).
and_return
(
{
'name'
=>
'John Doe'
,
'username'
=>
'testuser'
})
a
pi
.
stub
(
check_access:
GitAccessStatus
.
new
(
a
llow
(
api
).
to
receive
(
:check_access
).
and_return
(
GitAccessStatus
.
new
(
true
,
true
,
'ok'
,
'ok'
,
gl_repository:
gl_repository
,
gl_repository:
gl_repository
,
...
@@ -48,7 +48,7 @@ describe GitlabShell do
...
@@ -48,7 +48,7 @@ describe GitlabShell do
repository_path:
repo_path
,
repository_path:
repo_path
,
gitaly:
nil
,
gitaly:
nil
,
git_protocol:
git_protocol
))
git_protocol:
git_protocol
))
a
pi
.
stub
(
two_factor_recovery_codes:
{
a
llow
(
api
).
to
receive
(
:two_factor_recovery_codes
).
and_return
(
{
'success'
=>
true
,
'success'
=>
true
,
'recovery_codes'
=>
%w[f67c514de60c4953 41278385fc00c1e0]
'recovery_codes'
=>
%w[f67c514de60c4953 41278385fc00c1e0]
})
})
...
@@ -68,7 +68,7 @@ describe GitlabShell do
...
@@ -68,7 +68,7 @@ describe GitlabShell do
let
(
:git_protocol
)
{
'version=2'
}
let
(
:git_protocol
)
{
'version=2'
}
before
do
before
do
GitlabConfig
.
any_instance
.
stub
(
audit_usernames:
false
)
allow_any_instance_of
(
GitlabConfig
).
to
receive
(
:audit_usernames
).
and_return
(
false
)
end
end
describe
:initialize
do
describe
:initialize
do
...
@@ -177,22 +177,22 @@ describe GitlabShell do
...
@@ -177,22 +177,22 @@ describe GitlabShell do
after
{
subject
.
exec
(
ssh_cmd
)
}
after
{
subject
.
exec
(
ssh_cmd
)
}
it
"should process the command"
do
it
"should process the command"
do
subject
.
should_
receive
(
:process_cmd
).
with
(
%w(git-upload-pack gitlab-ci.git)
)
expect
(
subject
).
to
receive
(
:process_cmd
).
with
(
%w(git-upload-pack gitlab-ci.git)
)
end
end
it
"should execute the command"
do
it
"should execute the command"
do
subject
.
should_
receive
(
:exec_cmd
).
with
(
'git-upload-pack'
,
repo_path
)
expect
(
subject
).
to
receive
(
:exec_cmd
).
with
(
'git-upload-pack'
,
repo_path
)
end
end
it
"should log the command execution"
do
it
"should log the command execution"
do
message
=
"executing git command"
message
=
"executing git command"
user_string
=
"user with id
#{
gl_id
}
"
user_string
=
"user with id
#{
gl_id
}
"
$logger
.
should_
receive
(
:info
).
with
(
message
,
command:
"git-upload-pack
#{
repo_path
}
"
,
user:
user_string
)
expect
(
$logger
).
to
receive
(
:info
).
with
(
message
,
command:
"git-upload-pack
#{
repo_path
}
"
,
user:
user_string
)
end
end
it
"should use usernames if configured to do so"
do
it
"should use usernames if configured to do so"
do
GitlabConfig
.
any_instance
.
stub
(
audit_usernames:
true
)
allow_any_instance_of
(
GitlabConfig
).
to
receive
(
:audit_usernames
).
and_return
(
true
)
$logger
.
should_
receive
(
:info
).
with
(
"executing git command"
,
hash_including
(
user:
'testuser'
))
expect
(
$logger
).
to
receive
(
:info
).
with
(
"executing git command"
,
hash_including
(
user:
'testuser'
))
end
end
end
end
...
@@ -207,27 +207,27 @@ describe GitlabShell do
...
@@ -207,27 +207,27 @@ describe GitlabShell do
context
'gitaly-upload-pack'
do
context
'gitaly-upload-pack'
do
let
(
:ssh_cmd
)
{
"git-upload-pack gitlab-ci.git"
}
let
(
:ssh_cmd
)
{
"git-upload-pack gitlab-ci.git"
}
before
do
before
do
a
pi
.
stub
(
check_access:
gitaly_check_access
)
a
llow
(
api
).
to
receive
(
:check_access
).
and_return
(
gitaly_check_access
)
end
end
after
{
subject
.
exec
(
ssh_cmd
)
}
after
{
subject
.
exec
(
ssh_cmd
)
}
it
"should process the command"
do
it
"should process the command"
do
subject
.
should_
receive
(
:process_cmd
).
with
(
%w(git-upload-pack gitlab-ci.git)
)
expect
(
subject
).
to
receive
(
:process_cmd
).
with
(
%w(git-upload-pack gitlab-ci.git)
)
end
end
it
"should execute the command"
do
it
"should execute the command"
do
subject
.
should_
receive
(
:exec_cmd
).
with
(
File
.
join
(
ROOT_PATH
,
"bin/gitaly-upload-pack"
),
'unix:gitaly.socket'
,
gitaly_message
)
expect
(
subject
).
to
receive
(
:exec_cmd
).
with
(
File
.
join
(
ROOT_PATH
,
"bin/gitaly-upload-pack"
),
'unix:gitaly.socket'
,
gitaly_message
)
end
end
it
"should log the command execution"
do
it
"should log the command execution"
do
message
=
"executing git command"
message
=
"executing git command"
user_string
=
"user with id
#{
gl_id
}
"
user_string
=
"user with id
#{
gl_id
}
"
$logger
.
should_
receive
(
:info
).
with
(
message
,
command:
"gitaly-upload-pack unix:gitaly.socket
#{
gitaly_message
}
"
,
user:
user_string
)
expect
(
$logger
).
to
receive
(
:info
).
with
(
message
,
command:
"gitaly-upload-pack unix:gitaly.socket
#{
gitaly_message
}
"
,
user:
user_string
)
end
end
it
"should use usernames if configured to do so"
do
it
"should use usernames if configured to do so"
do
GitlabConfig
.
any_instance
.
stub
(
audit_usernames:
true
)
allow_any_instance_of
(
GitlabConfig
).
to
receive
(
:audit_usernames
).
and_return
(
true
)
$logger
.
should_
receive
(
:info
).
with
(
"executing git command"
,
hash_including
(
user:
'testuser'
))
expect
(
$logger
).
to
receive
(
:info
).
with
(
"executing git command"
,
hash_including
(
user:
'testuser'
))
end
end
end
end
...
@@ -236,44 +236,44 @@ describe GitlabShell do
...
@@ -236,44 +236,44 @@ describe GitlabShell do
after
{
subject
.
exec
(
ssh_cmd
)
}
after
{
subject
.
exec
(
ssh_cmd
)
}
it
"should process the command"
do
it
"should process the command"
do
subject
.
should_
receive
(
:process_cmd
).
with
(
%w(git-receive-pack gitlab-ci.git)
)
expect
(
subject
).
to
receive
(
:process_cmd
).
with
(
%w(git-receive-pack gitlab-ci.git)
)
end
end
it
"should execute the command"
do
it
"should execute the command"
do
subject
.
should_
receive
(
:exec_cmd
).
with
(
'git-receive-pack'
,
repo_path
)
expect
(
subject
).
to
receive
(
:exec_cmd
).
with
(
'git-receive-pack'
,
repo_path
)
end
end
it
"should log the command execution"
do
it
"should log the command execution"
do
message
=
"executing git command"
message
=
"executing git command"
user_string
=
"user with id
#{
gl_id
}
"
user_string
=
"user with id
#{
gl_id
}
"
$logger
.
should_
receive
(
:info
).
with
(
message
,
command:
"git-receive-pack
#{
repo_path
}
"
,
user:
user_string
)
expect
(
$logger
).
to
receive
(
:info
).
with
(
message
,
command:
"git-receive-pack
#{
repo_path
}
"
,
user:
user_string
)
end
end
end
end
context
'gitaly-receive-pack'
do
context
'gitaly-receive-pack'
do
let
(
:ssh_cmd
)
{
"git-receive-pack gitlab-ci.git"
}
let
(
:ssh_cmd
)
{
"git-receive-pack gitlab-ci.git"
}
before
do
before
do
a
pi
.
stub
(
check_access:
gitaly_check_access
)
a
llow
(
api
).
to
receive
(
:check_access
).
and_return
(
gitaly_check_access
)
end
end
after
{
subject
.
exec
(
ssh_cmd
)
}
after
{
subject
.
exec
(
ssh_cmd
)
}
it
"should process the command"
do
it
"should process the command"
do
subject
.
should_
receive
(
:process_cmd
).
with
(
%w(git-receive-pack gitlab-ci.git)
)
expect
(
subject
).
to
receive
(
:process_cmd
).
with
(
%w(git-receive-pack gitlab-ci.git)
)
end
end
it
"should execute the command"
do
it
"should execute the command"
do
subject
.
should_
receive
(
:exec_cmd
).
with
(
File
.
join
(
ROOT_PATH
,
"bin/gitaly-receive-pack"
),
'unix:gitaly.socket'
,
gitaly_message
)
expect
(
subject
).
to
receive
(
:exec_cmd
).
with
(
File
.
join
(
ROOT_PATH
,
"bin/gitaly-receive-pack"
),
'unix:gitaly.socket'
,
gitaly_message
)
end
end
it
"should log the command execution"
do
it
"should log the command execution"
do
message
=
"executing git command"
message
=
"executing git command"
user_string
=
"user with id
#{
gl_id
}
"
user_string
=
"user with id
#{
gl_id
}
"
$logger
.
should_
receive
(
:info
).
with
(
message
,
command:
"gitaly-receive-pack unix:gitaly.socket
#{
gitaly_message
}
"
,
user:
user_string
)
expect
(
$logger
).
to
receive
(
:info
).
with
(
message
,
command:
"gitaly-receive-pack unix:gitaly.socket
#{
gitaly_message
}
"
,
user:
user_string
)
end
end
it
"should use usernames if configured to do so"
do
it
"should use usernames if configured to do so"
do
GitlabConfig
.
any_instance
.
stub
(
audit_usernames:
true
)
allow_any_instance_of
(
GitlabConfig
).
to
receive
(
:audit_usernames
).
and_return
(
true
)
$logger
.
should_
receive
(
:info
).
with
(
"executing git command"
,
hash_including
(
user:
'testuser'
))
expect
(
$logger
).
to
receive
(
:info
).
with
(
"executing git command"
,
hash_including
(
user:
'testuser'
))
end
end
end
end
...
@@ -285,22 +285,22 @@ describe GitlabShell do
...
@@ -285,22 +285,22 @@ describe GitlabShell do
after
{
subject
.
exec
(
ssh_cmd
)
}
after
{
subject
.
exec
(
ssh_cmd
)
}
it
"should process the command"
do
it
"should process the command"
do
subject
.
should_
receive
(
:process_cmd
).
with
(
%w(git-upload-archive gitlab-ci.git)
)
expect
(
subject
).
to
receive
(
:process_cmd
).
with
(
%w(git-upload-archive gitlab-ci.git)
)
end
end
it
"should execute the command"
do
it
"should execute the command"
do
subject
.
should_
receive
(
:exec_cmd
).
with
(
*
exec_cmd_params
)
expect
(
subject
).
to
receive
(
:exec_cmd
).
with
(
*
exec_cmd_params
)
end
end
it
"should log the command execution"
do
it
"should log the command execution"
do
message
=
"executing git command"
message
=
"executing git command"
user_string
=
"user with id
#{
gl_id
}
"
user_string
=
"user with id
#{
gl_id
}
"
$logger
.
should_
receive
(
:info
).
with
(
message
,
command:
exec_cmd_log_params
.
join
(
' '
),
user:
user_string
)
expect
(
$logger
).
to
receive
(
:info
).
with
(
message
,
command:
exec_cmd_log_params
.
join
(
' '
),
user:
user_string
)
end
end
it
"should use usernames if configured to do so"
do
it
"should use usernames if configured to do so"
do
GitlabConfig
.
any_instance
.
stub
(
audit_usernames:
true
)
allow_any_instance_of
(
GitlabConfig
).
to
receive
(
:audit_usernames
).
and_return
(
true
)
$logger
.
should_
receive
(
:info
).
with
(
"executing git command"
,
hash_including
(
user:
'testuser'
))
expect
(
$logger
).
to
receive
(
:info
).
with
(
"executing git command"
,
hash_including
(
user:
'testuser'
))
end
end
end
end
...
@@ -314,7 +314,7 @@ describe GitlabShell do
...
@@ -314,7 +314,7 @@ describe GitlabShell do
context
'gitaly-upload-archive'
do
context
'gitaly-upload-archive'
do
before
do
before
do
a
pi
.
stub
(
check_access:
gitaly_check_access
)
a
llow
(
api
).
to
receive
(
:check_access
).
and_return
(
gitaly_check_access
)
end
end
it_behaves_like
'upload-archive'
,
'git-upload-archive'
do
it_behaves_like
'upload-archive'
,
'git-upload-archive'
do
...
@@ -337,17 +337,17 @@ describe GitlabShell do
...
@@ -337,17 +337,17 @@ describe GitlabShell do
after
{
subject
.
exec
(
ssh_cmd
)
}
after
{
subject
.
exec
(
ssh_cmd
)
}
it
"should not process the command"
do
it
"should not process the command"
do
subject
.
should_not_
receive
(
:process_cmd
)
expect
(
subject
).
not_to
receive
(
:process_cmd
)
end
end
it
"should not execute the command"
do
it
"should not execute the command"
do
subject
.
should_not_
receive
(
:exec_cmd
)
expect
(
subject
).
not_to
receive
(
:exec_cmd
)
end
end
it
"should log the attempt"
do
it
"should log the attempt"
do
message
=
'Denied disallowed command'
message
=
'Denied disallowed command'
user_string
=
"user with id
#{
gl_id
}
"
user_string
=
"user with id
#{
gl_id
}
"
$logger
.
should_
receive
(
:warn
).
with
(
message
,
command:
'arbitrary command'
,
user:
user_string
)
expect
(
$logger
).
to
receive
(
:warn
).
with
(
message
,
command:
'arbitrary command'
,
user:
user_string
)
end
end
end
end
...
@@ -355,7 +355,7 @@ describe GitlabShell do
...
@@ -355,7 +355,7 @@ describe GitlabShell do
after
{
subject
.
exec
(
nil
)
}
after
{
subject
.
exec
(
nil
)
}
it
"should call api.discover"
do
it
"should call api.discover"
do
api
.
should_
receive
(
:discover
).
with
(
gl_id
)
expect
(
api
).
to
receive
(
:discover
).
with
(
gl_id
)
end
end
end
end
...
@@ -363,16 +363,16 @@ describe GitlabShell do
...
@@ -363,16 +363,16 @@ describe GitlabShell do
let
(
:ssh_cmd
)
{
'git-upload-pack gitlab-ci.git'
}
let
(
:ssh_cmd
)
{
'git-upload-pack gitlab-ci.git'
}
before
do
before
do
a
pi
.
stub
(
:check_access
).
and_raise
(
GitlabNet
::
ApiUnreachableError
)
a
llow
(
api
).
to
receive
(
:check_access
).
and_raise
(
GitlabNet
::
ApiUnreachableError
)
end
end
after
{
subject
.
exec
(
ssh_cmd
)
}
after
{
subject
.
exec
(
ssh_cmd
)
}
it
"should not process the command"
do
it
"should not process the command"
do
subject
.
should_not_
receive
(
:process_cmd
)
expect
(
subject
).
not_to
receive
(
:process_cmd
)
end
end
it
"should not execute the command"
do
it
"should not execute the command"
do
subject
.
should_not_
receive
(
:exec_cmd
)
expect
(
subject
).
not_to
receive
(
:exec_cmd
)
end
end
end
end
...
@@ -402,7 +402,7 @@ describe GitlabShell do
...
@@ -402,7 +402,7 @@ describe GitlabShell do
context
'when the process is unsuccessful'
do
context
'when the process is unsuccessful'
do
it
'displays the error to the user'
do
it
'displays the error to the user'
do
a
pi
.
stub
(
two_factor_recovery_codes:
{
a
llow
(
api
).
to
receive
(
:two_factor_recovery_codes
).
and_return
(
{
'success'
=>
false
,
'success'
=>
false
,
'message'
=>
'Could not find the given key'
'message'
=>
'Could not find the given key'
})
})
...
@@ -422,11 +422,11 @@ describe GitlabShell do
...
@@ -422,11 +422,11 @@ describe GitlabShell do
after
{
subject
.
exec
(
ssh_cmd
)
}
after
{
subject
.
exec
(
ssh_cmd
)
}
it
"should call api.check_access"
do
it
"should call api.check_access"
do
api
.
should_
receive
(
:check_access
).
with
(
'git-upload-pack'
,
nil
,
'gitlab-ci.git'
,
gl_id
,
'_any'
,
'ssh'
)
expect
(
api
).
to
receive
(
:check_access
).
with
(
'git-upload-pack'
,
nil
,
'gitlab-ci.git'
,
gl_id
,
'_any'
,
'ssh'
)
end
end
it
"should disallow access and log the attempt if check_access returns false status"
do
it
"should disallow access and log the attempt if check_access returns false status"
do
a
pi
.
stub
(
check_access:
GitAccessStatus
.
new
(
a
llow
(
api
).
to
receive
(
:check_access
).
and_return
(
GitAccessStatus
.
new
(
false
,
false
,
'denied'
,
'denied'
,
gl_repository:
nil
,
gl_repository:
nil
,
...
@@ -438,7 +438,7 @@ describe GitlabShell do
...
@@ -438,7 +438,7 @@ describe GitlabShell do
git_protocol:
nil
))
git_protocol:
nil
))
message
=
'Access denied'
message
=
'Access denied'
user_string
=
"user with id
#{
gl_id
}
"
user_string
=
"user with id
#{
gl_id
}
"
$logger
.
should_
receive
(
:warn
).
with
(
message
,
command:
'git-upload-pack gitlab-ci.git'
,
user:
user_string
)
expect
(
$logger
).
to
receive
(
:warn
).
with
(
message
,
command:
'git-upload-pack gitlab-ci.git'
,
user:
user_string
)
end
end
end
end
...
@@ -451,11 +451,11 @@ describe GitlabShell do
...
@@ -451,11 +451,11 @@ describe GitlabShell do
context
"with a path that doesn't match an absolute path"
do
context
"with a path that doesn't match an absolute path"
do
before
do
before
do
File
.
stub
(
:absolute_path
)
{
'y/gitlab-ci.git'
}
allow
(
File
).
to
receive
(
:absolute_path
)
{
'y/gitlab-ci.git'
}
end
end
it
"refuses to assign the path"
do
it
"refuses to assign the path"
do
$stderr
.
should_
receive
(
:puts
).
with
(
"GitLab: Invalid repository path"
)
expect
(
$stderr
).
to
receive
(
:puts
).
with
(
"GitLab: Invalid repository path"
)
expect
(
subject
.
exec
(
ssh_cmd
)).
to
be_falsey
expect
(
subject
.
exec
(
ssh_cmd
)).
to
be_falsey
end
end
end
end
...
@@ -478,14 +478,14 @@ describe GitlabShell do
...
@@ -478,14 +478,14 @@ describe GitlabShell do
end
end
let
(
:exec_options
)
{
{
unsetenv_others:
true
,
chdir:
ROOT_PATH
}
}
let
(
:exec_options
)
{
{
unsetenv_others:
true
,
chdir:
ROOT_PATH
}
}
before
do
before
do
Kernel
.
stub
(
:exec
)
allow
(
Kernel
).
to
receive
(
:exec
)
shell
.
gl_repository
=
gl_repository
shell
.
gl_repository
=
gl_repository
shell
.
git_protocol
=
git_protocol
shell
.
git_protocol
=
git_protocol
shell
.
instance_variable_set
(
:@username
,
gl_username
)
shell
.
instance_variable_set
(
:@username
,
gl_username
)
end
end
it
"uses Kernel::exec method"
do
it
"uses Kernel::exec method"
do
Kernel
.
should_
receive
(
:exec
).
with
(
env
,
1
,
2
,
exec_options
).
once
expect
(
Kernel
).
to
receive
(
:exec
).
with
(
env
,
1
,
2
,
exec_options
).
once
shell
.
send
:exec_cmd
,
1
,
2
shell
.
send
:exec_cmd
,
1
,
2
end
end
...
@@ -494,7 +494,7 @@ describe GitlabShell do
...
@@ -494,7 +494,7 @@ describe GitlabShell do
end
end
it
"allows one argument if it is an array"
do
it
"allows one argument if it is an array"
do
Kernel
.
should_
receive
(
:exec
).
with
(
env
,
[
1
,
2
],
exec_options
).
once
expect
(
Kernel
).
to
receive
(
:exec
).
with
(
env
,
[
1
,
2
],
exec_options
).
once
shell
.
send
:exec_cmd
,
[
1
,
2
]
shell
.
send
:exec_cmd
,
[
1
,
2
]
end
end
...
@@ -502,7 +502,7 @@ describe GitlabShell do
...
@@ -502,7 +502,7 @@ describe GitlabShell do
let
(
:git_trace_log_file
)
{
'/tmp/git_trace_performance.log'
}
let
(
:git_trace_log_file
)
{
'/tmp/git_trace_performance.log'
}
before
do
before
do
GitlabConfig
.
any_instance
.
stub
(
git_trace_log_file:
git_trace_log_file
)
allow_any_instance_of
(
GitlabConfig
).
to
receive
(
:git_trace_log_file
).
and_return
(
git_trace_log_file
)
shell
shell
end
end
...
@@ -512,7 +512,7 @@ describe GitlabShell do
...
@@ -512,7 +512,7 @@ describe GitlabShell do
'GIT_TRACE_PACKET'
=>
git_trace_log_file
,
'GIT_TRACE_PACKET'
=>
git_trace_log_file
,
'GIT_TRACE_PERFORMANCE'
=>
git_trace_log_file
'GIT_TRACE_PERFORMANCE'
=>
git_trace_log_file
)
)
Kernel
.
should_
receive
(
:exec
).
with
(
expected_hash
,
[
1
,
2
],
exec_options
).
once
expect
(
Kernel
).
to
receive
(
:exec
).
with
(
expected_hash
,
[
1
,
2
],
exec_options
).
once
shell
.
send
:exec_cmd
,
[
1
,
2
]
shell
.
send
:exec_cmd
,
[
1
,
2
]
end
end
...
@@ -525,7 +525,7 @@ describe GitlabShell do
...
@@ -525,7 +525,7 @@ describe GitlabShell do
expected_hash
=
hash_excluding
(
expected_hash
=
hash_excluding
(
'GIT_TRACE'
,
'GIT_TRACE_PACKET'
,
'GIT_TRACE_PERFORMANCE'
'GIT_TRACE'
,
'GIT_TRACE_PACKET'
,
'GIT_TRACE_PERFORMANCE'
)
)
Kernel
.
should_
receive
(
:exec
).
with
(
expected_hash
,
[
1
,
2
],
exec_options
).
once
expect
(
Kernel
).
to
receive
(
:exec
).
with
(
expected_hash
,
[
1
,
2
],
exec_options
).
once
shell
.
send
:exec_cmd
,
[
1
,
2
]
shell
.
send
:exec_cmd
,
[
1
,
2
]
end
end
...
@@ -536,7 +536,7 @@ describe GitlabShell do
...
@@ -536,7 +536,7 @@ describe GitlabShell do
expect
(
$logger
).
to
receive
(
:warn
).
expect
(
$logger
).
to
receive
(
:warn
).
with
(
message
,
git_trace_log_file:
git_trace_log_file
)
with
(
message
,
git_trace_log_file:
git_trace_log_file
)
Kernel
.
should_
receive
(
:exec
).
with
(
env
,
[
1
,
2
],
exec_options
).
once
expect
(
Kernel
).
to
receive
(
:exec
).
with
(
env
,
[
1
,
2
],
exec_options
).
once
shell
.
send
:exec_cmd
,
[
1
,
2
]
shell
.
send
:exec_cmd
,
[
1
,
2
]
end
end
end
end
...
@@ -551,7 +551,7 @@ describe GitlabShell do
...
@@ -551,7 +551,7 @@ describe GitlabShell do
expected_hash
=
hash_excluding
(
expected_hash
=
hash_excluding
(
'GIT_TRACE'
,
'GIT_TRACE_PACKET'
,
'GIT_TRACE_PERFORMANCE'
'GIT_TRACE'
,
'GIT_TRACE_PACKET'
,
'GIT_TRACE_PERFORMANCE'
)
)
Kernel
.
should_
receive
(
:exec
).
with
(
expected_hash
,
[
1
,
2
],
exec_options
).
once
expect
(
Kernel
).
to
receive
(
:exec
).
with
(
expected_hash
,
[
1
,
2
],
exec_options
).
once
shell
.
send
:exec_cmd
,
[
1
,
2
]
shell
.
send
:exec_cmd
,
[
1
,
2
]
end
end
...
@@ -563,7 +563,7 @@ describe GitlabShell do
...
@@ -563,7 +563,7 @@ describe GitlabShell do
expect
(
$logger
).
to
receive
(
:warn
).
expect
(
$logger
).
to
receive
(
:warn
).
with
(
message
,
git_trace_log_file:
git_trace_log_file
,
error:
error
)
with
(
message
,
git_trace_log_file:
git_trace_log_file
,
error:
error
)
Kernel
.
should_
receive
(
:exec
).
with
(
env
,
[
1
,
2
],
exec_options
).
once
expect
(
Kernel
).
to
receive
(
:exec
).
with
(
env
,
[
1
,
2
],
exec_options
).
once
shell
.
send
:exec_cmd
,
[
1
,
2
]
shell
.
send
:exec_cmd
,
[
1
,
2
]
end
end
end
end
...
@@ -574,6 +574,6 @@ describe GitlabShell do
...
@@ -574,6 +574,6 @@ describe GitlabShell do
let
(
:shell
)
{
GitlabShell
.
new
(
gl_id
)
}
let
(
:shell
)
{
GitlabShell
.
new
(
gl_id
)
}
subject
{
shell
.
send
:api
}
subject
{
shell
.
send
:api
}
it
{
should
be_a
(
GitlabNet
)
}
it
{
is_expected
.
to
be_a
(
GitlabNet
)
}
end
end
end
end
spec/httpunix_spec.rb
View file @
cfec435a
...
@@ -6,7 +6,7 @@ describe URI::HTTPUNIX do
...
@@ -6,7 +6,7 @@ describe URI::HTTPUNIX do
uri
=
URI
::
parse
(
'http+unix://%2Fpath%2Fto%2Fsocket/img.jpg'
)
uri
=
URI
::
parse
(
'http+unix://%2Fpath%2Fto%2Fsocket/img.jpg'
)
subject
{
uri
}
subject
{
uri
}
it
{
should
be_an_instance_of
(
URI
::
HTTPUNIX
)
}
it
{
is_expected
.
to
be_an_instance_of
(
URI
::
HTTPUNIX
)
}
its
(
:scheme
)
{
should
eq
(
'http+unix'
)
}
its
(
:scheme
)
{
should
eq
(
'http+unix'
)
}
its
(
:hostname
)
{
should
eq
(
'/path/to/socket'
)
}
its
(
:hostname
)
{
should
eq
(
'/path/to/socket'
)
}
its
(
:path
)
{
should
eq
(
'/img.jpg'
)
}
its
(
:path
)
{
should
eq
(
'/img.jpg'
)
}
...
...
spec/names_helper_spec.rb
View file @
cfec435a
...
@@ -5,8 +5,8 @@ describe NamesHelper do
...
@@ -5,8 +5,8 @@ describe NamesHelper do
include
NamesHelper
include
NamesHelper
describe
:extract_ref_name
do
describe
:extract_ref_name
do
it
{
ex
tract_ref_name
(
'refs/heads/awesome-feature'
).
should
==
'awesome-feature'
}
it
{
ex
pect
(
extract_ref_name
(
'refs/heads/awesome-feature'
)).
to
eq
(
'awesome-feature'
)
}
it
{
ex
tract_ref_name
(
'refs/tags/v2.2.1'
).
should
==
'v2.2.1'
}
it
{
ex
pect
(
extract_ref_name
(
'refs/tags/v2.2.1'
)).
to
eq
(
'v2.2.1'
)
}
it
{
ex
tract_ref_name
(
'refs/tags/releases/v2.2.1'
).
should
==
'releases/v2.2.1'
}
it
{
ex
pect
(
extract_ref_name
(
'refs/tags/releases/v2.2.1'
)).
to
eq
(
'releases/v2.2.1'
)
}
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