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
Boxiang Sun
gitlab-ce
Commits
0668521b
Commit
0668521b
authored
Feb 24, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move current keychain methods to namespace
parent
0e3d3d60
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
30 deletions
+32
-30
app/models/gpg_key.rb
app/models/gpg_key.rb
+2
-2
lib/gitlab/gpg.rb
lib/gitlab/gpg.rb
+8
-8
spec/lib/gitlab/gpg_spec.rb
spec/lib/gitlab/gpg_spec.rb
+17
-17
spec/models/gpg_key_spec.rb
spec/models/gpg_key_spec.rb
+5
-3
No files found.
app/models/gpg_key.rb
View file @
0668521b
...
@@ -40,10 +40,10 @@ class GpgKey < ActiveRecord::Base
...
@@ -40,10 +40,10 @@ class GpgKey < ActiveRecord::Base
end
end
def
add_to_keychain
def
add_to_keychain
Gitlab
::
Gpg
.
add_to_keychain
(
key
)
Gitlab
::
Gpg
::
CurrentKeyChain
.
add
(
key
)
end
end
def
remove_from_keychain
def
remove_from_keychain
Gitlab
::
Gpg
.
remove_from_keychain
(
fingerprint
)
Gitlab
::
Gpg
::
CurrentKeyChain
.
remove
(
fingerprint
)
end
end
end
end
lib/gitlab/gpg.rb
View file @
0668521b
...
@@ -5,6 +5,14 @@ module Gitlab
...
@@ -5,6 +5,14 @@ module Gitlab
module
CurrentKeyChain
module
CurrentKeyChain
extend
self
extend
self
def
add
(
key
)
GPGME
::
Key
.
import
(
key
)
end
def
remove
(
fingerprint
)
GPGME
::
Key
.
get
(
fingerprint
).
delete!
end
def
emails
(
fingerprint
)
def
emails
(
fingerprint
)
GPGME
::
Key
.
find
(
:public
,
fingerprint
).
flat_map
{
|
raw_key
|
raw_key
.
uids
.
map
(
&
:email
)
}
GPGME
::
Key
.
find
(
:public
,
fingerprint
).
flat_map
{
|
raw_key
|
raw_key
.
uids
.
map
(
&
:email
)
}
end
end
...
@@ -32,14 +40,6 @@ module Gitlab
...
@@ -32,14 +40,6 @@ module Gitlab
end
end
end
end
def
add_to_keychain
(
key
)
GPGME
::
Key
.
import
(
key
)
end
def
remove_from_keychain
(
fingerprint
)
GPGME
::
Key
.
get
(
fingerprint
).
delete!
end
def
using_tmp_keychain
def
using_tmp_keychain
Dir
.
mktmpdir
do
|
dir
|
Dir
.
mktmpdir
do
|
dir
|
@original_dirs
||=
[
GPGME
::
Engine
.
dirinfo
(
'homedir'
)]
@original_dirs
||=
[
GPGME
::
Engine
.
dirinfo
(
'homedir'
)]
...
...
spec/lib/gitlab/gpg_spec.rb
View file @
0668521b
...
@@ -28,37 +28,37 @@ describe Gitlab::Gpg do
...
@@ -28,37 +28,37 @@ describe Gitlab::Gpg do
).
to
eq
[]
).
to
eq
[]
end
end
end
end
end
describe
Gitlab
::
Gpg
::
CurrentKeyChain
,
:gpg
do
describe
'.emails'
do
it
'returns the emails'
do
Gitlab
::
Gpg
::
CurrentKeyChain
.
add
(
GpgHelpers
::
User2
.
public_key
)
expect
(
described_class
.
emails
(
GpgHelpers
::
User2
.
fingerprint
)
).
to
match_array
GpgHelpers
::
User2
.
emails
end
end
describe
'.add
_to_keychain
'
,
:gpg
do
describe
'.add'
,
:gpg
do
it
'stores the key in the keychain'
do
it
'stores the key in the keychain'
do
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
to
eq
[]
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
to
eq
[]
Gitlab
::
Gpg
.
add_to_keychain
(
GpgHelpers
::
User1
.
public_key
)
Gitlab
::
Gpg
::
CurrentKeyChain
.
add
(
GpgHelpers
::
User1
.
public_key
)
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
not_to
eq
[]
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
not_to
eq
[]
end
end
end
end
describe
'.remove
_from_keychain
'
,
:gpg
do
describe
'.remove'
,
:gpg
do
it
'removes the key from the keychain'
do
it
'removes the key from the keychain'
do
Gitlab
::
Gpg
.
add_to_keychain
(
GpgHelpers
::
User1
.
public_key
)
Gitlab
::
Gpg
::
CurrentKeyChain
.
add
(
GpgHelpers
::
User1
.
public_key
)
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
not_to
eq
[]
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
not_to
eq
[]
Gitlab
::
Gpg
.
remove_from_keychain
(
GpgHelpers
::
User1
.
fingerprint
)
Gitlab
::
Gpg
::
CurrentKeyChain
.
remove
(
GpgHelpers
::
User1
.
fingerprint
)
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
to
eq
[]
expect
(
GPGME
::
Key
.
find
(
:public
,
GpgHelpers
::
User1
.
fingerprint
)).
to
eq
[]
end
end
end
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
spec/models/gpg_key_spec.rb
View file @
0668521b
...
@@ -24,17 +24,19 @@ describe GpgKey do
...
@@ -24,17 +24,19 @@ describe GpgKey do
describe
'add_to_keychain'
do
describe
'add_to_keychain'
do
it
'calls add_to_keychain after create'
do
it
'calls add_to_keychain after create'
do
expect
(
Gitlab
::
Gpg
).
to
receive
(
:add_to_keychain
).
with
(
GpgHelpers
::
User1
.
public_key
)
expect
(
Gitlab
::
Gpg
::
CurrentKeyChain
).
to
receive
(
:add
).
with
(
GpgHelpers
::
User1
.
public_key
)
create
:gpg_key
create
:gpg_key
end
end
end
end
describe
'remove_from_keychain'
do
describe
'remove_from_keychain'
do
it
'calls remove_from_keychain after destroy'
do
it
'calls remove_from_keychain after destroy'
do
allow
(
Gitlab
::
Gpg
).
to
receive
:add_to_keychain
allow
(
Gitlab
::
Gpg
::
CurrentKeyChain
).
to
receive
:add
gpg_key
=
create
:gpg_key
gpg_key
=
create
:gpg_key
expect
(
Gitlab
::
Gpg
).
to
receive
(
:remove_from_keychain
).
with
(
GpgHelpers
::
User1
.
fingerprint
)
expect
(
Gitlab
::
Gpg
::
CurrentKeyChain
).
to
receive
(
:remove
).
with
(
GpgHelpers
::
User1
.
fingerprint
)
gpg_key
.
destroy!
gpg_key
.
destroy!
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