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
Léo-Paul Géneau
gitlab-ce
Commits
0e3d3d60
Commit
0e3d3d60
authored
Feb 24, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
email handling for gpg keys
parent
41c96c45
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
2 deletions
+47
-2
app/models/gpg_key.rb
app/models/gpg_key.rb
+1
-2
lib/gitlab/gpg.rb
lib/gitlab/gpg.rb
+20
-0
spec/lib/gitlab/gpg_spec.rb
spec/lib/gitlab/gpg_spec.rb
+26
-0
No files found.
app/models/gpg_key.rb
View file @
0e3d3d60
...
...
@@ -28,8 +28,7 @@ class GpgKey < ActiveRecord::Base
end
def
emails
raw_key
=
GPGME
::
Key
.
get
(
fingerprint
)
raw_key
.
uids
.
map
(
&
:email
)
Gitlab
::
Gpg
::
CurrentKeyChain
.
emails
(
fingerprint
)
end
private
...
...
lib/gitlab/gpg.rb
View file @
0e3d3d60
...
...
@@ -2,6 +2,14 @@ module Gitlab
module
Gpg
extend
self
module
CurrentKeyChain
extend
self
def
emails
(
fingerprint
)
GPGME
::
Key
.
find
(
:public
,
fingerprint
).
flat_map
{
|
raw_key
|
raw_key
.
uids
.
map
(
&
:email
)
}
end
end
def
fingerprints_from_key
(
key
)
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
...
...
@@ -12,6 +20,18 @@ module Gitlab
end
end
def
emails_from_key
(
key
)
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
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
)
}
end
end
def
add_to_keychain
(
key
)
GPGME
::
Key
.
import
(
key
)
end
...
...
spec/lib/gitlab/gpg_spec.rb
View file @
0e3d3d60
...
...
@@ -15,6 +15,20 @@ describe Gitlab::Gpg do
end
end
describe
'.emails_from_key'
do
it
'returns the emails'
do
expect
(
described_class
.
emails_from_key
(
GpgHelpers
::
User1
.
public_key
)
).
to
eq
GpgHelpers
::
User1
.
emails
end
it
'returns an empty array when the key is invalid'
do
expect
(
described_class
.
emails_from_key
(
'bogus'
)
).
to
eq
[]
end
end
describe
'.add_to_keychain'
,
:gpg
do
it
'stores the key in the keychain'
do
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
to
eq
[]
...
...
@@ -36,3 +50,15 @@ describe Gitlab::Gpg do
end
end
end
describe
Gitlab
::
Gpg
::
CurrentKeyChain
,
:gpg
do
describe
'.emails'
do
it
'returns the emails'
do
Gitlab
::
Gpg
.
add_to_keychain
(
GpgHelpers
::
User2
.
public_key
)
expect
(
described_class
.
emails
(
GpgHelpers
::
User2
.
fingerprint
)
).
to
match_array
GpgHelpers
::
User2
.
emails
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