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
633042fd
Commit
633042fd
authored
Nov 02, 2013
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove sed invocation from GitlabKeys
parent
261cb1fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
lib/gitlab_keys.rb
lib/gitlab_keys.rb
+7
-2
spec/gitlab_keys_spec.rb
spec/gitlab_keys_spec.rb
+10
-5
No files found.
lib/gitlab_keys.rb
View file @
633042fd
...
...
@@ -36,8 +36,13 @@ class GitlabKeys
def
rm_key
$logger
.
info
"Removing key
#{
@key_id
}
"
Tempfile
.
open
(
'authorized_keys'
)
do
|
temp
|
cmd
=
"sed '/shell
#{
@key_id
}
\"
/d'
#{
auth_file
}
>
#{
temp
.
path
}
&& mv
#{
temp
.
path
}
#{
auth_file
}
"
system
(
cmd
)
open
(
auth_file
,
'r+'
)
do
|
current
|
current
.
each
do
|
line
|
temp
.
puts
(
line
)
unless
line
.
include?
(
"/bin/gitlab-shell
#{
@key_id
}
\"
"
)
end
end
temp
.
close
FileUtils
.
cp
(
temp
.
path
,
auth_file
)
end
end
...
...
spec/gitlab_keys_spec.rb
View file @
633042fd
...
...
@@ -34,14 +34,15 @@ describe GitlabKeys do
describe
:rm_key
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'rm-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
}
let
(
:temp_file
)
{
mock
(
:temp_file
,
path:
'tmp_path'
)
}
before
{
Tempfile
.
should_receive
(
:open
).
and_yield
(
temp_file
)
}
it
"should receive valid cmd"
do
auth_file
=
GitlabConfig
.
new
.
auth_file
valid_cmd
=
"sed '/shell key-741
\"
/d'
#{
auth_file
}
> tmp_path && mv tmp_path
#{
auth_file
}
"
gitlab_keys
.
should_receive
(
:system
).
with
(
valid_cmd
)
FileUtils
.
mkdir_p
(
File
.
dirname
(
tmp_authorized_keys_path
))
open
(
tmp_authorized_keys_path
,
'w'
)
do
|
auth_file
|
auth_file
.
puts
[
'first key'
,
'/bin/gitlab-shell key-741"'
,
'third key'
]
end
gitlab_keys
.
stub
(
auth_file:
tmp_authorized_keys_path
)
gitlab_keys
.
send
:rm_key
File
.
read
(
tmp_authorized_keys_path
).
should
==
"first key
\n
third key
\n
"
end
it
"should log an rm-key event"
do
...
...
@@ -87,4 +88,8 @@ describe GitlabKeys do
ARGV
[
i
]
=
arg
end
end
def
tmp_authorized_keys_path
File
.
join
(
ROOT_PATH
,
'tmp'
,
'authorized_keys'
)
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