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
a1f2c95f
Commit
a1f2c95f
authored
Nov 25, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gitlab_keys_return_values' of /home/git/repositories/gitlab/gitlab-shell
parents
098e5a68
d7e1deb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
24 deletions
+52
-24
lib/gitlab_keys.rb
lib/gitlab_keys.rb
+3
-0
spec/gitlab_keys_spec.rb
spec/gitlab_keys_spec.rb
+49
-24
No files found.
lib/gitlab_keys.rb
View file @
a1f2c95f
...
...
@@ -31,6 +31,7 @@ class GitlabKeys
$logger
.
info
"Adding key
#{
@key_id
}
=>
#{
@key
.
inspect
}
"
auth_line
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell
#{
@key_id
}
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty
#{
@key
}
"
open
(
auth_file
,
'a'
)
{
|
file
|
file
.
puts
(
auth_line
)
}
true
end
def
rm_key
...
...
@@ -44,9 +45,11 @@ class GitlabKeys
temp
.
close
FileUtils
.
cp
(
temp
.
path
,
auth_file
)
end
true
end
def
clear
open
(
auth_file
,
'w'
)
{
|
file
|
file
.
puts
'# Managed by gitlab-shell'
}
true
end
end
spec/gitlab_keys_spec.rb
View file @
a1f2c95f
...
...
@@ -14,46 +14,65 @@ describe GitlabKeys do
it
{
gitlab_keys
.
instance_variable_get
(
:@key_id
).
should
==
'key-741'
}
end
context
"file writing tests"
do
before
do
FileUtils
.
mkdir_p
(
File
.
dirname
(
tmp_authorized_keys_path
))
open
(
tmp_authorized_keys_path
,
'w'
)
{
|
file
|
file
.
puts
(
'existing content'
)
}
gitlab_keys
.
stub
(
auth_file:
tmp_authorized_keys_path
)
end
describe
:add_key
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
describe
:add_key
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
it
"adds a line at the end of the file"
do
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"
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
auth_line
}
\n
"
end
it
"adds a line at the end of the file"
do
create_authorized_keys_fixture
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"
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
auth_line
}
\n
"
end
context
"without file writing"
do
before
{
gitlab_keys
.
stub
(
:open
)
}
it
"should log an add-key event"
do
$logger
.
should_receive
(
:info
).
with
(
'Adding key key-741 => "ssh-rsa AAAAB3NzaDAxx2E"'
)
gitlab_keys
.
stub
(
:open
)
gitlab_keys
.
send
:add_key
end
it
"should return true"
do
gitlab_keys
.
send
(
:add_key
).
should
be_true
end
end
end
describe
:rm_key
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'rm-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
describe
:rm_key
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'rm-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
it
"removes the right line"
do
other_line
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-742
\"
,options ssh-rsa AAAAB3NzaDAxx2E"
open
(
tmp_authorized_keys_path
,
'a'
)
do
|
auth_file
|
auth_file
.
puts
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-741
\"
,options ssh-rsa AAAAB3NzaDAxx2E"
auth_file
.
puts
other_line
end
gitlab_keys
.
send
:rm_key
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
other_line
}
\n
"
it
"removes the right line"
do
create_authorized_keys_fixture
other_line
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-742
\"
,options ssh-rsa AAAAB3NzaDAxx2E"
open
(
tmp_authorized_keys_path
,
'a'
)
do
|
auth_file
|
auth_file
.
puts
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-741
\"
,options ssh-rsa AAAAB3NzaDAxx2E"
auth_file
.
puts
other_line
end
gitlab_keys
.
send
:rm_key
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
other_line
}
\n
"
end
context
"without file writing"
do
before
{
Tempfile
.
stub
(
:open
)
}
it
"should log an rm-key event"
do
$logger
.
should_receive
(
:info
).
with
(
'Removing key key-741'
)
gitlab_keys
.
send
:rm_key
end
it
"should return true"
do
gitlab_keys
.
send
(
:rm_key
).
should
be_true
end
end
end
describe
:clear
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'clear'
)
}
it
"should return true"
do
gitlab_keys
.
stub
(
:open
)
gitlab_keys
.
send
(
:clear
).
should
be_true
end
end
...
...
@@ -95,6 +114,12 @@ describe GitlabKeys do
end
end
def
create_authorized_keys_fixture
FileUtils
.
mkdir_p
(
File
.
dirname
(
tmp_authorized_keys_path
))
open
(
tmp_authorized_keys_path
,
'w'
)
{
|
file
|
file
.
puts
(
'existing content'
)
}
gitlab_keys
.
stub
(
auth_file:
tmp_authorized_keys_path
)
end
def
tmp_authorized_keys_path
File
.
join
(
ROOT_PATH
,
'tmp'
,
'authorized_keys'
)
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