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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-shell
Commits
519ba6f9
Commit
519ba6f9
authored
Mar 11, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test GitlabKeys exec
parent
409404d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
19 deletions
+37
-19
lib/gitlab_keys.rb
lib/gitlab_keys.rb
+2
-0
spec/gitlab_keys_spec.rb
spec/gitlab_keys_spec.rb
+35
-19
No files found.
lib/gitlab_keys.rb
View file @
519ba6f9
require
'open3'
require_relative
'gitlab_config'
class
GitlabKeys
attr_accessor
:auth_file
,
:key
...
...
spec/gitlab_keys_spec.rb
View file @
519ba6f9
...
...
@@ -3,40 +3,56 @@ require_relative '../lib/gitlab_keys'
describe
GitlabKeys
do
describe
:initialize
do
before
do
argv
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
@gl_keys
=
GitlabKeys
.
new
end
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
it
{
@gl
_keys
.
key
.
should
==
'ssh-rsa AAAAB3NzaDAxx2E'
}
it
{
@gl
_keys
.
instance_variable_get
(
:@command
).
should
==
'add-key'
}
it
{
@gl
_keys
.
instance_variable_get
(
:@key_id
).
should
==
'key-741'
}
it
{
gitlab
_keys
.
key
.
should
==
'ssh-rsa AAAAB3NzaDAxx2E'
}
it
{
gitlab
_keys
.
instance_variable_get
(
:@command
).
should
==
'add-key'
}
it
{
gitlab
_keys
.
instance_variable_get
(
:@key_id
).
should
==
'key-741'
}
end
describe
:add_key
do
before
do
argv
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
@gl_keys
=
GitlabKeys
.
new
end
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
it
"should receive valid cmd"
do
valid_cmd
=
"echo 'command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-741
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaDAxx2E' >>
#{
GitlabConfig
.
new
.
auth_file
}
"
@gl
_keys
.
should_receive
(
:system
).
with
(
valid_cmd
)
@gl
_keys
.
send
:add_key
gitlab
_keys
.
should_receive
(
:system
).
with
(
valid_cmd
)
gitlab
_keys
.
send
:add_key
end
end
describe
:rm_key
do
before
do
argv
(
'rm-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
@gl_keys
=
GitlabKeys
.
new
end
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'rm-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
it
"should receive valid cmd"
do
valid_cmd
=
"sed -i '/shell key-741/d'
#{
GitlabConfig
.
new
.
auth_file
}
"
@gl_keys
.
should_receive
(
:system
).
with
(
valid_cmd
)
@gl_keys
.
send
:rm_key
gitlab_keys
.
should_receive
(
:system
).
with
(
valid_cmd
)
gitlab_keys
.
send
:rm_key
end
end
describe
:exec
do
it
'add-key arg should execute add_key method'
do
gitlab_keys
=
build_gitlab_keys
(
'add-key'
)
gitlab_keys
.
should_receive
(
:add_key
)
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
'should puts message if unknown command arg'
do
gitlab_keys
=
build_gitlab_keys
(
'change-key'
)
gitlab_keys
.
should_receive
(
:puts
).
with
(
'not allowed'
)
gitlab_keys
.
exec
end
end
def
build_gitlab_keys
(
*
args
)
argv
(
*
args
)
GitlabKeys
.
new
end
def
argv
(
*
args
)
...
...
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