BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
e34cef0c
Commit
e34cef0c
authored
Feb 22, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract gpg functionality to lib class
parent
7b4d29f4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
12 deletions
+54
-12
gpg_key.rb
app/models/gpg_key.rb
+1
-5
gpg.rb
lib/gitlab/gpg.rb
+32
-0
gpg_spec.rb
spec/lib/gitlab/gpg_spec.rb
+20
-0
spec_helper.rb
spec/spec_helper.rb
+1
-7
No files found.
app/models/gpg_key.rb
View file @
e34cef0c
...
...
@@ -33,12 +33,8 @@ class GpgKey < ActiveRecord::Base
private
def
extract_fingerprint
import
=
GPGME
::
Key
.
import
(
key
)
return
if
import
.
considered
==
0
# we can assume that the result only contains one item as the validation
# only allows one key
self
.
fingerprint
=
import
.
imports
.
first
.
fingerprin
t
self
.
fingerprint
=
Gitlab
::
Gpg
.
fingerprints_from_key
(
key
).
firs
t
end
end
lib/gitlab/gpg.rb
0 → 100644
View file @
e34cef0c
module
Gitlab
module
Gpg
extend
self
def
fingerprints_from_key
(
key
)
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
return
[]
if
import
.
imported
==
0
import
.
imports
.
map
(
&
:fingerprint
)
end
end
def
using_tmp_keychain
Dir
.
mktmpdir
do
|
dir
|
@original_dirs
||=
[
GPGME
::
Engine
.
dirinfo
(
'homedir'
)]
@original_dirs
.
push
(
dir
)
GPGME
::
Engine
.
home_dir
=
dir
return_value
=
yield
@original_dirs
.
pop
GPGME
::
Engine
.
home_dir
=
@original_dirs
[
-
1
]
return_value
end
end
end
end
spec/lib/gitlab/gpg_spec.rb
0 → 100644
View file @
e34cef0c
require
'rails_helper'
describe
Gitlab
::
Gpg
do
describe
'.fingerprints_from_key'
do
it
'returns the fingerprint'
do
expect
(
described_class
.
fingerprints_from_key
(
GpgHelpers
.
public_key
)
).
to
eq
[
'4F4840A503964251CF7D7F5DC728AF10972E97C0'
]
end
it
'returns an empty array when the key is invalid'
do
expect
(
described_class
.
fingerprints_from_key
(
'bogus'
)
).
to
eq
[]
end
end
describe
'.add_to_keychain'
do
end
end
spec/spec_helper.rb
View file @
e34cef0c
...
...
@@ -143,14 +143,8 @@ RSpec.configure do |config|
end
config
.
around
(
:each
,
:gpg
)
do
|
example
|
Dir
.
mktmpdir
do
|
dir
|
original_dir
=
GPGME
::
Engine
.
dirinfo
(
'homedir'
)
GPGME
::
Engine
.
home_dir
=
dir
Gitlab
::
Gpg
.
using_tmp_keychain
do
example
.
run
GPGME
::
Engine
.
home_dir
=
original_dir
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