Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
Jérome Perrin
gitlab-ce
Commits
deb474b4
Commit
deb474b4
authored
Jul 06, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract common method
parent
b66e3726
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
21 deletions
+30
-21
lib/gitlab/gpg.rb
lib/gitlab/gpg.rb
+9
-13
spec/lib/gitlab/gpg_spec.rb
spec/lib/gitlab/gpg_spec.rb
+21
-8
No files found.
lib/gitlab/gpg.rb
View file @
deb474b4
...
@@ -8,10 +8,8 @@ module Gitlab
...
@@ -8,10 +8,8 @@ module Gitlab
def
add
(
key
)
def
add
(
key
)
GPGME
::
Key
.
import
(
key
)
GPGME
::
Key
.
import
(
key
)
end
end
end
def
fingerprints_from_key
(
key
)
def
fingerprints_from_key
(
key
)
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
import
=
GPGME
::
Key
.
import
(
key
)
return
[]
if
import
.
imported
==
0
return
[]
if
import
.
imported
==
0
...
@@ -20,13 +18,15 @@ module Gitlab
...
@@ -20,13 +18,15 @@ module Gitlab
end
end
end
end
def
primary_keyid
s_from_key
(
key
)
def
fingerprint
s_from_key
(
key
)
using_tmp_keychain
do
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
CurrentKeyChain
.
fingerprints_from_key
(
key
)
end
return
[]
if
import
.
imported
==
0
end
fingerprints
=
import
.
imports
.
map
(
&
:fingerprint
)
def
primary_keyids_from_key
(
key
)
using_tmp_keychain
do
fingerprints
=
CurrentKeyChain
.
fingerprints_from_key
(
key
)
GPGME
::
Key
.
find
(
:public
,
fingerprints
).
map
{
|
raw_key
|
raw_key
.
primary_subkey
.
keyid
}
GPGME
::
Key
.
find
(
:public
,
fingerprints
).
map
{
|
raw_key
|
raw_key
.
primary_subkey
.
keyid
}
end
end
...
@@ -34,11 +34,7 @@ module Gitlab
...
@@ -34,11 +34,7 @@ module Gitlab
def
emails_from_key
(
key
)
def
emails_from_key
(
key
)
using_tmp_keychain
do
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
fingerprints
=
CurrentKeyChain
.
fingerprints_from_key
(
key
)
return
[]
if
import
.
imported
==
0
fingerprints
=
import
.
imports
.
map
(
&
:fingerprint
)
GPGME
::
Key
.
find
(
:public
,
fingerprints
).
flat_map
{
|
raw_key
|
raw_key
.
uids
.
map
(
&
:email
)
}
GPGME
::
Key
.
find
(
:public
,
fingerprints
).
flat_map
{
|
raw_key
|
raw_key
.
uids
.
map
(
&
:email
)
}
end
end
...
...
spec/lib/gitlab/gpg_spec.rb
View file @
deb474b4
...
@@ -2,16 +2,15 @@ require 'rails_helper'
...
@@ -2,16 +2,15 @@ require 'rails_helper'
describe
Gitlab
::
Gpg
do
describe
Gitlab
::
Gpg
do
describe
'.fingerprints_from_key'
do
describe
'.fingerprints_from_key'
do
it
'returns the fingerprint'
do
before
do
expect
(
# make sure that each method is using the temporary keychain
described_class
.
fingerprints_from_key
(
GpgHelpers
::
User1
.
public_key
)
expect
(
described_class
).
to
receive
(
:using_tmp_keychain
).
and_call_original
).
to
eq
[
GpgHelpers
::
User1
.
fingerprint
]
end
end
it
'returns
an empty array when the key is invalid
'
do
it
'returns
CurrentKeyChain.fingerprints_from_key
'
do
expect
(
expect
(
Gitlab
::
Gpg
::
CurrentKeyChain
).
to
receive
(
:fingerprints_from_key
).
with
(
GpgHelpers
::
User1
.
public_key
)
described_class
.
fingerprints_from_key
(
'bogus'
)
).
to
eq
[]
described_class
.
fingerprints_from_key
(
GpgHelpers
::
User1
.
public_key
)
end
end
end
end
...
@@ -65,4 +64,18 @@ describe Gitlab::Gpg::CurrentKeyChain do
...
@@ -65,4 +64,18 @@ describe Gitlab::Gpg::CurrentKeyChain do
)
)
end
end
end
end
describe
'.fingerprints_from_key'
do
it
'returns the fingerprint'
do
expect
(
described_class
.
fingerprints_from_key
(
GpgHelpers
::
User1
.
public_key
)
).
to
eq
[
GpgHelpers
::
User1
.
fingerprint
]
end
it
'returns an empty array when the key is invalid'
do
expect
(
described_class
.
fingerprints_from_key
(
'bogus'
)
).
to
eq
[]
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